Skip to content

Commit

Permalink
Properly convert resolved packages to pep 508 dependencies using class
Browse files Browse the repository at this point in the history
method instead of manual construction of the Dependency object.

Backfill in_extras when building wheel with --only-lock option.  Fixes
#8
  • Loading branch information
spoorn committed Sep 6, 2022
1 parent 2de2866 commit 793b1bb
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 51 deletions.
22 changes: 17 additions & 5 deletions src/poeblix/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def _write_metadata(self, wheel: zipfile.ZipFile) -> None:
if self._no_lock:
logger.info("Excluding lock dependencies from wheel as --no-lock was specified")
else:
from poetry.core.packages.dependency import Dependency

logger.info("Adding dependencies from lock file to wheel build")
# There is currently a bug with poetry 1.2.0b1 where the `category` field in poetry.lock all gets set to
Expand Down Expand Up @@ -108,17 +107,30 @@ def _write_metadata(self, wheel: zipfile.ZipFile) -> None:
# 'pyproject.toml' are also on the 'poetry.lock' file,
# so no direct dependencies will be missed when the wheel
# is built. Only package versions may vary.

in_extras = {}
if self._only_lock:
# in_extras is backfilled in factory.py:
# https://github.com/python-poetry/poetry-core/blob/8097f67d0760bad5989219483c59339e1eed549c/src/poetry/core/factory.py#L176-L187
# keep a record of these so if we are building with only_lock enabled, we preserve the in_extras
for p in self._poetry.package.requires:
in_extras[p.pretty_name] = p.in_extras
self._meta.requires_dist = []

requires_dist = self._meta.requires_dist
required_packages_names = [p.pretty_name for p in self._poetry.package.requires]
logger.debug(f"Adding to Wheel Requires Dist: {ops}")
for op in ops:
dependency_package = op.package
name = dependency_package.pretty_name
version = dependency_package.version
dep = Dependency(name, version).to_pep_508(False)
dep_pack = op.package
name = dep_pack.pretty_name
# Exclude python version constraints from the wheel file Required-Dist as default
# otherwise, most of the deps will have a verbose python version constraint with it
dep_pack.python_versions = "*"
dependency = dep_pack.to_dependency()
# Backfill in_extras
if self._only_lock and name in in_extras:
dependency.in_extras.extend(in_extras[name])
dep = dependency.to_pep_508()
if self._only_lock or name not in required_packages_names:
requires_dist.append(dep)

Expand Down
Binary file not shown.
90 changes: 58 additions & 32 deletions test/positive_cases/happy_case_example/poetry.lock

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

5 changes: 5 additions & 0 deletions test/positive_cases/happy_case_example/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ authors = ["spoorn <spookump@gmail.com>"]
python = "^3.9"
nemoize = "^0.1.0"
pandas = "1.4.2"
# https://github.com/spoorn/poeblix/issues/8
gunicorn = { version = "^19.9.0", optional = true }

[tool.poetry.extras]
gunicorn = ["gunicorn"]

[tool.poetry.group.dev.dependencies]
flake8 = "^4.0.1"
Expand Down
Binary file not shown.
34 changes: 27 additions & 7 deletions test/positive_cases/only_lock/poetry.lock

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

5 changes: 5 additions & 0 deletions test/positive_cases/only_lock/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ authors = ["spoorn <spookump@gmail.com>"]
python = "^3.9"
nemoize = "^0.1.0"
pandas = ">=1.3"
# https://github.com/spoorn/poeblix/issues/8
gunicorn = { version = "^19.9.0", optional = true }

[tool.poetry.extras]
gunicorn = ["gunicorn"]

[tool.poetry.group.dev.dependencies]
flake8 = "^4.0.1"
Expand Down
Loading

0 comments on commit 793b1bb

Please sign in to comment.