Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use build.util.project_wheel_metadata to get the package dependencies/requirements #42

Open
wwuck opened this issue Jul 29, 2021 · 4 comments

Comments

@wwuck
Copy link
Contributor

wwuck commented Jul 29, 2021

It looks like there is finally a standard supported way to get the package dependencies/requirements via PEP517.

pypa/build#181

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.

@koobs
Copy link

koobs commented Jul 30, 2021

@wwuck What are your thoughts on shipping this as its own PyPI package, to:

a) make it easily available accessible
b) provide a stable home until such time as an easily invokable access method is provided by build?
c) discourage copy/pasta/variations/inconsistencies over time
d) as a sandbox/experimental area to validate, prove out and provide examples for adding additional conveniences / Quality of Life stuff to build or other PyCA projects

@arkq
Copy link
Owner

arkq commented Jul 30, 2021

It looks like there is finally a standard supported way to get the package dependencies/requirements via PEP517.

What are your thoughts on shipping this as its own PyPI package, to

The same objections are on my side. It does not look like a standard way of getting package dependencies. It's more like "it can be done". Anyway, nice work. So, I think that I will wait until there is an actual API for getting dependencies in build or pep517 packages. From my side I do not care where it will be, but I do care about potential "API" breakages.

@wwuck
Copy link
Contributor Author

wwuck commented Jul 30, 2021

I'm somewhat in agreement @arkq, except its hard to know if a "standard API" will ever appear given previous comments from some of the PyPA people. In any case, I'm guessing it would just be some sort of wrapper around the example from pypa/build#181.

At least that bug has now been re-opened so there is hope that something more "standard" may appear sooner rather than later.

@wwuck
Copy link
Contributor Author

wwuck commented Sep 17, 2021

@arkq It’s finally arrived?

pypa/build#181 (comment)

@wwuck wwuck changed the title Use build and pep517 to get the package dependencies/requirements Use build.util.project_wheel_metadata to get the package dependencies/requirements Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants