I'm trying to generate a list of requirements from a local uninstalled wheel. Simply getting the list that was fed as the packages
parameter into setup.py
's setuptools.setup
-call would be optimal. The output that a pip freeze
would generate if the wheel were installed could work, too.
Slightly more context
I want to build a docker image that is going to be used in a CI chain. In order to cut down on pipeline time, it should come front-loaded with all runtime dependencies. But at the point where the image is built, the python package is not built yet, and building the package outside of the chain merely for obtaining a requirements.txt
is cumbersome and error-prone.
Things I tried
Hacking it into the Dockerfile:
python -c $'\
import setuptools\n\
setuptools.setup = lambda *args, **kwargs: None\n\
exec(compile(open("setup.py").read(), "setup.py", "exec"))\n\
for requirement in requirements: print(requirement)\n' > python_packages.txt
# `requirements` is the name of variable that holds the package list
This doesn't work very well because docker does weird things with its build context. Having any code in setup.py
that accesses local files (such as, for example, fetching the current version number from a VERSION
file) breaks this hack.
Fixing the docker-build context so that this code works would solve my problem, but I'd prefer a proper solution that doesn't implicitly rely on how stuff looks in setup.py
.
Using pip/pipreqs/pipenv/pipdeptree:
All of these tools work on top of local environments, and can't handle an uninstalled wheel. This answer comes quite close using pip
, but 1) only works if the package is uploaded at pyPI (which my target package isn't) and 2) does a hefty dry-build to get the package list.