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

Port "wapm install" to Wasmer #3317

Merged
merged 10 commits into from
Nov 17, 2022
Merged

Port "wapm install" to Wasmer #3317

merged 10 commits into from
Nov 17, 2022

Conversation

Michael-F-Bryan
Copy link
Contributor

@Michael-F-Bryan Michael-F-Bryan commented Nov 17, 2022

This ports the wapm install command (wasmerio/wapm-cli#262) to the wasmer CLI under the name wasmer add.

Fixes #3303.

@Michael-F-Bryan Michael-F-Bryan marked this pull request as ready for review November 17, 2022 12:23
Copy link
Contributor

@fschutt fschutt left a comment

Choose a reason for hiding this comment

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

Okay overall, just make sure we don't implement the SplitVersion x number of times, since we seem to reuse it for specifying generators, bindings, install, run, etc.

}

fn target(&self) -> Target {
match (self.pip, self.npm, self.yarn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would refactor this to:

if self.pip { return Target::Pip; }
if self.npm { return Target::Npm }
if self.yarn { return Target::Yarn }
unreachable!("Clap should ensure at least one item in the \"bindings\" group is specified")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to keep the match version because it shows that exactly one of pip, npm, and yarn can be set.

I don't want a potential update to those fields (e.g. updating the #[clap] attribute to clap 4.0 or adding a new package manager) to mess up the logic so --npm --pip is accidentally allowed and we silently favour pip.


/// The full name and optional version number for a WAPM package.
#[derive(Debug)]
struct PackageSpecifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically you can use SplitVersion from crate::cli, which also has tests. I would want to avoid making n number of copies for parsing the namespace/name@version thing.

SplitVersion::new("registry.wapm.io/graphql/python/python").unwrap(),

Copy link
Contributor Author

@Michael-F-Bryan Michael-F-Bryan Nov 17, 2022

Choose a reason for hiding this comment

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

I've switched the Add command over to SplitVersion.

At some point we'll need to refactor SplitVersion. Currently it's fulfilling multiple somewhat contradictory roles (URL dependency, a package name, a package's command, etc.) and we're silently ignoring issues (e.g. wasmer add --yarn namespace/package:command would be permitted, but doesn't make logical sense).

@@ -347,6 +350,15 @@ pub enum Registries {
Multi(MultiRegistry),
}

impl Registries {
pub fn current(&self) -> &str {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will likely conflict with my code, just copy the entire impl Registries block from wapm-cli.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not wrong, but I will have to overwrite it when I port the other commands from wapm-cli.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've copied the impl Registries block across. You'll probably get some small merge conflicts because I replaced println!() statements with log::warn!() and friends - libraries shouldn't be printing to stdout.

@@ -1296,6 +1308,30 @@ pub struct BindingsGenerator {
pub command: String,
}

impl Display for BindingsGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the same syntax as crate::cli::SplitVersion again? Want to avoid having n number of parsers / displayers for the same syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I didn't know that had been ported across from wapm, so I implemented it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it's not quite the same as SplitVersion because this includes a command in the output and the struct has different fields. The SplitVersion type is also part of the wasmer-cli crate, so I can't import it.

@@ -10,6 +10,8 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C

## Added

- [#3317](https://github.com/wasmerio/wasmer/pull/3317) Add a `wasmer add` command for adding bindings for a WAPM package to your project (only Python and JavaScript are supported for now)
Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, you don't need to update the changelog at all in PRs. When doing a release, I just do gh search --prs --merged --repo wasmerio/wasmer and then copy the list since the last release. Otherwise I'd have to look if every PR has included this message. So this commit is nice, but pointless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay. We should probably update the pull request template so we don't tell people to update the changelog.

@Michael-F-Bryan
Copy link
Contributor Author

bors r+

@bors bors bot merged commit 9401599 into master Nov 17, 2022
@bors bors bot deleted the wasmer-install branch November 17, 2022 19:44
@bors
Copy link
Contributor

bors bot commented Nov 17, 2022

This PR was included in a batch that successfully built, but then failed to merge into master. It will not be retried.

Additional information:

{"message":"Changes must be made through a pull request.","documentation_url":"https://docs.github.com/articles/about-protected-branches"}

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.

Port wapm install --npm to the wasmer CLI
2 participants