Skip to content

Commit

Permalink
feat: gracefully handle wheels with no dependencies (#21)
Browse files Browse the repository at this point in the history
Skip wheels with no `Requires-Dist` lines, rather than trying and failing to freeze them.
  • Loading branch information
DBS-ST-VIT authored Jan 7, 2025
1 parent 87ded2c commit 92efa51
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/poetry_plugin_freeze/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def get_frozen_deps(self, dep_packages, exclude_packages=None):

def replace_deps(self, dist_meta, dep_lines):
start_pos = 0
for m in dist_meta.get_all("Requires-Dist"):

for m in dist_meta.get_all("Requires-Dist", ()):
if not start_pos:
start_pos = dist_meta._headers.index(("Requires-Dist", m))
dist_meta._headers.remove(("Requires-Dist", m))
Expand Down Expand Up @@ -316,7 +317,8 @@ def freeze_wheel(self, wheel_path, dep_packages):
deps = self.get_path_deps(MAIN_GROUP)
deps.update(dep_packages)
dep_lines = self.get_frozen_deps(deps, self.exclude_packages)
self.replace_deps(dist_meta, dep_lines)
if dep_lines:
self.replace_deps(dist_meta, dep_lines)

with source_whl.open(record_path) as record_fh:
record_text = self.freeze_record(record_fh, dist_meta, md_path)
Expand Down
Empty file.
Binary file not shown.
144 changes: 144 additions & 0 deletions tests/fixtures/nested_packages/others/app_no_deps/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tests/fixtures/nested_packages/others/app_no_deps/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "app_no_deps"
description = "lorem ipsum"
version = "0.2"
authors = ["SideCars"]
license = "Apache-2.0"
packages = [
{ include = "app_no_deps" }]

[tool.poetry.dependencies]
python = "^3.10"

[tool.poetry.group.dev.dependencies]
app_b = {path = "../..", develop = true}

[build-system]
requires = ["poetry>=0.12", "setuptools"]
build-backend = "poetry.masonry.api"

62 changes: 62 additions & 0 deletions tests/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_project_roots(fixture_root):
assert sorted(project_roots(fixture_root)) == [
fixture_root / "nested_packages",
fixture_root / "nested_packages" / "others" / "app_c",
fixture_root / "nested_packages" / "others" / "app_no_deps",
fixture_root / "nested_packages" / "others" / "app_with_extras",
fixture_root / "non_poetry_package",
]
Expand Down Expand Up @@ -168,6 +169,67 @@ def test_freeze_nested(fixture_root, fixture_copy):
assert get_sha256_digest(md_bytes) == "ZTdp4AJVW1WFj_Wv5oUVdtUC1_5r9bYWNxDzssJgO6o"


def test_freeze_no_deps(fixture_root, fixture_copy):
package = fixture_copy(fixture_root / "nested_packages")
sub_package = fixture_copy(fixture_root / "nested_packages" / "others" / "app_no_deps")

iced_pkg = IcedPoet(package)
iced_sub = IcedPoet(sub_package)
fridge = {iced_pkg.name: iced_pkg, iced_sub.name: iced_sub}
iced_sub.set_fridge(fridge)

wheels = iced_sub.freeze()
assert len(wheels) == 1

wheel = zipfile.ZipFile(wheels[0])

records = parse_record(
wheel.open(f"{iced_sub.distro_name}-{iced_sub.version}.dist-info/RECORD").read()
)
md = parse_md(
wheel.open(f"{iced_sub.distro_name}-{iced_sub.version}.dist-info/METADATA").read()
)

expected_headers = [
("Metadata-Version", "2.1"),
("Name", "app_no_deps"),
("Version", "0.2"),
("Summary", "lorem ipsum"),
("License", "Apache-2.0"),
("Author", "SideCars"),
("Requires-Python", ">=3.10,<4.0"),
("Classifier", "License :: OSI Approved :: Apache Software License"),
("Classifier", "Programming Language :: Python :: 3"),
("Classifier", "Programming Language :: Python :: 3.10"),
("Classifier", "Programming Language :: Python :: 3.11"),
("Classifier", "Programming Language :: Python :: 3.12"),
]
assert sorted(md._headers) == sorted(expected_headers)

assert records == [
[
"app_no_deps/__init__.py",
"sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU",
"0",
],
[
"app_no_deps-0.2.dist-info/WHEEL",
"sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg",
"88",
],
["app_no_deps-0.2.dist-info/RECORD", "", ""],
[
"app_no_deps-0.2.dist-info/METADATA",
"sha256=VX5SQgKuWZ04guxl1ZXZAOsK49nxKioLba_W4k0SzXE",
"405",
],
]

md_bytes = wheel.open(f"{iced_sub.distro_name}-{iced_sub.version}.dist-info/METADATA").read()
assert len(md_bytes) == 405
assert get_sha256_digest(md_bytes) == "VX5SQgKuWZ04guxl1ZXZAOsK49nxKioLba_W4k0SzXE"


def test_freeze_extras(fixture_root, fixture_copy):
nested_packages = fixture_copy(fixture_root / "nested_packages")

Expand Down

0 comments on commit 92efa51

Please sign in to comment.