diff --git a/Changelog.md b/Changelog.md index a3df7faac..5ee6d7f4e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * **Breaking Change**: Don't build source distribution by default in `maturin build` command in [#955](https://github.com/PyO3/maturin/pull/955), `--no-sdist` option is replaced by `--sdist` * **Breaking Change**: maturin no longer search for python interpreters by default and only build for current interpreter in `PATH` in [#964](https://github.com/PyO3/maturin/pull/964) * **Breaking Change**: Removed `--cargo-extra-args` and `--rustc-extra-args` options in [#972](https://github.com/PyO3/maturin/pull/972). You can now pass all common `cargo build` arguments directly to `maturin build` +* **Breaking Change**: `--repository-url` option in `upload` command no longer accepts plain repository name, full url required and `-r` short option moved to `--repository` in [#987](https://github.com/PyO3/maturin/pull/987) * Add support for building with multiple binary targets in [#948](https://github.com/PyO3/maturin/pull/948) * Add a `--target` option to `maturin list-python` command in [#957](https://github.com/PyO3/maturin/pull/957) * Add support for using bundled python sysconfigs for PyPy when abi3 feature is enabled in [#958](https://github.com/PyO3/maturin/pull/958) @@ -21,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add support for `wasm32-unknown-emscripten` target in [#974](https://github.com/PyO3/maturin/pull/974) * Allow overriding platform release version using env var in [#975](https://github.com/PyO3/maturin/pull/975) * Fix `maturin develop` for arm64 Python on M1 Mac when default toolchain is x86_64 in [#980](https://github.com/PyO3/maturin/pull/980) +* Add `--repository` option to `maturin upload` command in [#987](https://github.com/PyO3/maturin/pull/987) ## [0.12.20] - 2022-06-15 diff --git a/src/upload.rs b/src/upload.rs index 2bf4f9c10..0f80d571f 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -17,23 +17,30 @@ use thiserror::Error; /// An account with a registry, possibly incomplete #[derive(Debug, clap::Parser)] pub struct PublishOpt { - /// The URL of the registry where the wheels are uploaded to. Note than you can also pass - /// the URL through MATURIN_REPOSITORY_URL variable + /// The repository (package index) to upload the package to. Should be a section in the config file. + /// + /// Can also be set via MATURIN_REPOSITORY environment variable. + #[clap(short = 'r', long, env = "MATURIN_REPOSITORY", default_value = "pypi")] + repository: String, + /// The URL of the registry where the wheels are uploaded to. This overrides --repository. + /// + /// Can also be set via MATURIN_REPOSITORY_URL environment variable. #[clap( - short = 'r', long = "repository-url", env = "MATURIN_REPOSITORY_URL", - default_value = "https://upload.pypi.org/legacy/" + overrides_with = "repository" )] - registry: String, - /// Username for pypi or your custom registry. Note that you can also pass the username - /// through MATURIN_USERNAME variable + repository_url: Option, + /// Username for pypi or your custom registry. + /// + /// Can also be set via MATURIN_USERNAME environment variable. /// /// Set MATURIN_PYPI_TOKEN variable to use token-based authentication instead #[clap(short, long, env = "MATURIN_USERNAME")] username: Option, - /// Password for pypi or your custom registry. Note that you can also pass the password - /// through MATURIN_PASSWORD variable + /// Password for pypi or your custom registry. + /// + /// Can also be set via MATURIN_PASSWORD environment variable. #[clap(short, long)] password: Option, /// Continue uploading files if one already exists. @@ -42,6 +49,11 @@ pub struct PublishOpt { skip_existing: bool, } +impl PublishOpt { + const DEFAULT_REPOSITORY_URL: &'static str = "https://upload.pypi.org/legacy/"; + const TEST_REPOSITORY_URL: &'static str = "https://test.pypi.org/legacy/"; +} + /// Error type for different types of errors that can happen when uploading a /// wheel. /// @@ -206,24 +218,32 @@ fn resolve_pypi_cred( fn complete_registry(opt: &PublishOpt) -> Result { // load creds from pypirc if found let pypirc = load_pypirc(); - let (register_name, registry_url) = - if !opt.registry.starts_with("http://") && !opt.registry.starts_with("https://") { - if let Some(url) = pypirc.get(&opt.registry, "repository") { - (Some(opt.registry.as_str()), url) - } else { - bail!( - "Failed to get registry {} in .pypirc. \ - Note: Your index didn't start with http:// or https://, \ - which is required for non-pypirc indices.", - opt.registry - ); - } - } else if opt.registry == "https://upload.pypi.org/legacy/" { - (Some("pypi"), opt.registry.clone()) - } else { - (None, opt.registry.clone()) + let (registry_name, registry_url) = if let Some(repository_url) = opt.repository_url.as_deref() + { + let name = match repository_url { + PublishOpt::DEFAULT_REPOSITORY_URL => Some("pypi"), + PublishOpt::TEST_REPOSITORY_URL => Some("testpypi"), + _ => None, }; - let (username, password) = resolve_pypi_cred(opt, &pypirc, register_name); + (name, repository_url.to_string()) + } else if let Some(url) = pypirc.get(&opt.repository, "repository") { + (Some(opt.repository.as_str()), url) + } else if opt.repository == "pypi" { + (Some("pypi"), PublishOpt::DEFAULT_REPOSITORY_URL.to_string()) + } else if opt.repository == "testpypi" { + ( + Some("testpypi"), + PublishOpt::TEST_REPOSITORY_URL.to_string(), + ) + } else { + bail!( + "Failed to get registry {} in .pypirc. \ + Note: Your index didn't start with http:// or https://, \ + which is required for non-pypirc indices.", + opt.repository + ); + }; + let (username, password) = resolve_pypi_cred(opt, &pypirc, registry_name); let registry = Registry::new(username, password, registry_url); Ok(registry)