From f103539219f351e322d915663a05971267dae00f Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 10 Dec 2021 14:31:11 +0800 Subject: [PATCH] Replace structopt with Clap 3.0 --- Cargo.lock | 134 ++++++++++++++++-------------------- Cargo.toml | 3 +- src/build_options.rs | 25 ++++--- src/main.rs | 116 ++++++++++++++++--------------- src/new_project.rs | 9 ++- src/upload.rs | 13 ++-- tests/common/editable.rs | 4 +- tests/common/errors.rs | 8 +-- tests/common/integration.rs | 6 +- tests/common/other.rs | 6 +- 10 files changed, 158 insertions(+), 166 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae27c3fae..484c4c71d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,15 +57,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.51" @@ -308,17 +299,41 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "3.0.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "098d281b47bf725a0bddd829e0070ee76560faab8af123050a86c440d7f0a1fd" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", "strsim", - "textwrap 0.11.0", - "unicode-width", - "vec_map", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26de8102ffb96701066cea36f9a104285b67fbcc302a520640289d476c15ed8a" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_generate" +version = "3.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6348a4d94b0a7554e2725a77db6c6e2f897688f77230c083f51856ef021eb7d" +dependencies = [ + "clap", ] [[package]] @@ -465,9 +480,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" -version = "0.8.29" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a74ea89a0a1b98f6332de42c95baff457ada66d1cb4030f9ff151b2041a1c746" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ "cfg-if 1.0.0", ] @@ -733,9 +748,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fd819562fcebdac5afc5c113c3ec36f902840b70fd4fc458799c8ce4607ae55" +checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" dependencies = [ "bytes", "fnv", @@ -767,9 +782,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "c7a30908dbce072eca83216eab939d2290080e00ca71611b96a09e5cdce5f3fa" dependencies = [ "libc", ] @@ -854,9 +869,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.15" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436ec0091e4f20e655156a30a0df3770fe2900aa301e548e08446ec794b6953c" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -987,9 +1002,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.109" +version = "0.2.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01" +checksum = "b58a4469763e4e3a906c4ed786e1c70512d16aa88f84dded826da42640fc6a1c" [[package]] name = "log" @@ -1026,6 +1041,8 @@ dependencies = [ "bytesize", "cargo_metadata", "cbindgen", + "clap", + "clap_generate", "configparser", "console", "dialoguer", @@ -1052,11 +1069,10 @@ dependencies = [ "serde_json", "sha2", "shlex", - "structopt", "tar", "target-lexicon", "tempfile", - "textwrap 0.14.2", + "textwrap", "thiserror", "toml", "zip", @@ -1264,6 +1280,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "os_type" version = "2.3.0" @@ -1299,9 +1324,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" +checksum = "d1a3ea4f0dd7f1f3e512cf97bf100819aa547f36a6eccac8dbaae839eb92363e" [[package]] name = "plain" @@ -1736,18 +1761,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "b710a83c4e0dff6a3d511946b95274ad9ca9e5d3ae497b63fda866ac955358d2" dependencies = [ "proc-macro2", "quote", @@ -1843,33 +1868,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "structopt" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" @@ -1938,15 +1939,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "textwrap" version = "0.14.2" @@ -2184,12 +2176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index 1e04891f7..def6ac49d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.70" sha2 = "0.9.3" shlex = "1.0.0" -structopt = "0.3.21" tar = "0.4.33" tempfile = "3.2.0" toml = "0.5.8" @@ -57,6 +56,8 @@ ignore = "0.4.18" dialoguer = "0.9.0" console = "0.15.0" minijinja = "0.8.2" +clap = { version = "3.0.0-rc.3", features = ["derive", "env"] } +clap_generate = "3.0.0-rc.3" [dev-dependencies] indoc = "1.0.3" diff --git a/src/build_options.rs b/src/build_options.rs index e55265f32..13f86cc1b 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -16,10 +16,9 @@ use std::collections::{HashMap, HashSet}; use std::env; use std::io; use std::path::PathBuf; -use structopt::StructOpt; /// High level API for building wheels from a crate which is also used for the CLI -#[derive(Debug, Serialize, Deserialize, StructOpt, Clone, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, clap::Parser, Clone, Eq, PartialEq)] #[serde(default)] pub struct BuildOptions { /// Control the platform tag on linux. @@ -34,22 +33,22 @@ pub struct BuildOptions { /// The default is the lowest compatible `manylinux` tag, or plain `linux` if nothing matched /// /// This option is ignored on all non-linux platforms - #[structopt( + #[clap( name = "compatibility", long = "compatibility", alias = "manylinux", parse(try_from_str) )] pub platform_tag: Option, - #[structopt(short, long)] + #[clap(short, long)] /// The python versions to build wheels for, given as the names of the /// interpreters. Uses autodiscovery if not explicitly set. pub interpreter: Option>, /// Which kind of bindings to use. Possible values are pyo3, rust-cpython, cffi and bin - #[structopt(short, long)] + #[clap(short, long)] pub bindings: Option, - #[structopt( - short = "m", + #[clap( + short = 'm', long = "manifest-path", parse(from_os_str), default_value = "Cargo.toml", @@ -59,13 +58,13 @@ pub struct BuildOptions { pub manifest_path: PathBuf, /// The directory to store the built wheels in. Defaults to a new "wheels" /// directory in the project's target directory - #[structopt(short, long, parse(from_os_str))] + #[clap(short, long, parse(from_os_str))] pub out: Option, /// Don't check for manylinux compliance - #[structopt(long = "skip-auditwheel")] + #[clap(long = "skip-auditwheel")] pub skip_auditwheel: bool, /// The --target option for cargo - #[structopt(long, name = "TRIPLE", env = "CARGO_BUILD_TARGET")] + #[clap(long, name = "TRIPLE", env = "CARGO_BUILD_TARGET")] pub target: Option, /// Extra arguments that will be passed to cargo as `cargo rustc [...] [arg1] [arg2] -- [...]` /// @@ -74,16 +73,16 @@ pub struct BuildOptions { /// Note that maturin invokes cargo twice: Once as `cargo metadata` and then as `cargo rustc`. /// maturin tries to pass only the shared subset of options to cargo metadata, but this is may /// be a bit flaky. - #[structopt(long = "cargo-extra-args")] + #[clap(long = "cargo-extra-args")] pub cargo_extra_args: Vec, /// Extra arguments that will be passed to rustc as `cargo rustc [...] -- [...] [arg1] [arg2]` /// /// Use as `--rustc-extra-args="--my-arg"` - #[structopt(long = "rustc-extra-args")] + #[clap(long = "rustc-extra-args")] pub rustc_extra_args: Vec, /// Control whether to build universal2 wheel for macOS or not. /// Only applies to macOS targets, do nothing otherwise. - #[structopt(long)] + #[clap(long)] pub universal2: bool, } diff --git a/src/main.rs b/src/main.rs index 199772436..c45d63343 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use anyhow::{bail, Context, Result}; use cargo_metadata::MetadataCommand; +use clap::{IntoApp, Parser}; use fs_err as fs; use maturin::{ develop, init_project, new_project, source_distribution, write_dist_info, BridgeModel, @@ -16,60 +17,59 @@ use maturin::{upload_ui, PublishOpt}; use std::env; use std::io; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] -#[structopt(name = env!("CARGO_PKG_NAME"))] +#[derive(Debug, Parser)] +#[clap(name = env!("CARGO_PKG_NAME"))] #[cfg_attr(feature = "cargo-clippy", allow(clippy::large_enum_variant))] /// Build and publish crates with pyo3, rust-cpython and cffi bindings as well /// as rust binaries as python packages enum Opt { - #[structopt(name = "build")] + #[clap(name = "build")] /// Build the crate into python packages Build { - #[structopt(flatten)] + #[clap(flatten)] build: BuildOptions, /// Pass --release to cargo - #[structopt(long)] + #[clap(long)] release: bool, /// Strip the library for minimum file size - #[structopt(long)] + #[clap(long)] strip: bool, /// Don't build a source distribution - #[structopt(long = "no-sdist")] + #[clap(long = "no-sdist")] no_sdist: bool, }, #[cfg(feature = "upload")] - #[structopt(name = "publish")] + #[clap(name = "publish")] /// Build and publish the crate as python packages to pypi Publish { - #[structopt(flatten)] + #[clap(flatten)] build: BuildOptions, /// Do not pass --release to cargo - #[structopt(long)] + #[clap(long)] debug: bool, /// Do not strip the library for minimum file size - #[structopt(long = "no-strip")] + #[clap(long = "no-strip")] no_strip: bool, /// Don't build a source distribution - #[structopt(long = "no-sdist")] + #[clap(long = "no-sdist")] no_sdist: bool, - #[structopt(flatten)] + #[clap(flatten)] publish: PublishOpt, }, - #[structopt(name = "list-python")] + #[clap(name = "list-python")] /// Searches and lists the available python installations ListPython, - #[structopt(name = "develop")] + #[clap(name = "develop")] /// Installs the crate as module in the current virtualenv /// /// Note that this command doesn't create entrypoints Develop { /// Which kind of bindings to use. Possible values are pyo3, rust-cpython, cffi and bin - #[structopt(short = "b", long = "binding-crate")] + #[clap(short = 'b', long = "binding-crate")] binding_crate: Option, - #[structopt( - short = "m", + #[clap( + short = 'm', long = "manifest-path", parse(from_os_str), default_value = "Cargo.toml" @@ -77,25 +77,31 @@ enum Opt { /// The path to the Cargo.toml manifest_path: PathBuf, /// Pass --release to cargo - #[structopt(long)] + #[clap(long)] release: bool, /// Strip the library for minimum file size - #[structopt(long)] + #[clap(long)] strip: bool, /// Extra arguments that will be passed to cargo as `cargo rustc [...] [arg1] [arg2] --` /// /// Use as `--cargo-extra-args="--my-arg"` - #[structopt(long = "cargo-extra-args")] + #[clap(long = "cargo-extra-args")] cargo_extra_args: Vec, /// Extra arguments that will be passed to rustc as `cargo rustc [...] -- [arg1] [arg2]` /// /// Use as `--rustc-extra-args="--my-arg"` - #[structopt(long = "rustc-extra-args")] + #[clap(long = "rustc-extra-args")] rustc_extra_args: Vec, /// Install extra requires aka. optional dependencies /// /// Use as `--extras=extra1,extra2` - #[structopt(short = "E", long, use_delimiter = true, multiple = false)] + #[clap( + short = 'E', + long, + use_delimiter = true, + multiple_values = false, + multiple_occurrences = true + )] extras: Vec, }, /// Build only a source distribution (sdist) without compiling. @@ -103,10 +109,10 @@ enum Opt { /// Building a source distribution requires a pyproject.toml with a `[build-system]` table. /// /// This command is a workaround for [pypa/pip#6041](https://github.com/pypa/pip/issues/6041) - #[structopt(name = "sdist")] + #[clap(name = "sdist")] SDist { - #[structopt( - short = "m", + #[clap( + short = 'm', long = "manifest-path", parse(from_os_str), default_value = "Cargo.toml" @@ -115,23 +121,23 @@ enum Opt { manifest_path: PathBuf, /// The directory to store the built wheels in. Defaults to a new "wheels" /// directory in the project's target directory - #[structopt(short, long, parse(from_os_str))] + #[clap(short, long, parse(from_os_str))] out: Option, }, /// Create a new cargo project in an existing directory - #[structopt(name = "init")] + #[clap(name = "init")] InitProject { /// Project path path: Option, - #[structopt(flatten)] + #[clap(flatten)] options: GenerateProjectOptions, }, /// Create a new cargo project - #[structopt(name = "new")] + #[clap(name = "new")] NewProject { /// Project path path: String, - #[structopt(flatten)] + #[clap(flatten)] options: GenerateProjectOptions, }, /// Uploads python packages to pypi @@ -139,66 +145,67 @@ enum Opt { /// It is mostly similar to `twine upload`, but can only upload python wheels /// and source distributions. #[cfg(feature = "upload")] - #[structopt(name = "upload")] + #[clap(name = "upload")] Upload { - #[structopt(flatten)] + #[clap(flatten)] publish: PublishOpt, /// The python packages to upload - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] files: Vec, }, /// Backend for the PEP 517 integration. Not for human consumption /// /// The commands are meant to be called from the python PEP 517 - #[structopt(name = "pep517", setting = structopt::clap::AppSettings::Hidden)] + #[clap(subcommand)] Pep517(Pep517Command), /// Generate shell completions - #[structopt(name = "completions", setting = structopt::clap::AppSettings::Hidden)] + #[clap(name = "completions", setting = clap::AppSettings::Hidden)] Completions { - #[structopt(name = "SHELL", parse(try_from_str))] - shell: structopt::clap::Shell, + #[clap(name = "SHELL", parse(try_from_str))] + shell: clap_generate::Shell, }, } /// Backend for the PEP 517 integration. Not for human consumption /// /// The commands are meant to be called from the python PEP 517 -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] +#[clap(name = "pep517", setting = clap::AppSettings::Hidden)] enum Pep517Command { /// The implementation of prepare_metadata_for_build_wheel - #[structopt(name = "write-dist-info")] + #[clap(name = "write-dist-info")] WriteDistInfo { - #[structopt(flatten)] + #[clap(flatten)] build_options: BuildOptions, /// The metadata_directory argument to prepare_metadata_for_build_wheel - #[structopt(long = "metadata-directory", parse(from_os_str))] + #[clap(long = "metadata-directory", parse(from_os_str))] metadata_directory: PathBuf, /// Strip the library for minimum file size - #[structopt(long)] + #[clap(long)] strip: bool, }, - #[structopt(name = "build-wheel")] + #[clap(name = "build-wheel")] /// Implementation of build_wheel /// /// --release and --strip are currently unused by the PEP 517 implementation BuildWheel { - #[structopt(flatten)] + #[clap(flatten)] build_options: BuildOptions, /// Strip the library for minimum file size - #[structopt(long)] + #[clap(long)] strip: bool, /// Build editable wheels - #[structopt(long)] + #[clap(long)] editable: bool, }, /// The implementation of build_sdist - #[structopt(name = "write-sdist")] + #[clap(name = "write-sdist")] WriteSDist { /// The sdist_directory argument to build_sdist - #[structopt(long = "sdist-directory", parse(from_os_str))] + #[clap(long = "sdist-directory", parse(from_os_str))] sdist_directory: PathBuf, - #[structopt( - short = "m", + #[clap( + short = 'm', long = "manifest-path", parse(from_os_str), default_value = "Cargo.toml", @@ -290,7 +297,7 @@ fn run() -> Result<()> { #[cfg(feature = "log")] pretty_env_logger::init(); - let opt = Opt::from_args(); + let opt = Opt::parse(); match opt { Opt::Build { @@ -421,7 +428,8 @@ fn run() -> Result<()> { upload_ui(&files, &publish)? } Opt::Completions { shell } => { - Opt::clap().gen_completions_to(env!("CARGO_BIN_NAME"), shell, &mut io::stdout()); + let mut app = Opt::into_app(); + clap_generate::generate(shell, &mut app, env!("CARGO_BIN_NAME"), &mut io::stdout()); } } diff --git a/src/new_project.rs b/src/new_project.rs index 3c4e7be1e..2c6ca558f 100644 --- a/src/new_project.rs +++ b/src/new_project.rs @@ -4,7 +4,6 @@ use dialoguer::{theme::ColorfulTheme, Select}; use fs_err as fs; use minijinja::{context, Environment}; use std::path::Path; -use structopt::StructOpt; struct ProjectGenerator<'a> { env: Environment<'a>, @@ -92,16 +91,16 @@ impl<'a> ProjectGenerator<'a> { // workaround for https://github.com/TeXitoi/structopt/issues/333#issuecomment-712265332 #[cfg_attr(not(doc), allow(missing_docs))] #[cfg_attr(doc, doc = "Options common to `maturin new` and `maturin init`.")] -#[derive(Debug, StructOpt)] +#[derive(Debug, clap::Parser)] pub struct GenerateProjectOptions { /// Set the resulting package name, defaults to the directory name - #[structopt(long)] + #[clap(long)] name: Option, /// Use mixed Rust/Python project layout - #[structopt(long)] + #[clap(long)] mixed: bool, /// Which kind of bindings to use - #[structopt(short, long, possible_values = &["pyo3", "rust-cpython", "cffi", "bin"])] + #[clap(short, long, possible_values = &["pyo3", "rust-cpython", "cffi", "bin"])] bindings: Option, } diff --git a/src/upload.rs b/src/upload.rs index a7c8c7caf..d6d1a68a5 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -14,29 +14,28 @@ use sha2::{Digest, Sha256}; use std::env; use std::io; use std::path::{Path, PathBuf}; -use structopt::StructOpt; use thiserror::Error; /// An account with a registry, possibly incomplete -#[derive(Debug, StructOpt)] +#[derive(Debug, clap::Parser)] pub struct PublishOpt { - #[structopt( - short = "r", + #[clap( + short = 'r', long = "repository-url", default_value = "https://upload.pypi.org/legacy/" )] /// The url of registry where the wheels are uploaded to registry: String, - #[structopt(short, long)] + #[clap(short, long)] /// Username for pypi or your custom registry username: Option, - #[structopt(short, long)] + #[clap(short, long)] /// Password for pypi or your custom registry. Note that you can also pass the password /// through MATURIN_PASSWORD password: Option, /// Continue uploading files if one already exists. /// (Only valid when uploading to PyPI. Other implementations may not support this.) - #[structopt(long = "skip-existing")] + #[clap(long = "skip-existing")] skip_existing: bool, } diff --git a/tests/common/editable.rs b/tests/common/editable.rs index 684d9785e..d4fe661de 100644 --- a/tests/common/editable.rs +++ b/tests/common/editable.rs @@ -2,11 +2,11 @@ use crate::common::{ adjust_canonicalization, check_installed, create_virtualenv, maybe_mock_cargo, }; use anyhow::{bail, Context, Result}; +use clap::Parser; use maturin::BuildOptions; use std::path::Path; use std::process::Command; use std::str; -use structopt::StructOpt; /// test PEP 660 editable installs pub fn test_editable(package: impl AsRef, bindings: Option) -> Result<()> { @@ -33,7 +33,7 @@ pub fn test_editable(package: impl AsRef, bindings: Option) -> Res cli.push(bindings); } - let options: BuildOptions = BuildOptions::from_iter_safe(cli)?; + let options: BuildOptions = BuildOptions::try_parse_from(cli)?; let build_context = options.into_build_context(false, cfg!(feature = "faster-tests"), true)?; let wheels = build_context.build_wheels()?; diff --git a/tests/common/errors.rs b/tests/common/errors.rs index 071d2a9d3..46fdfc384 100644 --- a/tests/common/errors.rs +++ b/tests/common/errors.rs @@ -1,7 +1,7 @@ use anyhow::format_err; use anyhow::{bail, Result}; +use clap::Parser; use maturin::BuildOptions; -use structopt::StructOpt; pub fn abi3_without_version() -> Result<()> { // The first argument is ignored by clap @@ -12,7 +12,7 @@ pub fn abi3_without_version() -> Result<()> { "--cargo-extra-args='--quiet'", ]; - let options = BuildOptions::from_iter_safe(cli)?; + let options = BuildOptions::try_parse_from(cli)?; let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false); if let Err(err) = result { assert_eq!(err.to_string(), @@ -38,7 +38,7 @@ pub fn pyo3_no_extension_module() -> Result<()> { "-i=python", ]; - let options = BuildOptions::from_iter_safe(cli)?; + let options = BuildOptions::try_parse_from(cli)?; let result = options .into_build_context(false, cfg!(feature = "faster-tests"), false)? .build_wheels(); @@ -72,7 +72,7 @@ pub fn locked_doesnt_build_without_cargo_lock() -> Result<()> { "--cargo-extra-args='--locked'", "-i=python", ]; - let options = BuildOptions::from_iter_safe(cli)?; + let options = BuildOptions::try_parse_from(cli)?; let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false); if let Err(err) = result { let err_string = err diff --git a/tests/common/integration.rs b/tests/common/integration.rs index 58f6a86f6..cbce00c36 100644 --- a/tests/common/integration.rs +++ b/tests/common/integration.rs @@ -1,10 +1,10 @@ use crate::common::{adjust_canonicalization, check_installed, maybe_mock_cargo}; use anyhow::{bail, Context, Result}; +use clap::Parser; use maturin::{BuildOptions, PythonInterpreter, Target}; use std::path::{Path, PathBuf}; use std::process::Command; use std::str; -use structopt::StructOpt; /// For each installed python version, this builds a wheel, creates a virtualenv if it /// doesn't exist, installs the package and runs check_installed.py @@ -30,7 +30,7 @@ pub fn test_integration(package: impl AsRef, bindings: Option) -> cli.push(bindings); } - let options: BuildOptions = BuildOptions::from_iter_safe(cli)?; + let options: BuildOptions = BuildOptions::try_parse_from(cli)?; let build_context = options.into_build_context(false, cfg!(feature = "faster-tests"), false)?; let wheels = build_context.build_wheels()?; @@ -182,7 +182,7 @@ pub fn test_integration_conda(package: impl AsRef, bindings: Option Result { }; // The first arg gets ignored - let options: BuildOptions = BuildOptions::from_iter_safe(&[ + let options: BuildOptions = BuildOptions::try_parse_from(&[ "build", "--manifest-path", "test-crates/hello-world/Cargo.toml", @@ -90,7 +90,7 @@ pub fn test_musl() -> Result { /// https://github.com/PyO3/maturin/issues/449 pub fn test_workspace_cargo_lock() -> Result<()> { // The first arg gets ignored - let options: BuildOptions = BuildOptions::from_iter_safe(&[ + let options: BuildOptions = BuildOptions::try_parse_from(&[ "build", "--manifest-path", "test-crates/workspace/py/Cargo.toml",