Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Scarb workspaces for Cast #1093

Closed
wants to merge 44 commits into from
Closed

Conversation

Radinyn
Copy link
Member

@Radinyn Radinyn commented Nov 10, 2023

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

@Radinyn Radinyn self-assigned this Nov 10, 2023
@Radinyn Radinyn marked this pull request as ready for review November 29, 2023 16:08
@Radinyn Radinyn requested a review from a team as a code owner November 29, 2023 16:08
@Radinyn Radinyn requested review from DelevoXDG, abulenok and THenry14 and removed request for a team November 29, 2023 16:08
@DelevoXDG DelevoXDG mentioned this pull request Nov 30, 2023
5 tasks
Copy link
Contributor

@THenry14 THenry14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall the logic looks good 👍

benchmarks/benchmarks copy.csv Outdated Show resolved Hide resolved
crates/cast/src/helpers/build.rs Outdated Show resolved Hide resolved
crates/cast/src/main.rs Outdated Show resolved Hide resolved
crates/cast/tests/e2e/main_tests.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@Radinyn Radinyn requested a review from THenry14 December 6, 2023 19:30
Copy link
Member

@MaksymilianDemitraszek MaksymilianDemitraszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally don't understand --package filter from the perspective of cast. What purpose does it serve exactly?

Comment on lines 124 to 125
which::which("scarb")
.context("Cannot find `scarb` binary in PATH. Make sure you have Scarb installed https://github.com/software-mansion/scarb")?;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotmag769 what was the reason we require it for all comands in forge?

pub package: Result<PackageMetadata>,
}

// Lazily get all the required package information from CLI

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the argument. What is the difference between calling different functions from different places instead of unpacking the errors in those places. It only adds complexity (we have to pass PackageData around) and is heavily not idiomatic. Please change that.

};

// Check if the path is actually valid
result.manifest_path = match path {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unpack path with ? in the part above.

// Check if the path is actually valid
result.manifest_path = match path {
Ok(path) => {
if path.exists() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this part to a separate function.

use super::constants::LIB_CONTRACT_ARTIFACTS_NAME;

#[allow(clippy::too_many_lines)]
pub fn build(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good practice to have small functions doing only one thing. Current interface makes it not obvious that scarb writes to the memory. Declare shouldn't load scripts.

.context("Cannot find `scarb` binary in PATH. Make sure you have Scarb installed https://github.com/software-mansion/scarb")?;

let package_data = get_package_data(&cli);
let mut config = match &package_data.package {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut config = match &package_data.package {
let mut cast_config = match &package_data.package_metadata {

@@ -27,13 +33,16 @@ mod starknet_commands;
#[allow(clippy::struct_excessive_bools)]
struct Cli {
/// Profile name in Scarb.toml config file
#[clap(short, long)]
#[clap(short = 'p', long)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related change, please revert it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? I think it is to override the -p option as a short option for --package (not sure how clap handles 2 flags with the same short form)

profile: Option<String>,

/// Path to Scarb.toml that is to be used; overrides default behaviour of searching for scarb.toml in current or parent directories
/// Path to Scarb.toml that is to be used; overrides default behaviour of searching for Scarb.toml in current or parent directories

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related change, please revert it

Comment on lines 79 to 80

## `--package`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this flag? How it behaves when I call a script, How it behaves when i call declare.

@@ -226,6 +226,23 @@ pub fn duplicate_directory_with_salt(src_path: String, to_be_salted: &str, salt:
temp_dir
}

#[must_use]
pub fn duplicate_directory(src_path: String) -> TempDir {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably copy_directory_to_tempdir?

@MaksymilianDemitraszek
Copy link
Member

Also we probably shouldn't take the first match, we should throw an error when it is ambigous

@MaksymilianDemitraszek
Copy link
Member

MaksymilianDemitraszek commented Dec 8, 2023

We discussed it with @THenry14 , filter mechanism does not make much sense in the context of scripts.
Instead we should be able to pass module path to script instead of a name:
script package_name::path::to::script_module

If only script_module is passed and it is ambigous in the context of workspace we should print something like this:

package_namea::path::to::script_module
package_nameb::path::to::script_module
package_nameb::path2::to::script_module

Passing to::script_module also should be possible

@piotmag769
Copy link
Member

I generally don't understand --package filter from the perspective of cast. What purpose does it serve exactly?

@MaksymilianDemitraszek --package makes sense, you can choose an explicit package that config will be taken from etc.. I don't understand what --workspace does. It was decided that --workspace will be disabled, right? I don't see it explicitly disabled, looks like you can still pass it for a workspace with a single package (match_one won't fail).

Also what config from Scarb.toml takes priority when both --manifest-path and --package are both passed? Should it be even allowed? (currently it is from the CLI point of view)

Copy link
Member

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good bye 👋 👽 😢 🌹
image

.join(&metadata.current_profile)
.join(sierra_filename);

let lib_artifacts = StarknetContractArtifacts {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing it together with StarknetContractArtifacts is kinda a hack, should be stored in a separate struct prob

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe introduce a type alias?

@@ -276,23 +259,40 @@ pub fn get_package_tool_sncast(metadata: &scarb_metadata::Metadata) -> Result<&V
Ok(tool_sncast)
}

pub fn get_first_package_from_metadata(metadata: &Metadata) -> Result<PackageMetadata> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It terrifies me (I know this logic has been there before) xD Is it only used in tests? If so can we move it to the tests mod?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in tests in multiple modules

github-merge-queue bot pushed a commit that referenced this pull request Jan 25, 2024
<!-- Reference any GitHub issues resolved by this PR -->

## Introduced changes

<!-- A brief description of the changes -->

- Opens up a discussion about sncast declare/script interfaces, first
raised under this PR
#1093

## Checklist

<!-- Make sure all of these are complete -->

- [X] Linked relevant issue
- [X] Updated relevant documentation
- [X] Added relevant tests
- [X] Performed self-review of the code
- [X] Added changes to `CHANGELOG.md`
@THenry14 THenry14 closed this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants