Skip to content

Commit

Permalink
feat: allow additional sdist formats (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwint authored Dec 19, 2022
1 parent 785699c commit d36c278
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)

## Unreleased

### Added

- Allow uploading source distributions with `.tar.bz2`, `.tar.xz`, and `.zip` extensions.

### Changed

- Require Python 3.7 or greater.
Expand Down
12 changes: 8 additions & 4 deletions s3pypi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ def upload_packages(


def parse_distribution(path: Path) -> Distribution:
if path.name.endswith(".tar.gz"):
name, version = path.name[:-7].rsplit("-", 1)
elif path.suffix == ".whl":
extensions = (".whl", ".tar.gz", ".tar.bz2", ".tar.xz", ".zip")

ext = next((ext for ext in extensions if path.name.endswith(ext)), "")
if not ext:
raise S3PyPiError(f"Unknown file type: {path}")

if ext == ".whl":
meta = extract_wheel_metadata(path)
name, version = meta["Name"], meta["Version"]
else:
raise S3PyPiError(f"Unknown file type: {path}")
name, version = path.name[: -len(ext)].rsplit("-", 1)

return Distribution(name, version, path)

Expand Down
1 change: 1 addition & 0 deletions tests/data/dists/xyz-0.1.0.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xyz
1 change: 1 addition & 0 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def assert_pkg_exists(prefix: str, filename: str):

assert_pkg_exists("foo/", "foo-0.1.0.tar.gz")
assert_pkg_exists("hello-world/", "hello_world-0.1.0-py3-none-any.whl")
assert_pkg_exists("xyz/", "xyz-0.1.0.zip")


def test_main_upload_package_exists(chdir, data_dir, s3_bucket, caplog):
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import pytest

from s3pypi import core
Expand All @@ -13,3 +15,23 @@
)
def test_normalize_package_name(name, normalized):
assert core.normalize_package_name(name) == normalized


@pytest.mark.parametrize(
"dist",
[
core.Distribution(
name="hello-world",
version="0.1.0",
local_path=Path("dist/hello-world-0.1.0.tar.gz"),
),
core.Distribution(
name="foo-bar",
version="1.2.3",
local_path=Path("dist/foo-bar-1.2.3.zip"),
),
],
)
def test_parse_distribution(dist):
path = dist.local_path
assert core.parse_distribution(path) == dist

0 comments on commit d36c278

Please sign in to comment.