Open
Description
It looks like there is finally a standard supported way to get the package dependencies/requirements via PEP517.
From the end of the discussion on that issue, something like this should work:
import tempfile
from importlib.metadata import PathDistribution
from pathlib import Path
import pep517.wrappers
from build import ProjectBuilder
from packaging.requirements import Requirement
# replace "." with the package directory
builder = ProjectBuilder(".", runner=pep517.wrappers.quiet_subprocess_runner)
with tempfile.TemporaryDirectory() as tmpdir:
distribution = PathDistribution(Path(builder.metadata_path(tmpdir)))
requires = [Requirement(i) for i in distribution.requires]
for x in requires:
print(type(x))
print(x)
This should work for any package/project that uses a PEP517 compatible build backend, eg. setuptools, flit, poetry, whey, etc. I've only tested it myself on https://github.com/pypa/sampleproject which uses setuptools.
EDIT: https://pypa-build.readthedocs.io/en/latest/api.html#build.util.project_wheel_metadata is now available and should be sufficient for this feature.
Metadata
Metadata
Assignees
Labels
No labels
Activity