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

Fix pypi/testpypi upload #2229

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct PublishOpt {
}

impl PublishOpt {
// Here we omit trailing slashes from the repository URL, which we'll add back in `complete_registry`
const DEFAULT_REPOSITORY_URL: &'static str = "https://upload.pypi.org/legacy";
const TEST_REPOSITORY_URL: &'static str = "https://test.pypi.org/legacy";

Expand Down Expand Up @@ -317,20 +318,32 @@ fn complete_registry(opt: &PublishOpt) -> Result<Registry> {
let (registry_name, registry_url) = if let Some(repository_url) = opt.repository_url.as_deref()
{
// to normalize URLs by removing trailing slashes
let name = match repository_url.trim_end_matches('/') {
PublishOpt::DEFAULT_REPOSITORY_URL => Some("pypi"),
PublishOpt::TEST_REPOSITORY_URL => Some("testpypi"),
_ => None,
};
(name, repository_url.to_string())
match repository_url.trim_end_matches('/') {
PublishOpt::DEFAULT_REPOSITORY_URL => (
Some("pypi"),
// Add trailing slash back
format!("{}/", PublishOpt::DEFAULT_REPOSITORY_URL),
),
PublishOpt::TEST_REPOSITORY_URL => (
Some("testpypi"),
// Add trailing slash back
format!("{}/", PublishOpt::TEST_REPOSITORY_URL),
),
_ => (None, 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())
(
Some("pypi"),
// Add trailing slash back
format!("{}/", PublishOpt::DEFAULT_REPOSITORY_URL),
)
} else if opt.repository == "testpypi" {
(
Some("testpypi"),
PublishOpt::TEST_REPOSITORY_URL.to_string(),
// Add trailing slash back
format!("{}/", PublishOpt::TEST_REPOSITORY_URL),
)
} else {
bail!(
Expand Down
Loading