From 35579dade02e84e362ef9befefad78baf6330437 Mon Sep 17 00:00:00 2001 From: Matteo De Wint Date: Sun, 14 Jan 2024 15:41:32 +0100 Subject: [PATCH] fix: correctly parse source distribution names with hyphens --- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- s3pypi/__init__.py | 2 +- s3pypi/core.py | 9 ++++++++- setup.cfg | 2 +- tests/unit/test_core.py | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2519c08..8eb13ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/). +## 2.0.1 - 2024-01-14 + +### Fixed + +- Correctly parse source distribution names with hyphens, since setuptools does not + produce normalised names. See + [pypa/setuptools#3593](https://github.com/pypa/setuptools/issues/3593). + + ## 2.0.0 - 2024-01-06 ### Added diff --git a/pyproject.toml b/pyproject.toml index 9b492e4..f64a4ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "s3pypi" -version = "2.0.0" +version = "2.0.1" description = "CLI for creating a Python Package Repository in an S3 bucket" authors = [ "Matteo De Wint ", diff --git a/s3pypi/__init__.py b/s3pypi/__init__.py index dec3ee0..4ba9c9a 100644 --- a/s3pypi/__init__.py +++ b/s3pypi/__init__.py @@ -1,2 +1,2 @@ __prog__ = "s3pypi" -__version__ = "2.0.0" +__version__ = "2.0.1" diff --git a/s3pypi/core.py b/s3pypi/core.py index 3a87c49..60aa365 100644 --- a/s3pypi/core.py +++ b/s3pypi/core.py @@ -87,7 +87,14 @@ def parse_distribution_id(filename: str) -> DistributionId: if not ext: raise S3PyPiError(f"Unknown file type: {filename}") - name, version = filename[: -len(ext)].split("-", 2)[:2] + stem = filename[: -len(ext)] + + if ext == ".whl": + name, version = stem.split("-", 2)[:2] + else: + name, version = stem.rsplit("-", 1) + name = name.replace("-", "_") + return DistributionId(name, version) diff --git a/setup.cfg b/setup.cfg index b31db2c..44c228d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.0 +current_version = 2.0.1 commit = True message = chore: bump version to {new_version} diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py index f490bae..410c43d 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -18,6 +18,7 @@ def test_normalize_package_name(name, normalized): @pytest.mark.parametrize( "filename, dist", [ + ("hello-world-0.1.0.tar.gz", core.DistributionId("hello_world", "0.1.0")), ("hello_world-0.1.0.tar.gz", core.DistributionId("hello_world", "0.1.0")), ("foo_bar-1.2.3-py3-none-any.whl", core.DistributionId("foo_bar", "1.2.3")), ],