1

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.

Arne
  • 17,706
  • 5
  • 83
  • 99

1 Answers1

1

My project johnnydep has precisely this feature for generating dependencies from an uninstalled wheel file.

pip install johnnydep
johnnydep your-wheel-file.whl --output-format=pinned

Demo:

$ johnnydep johnnydep-0.5-py2.py3-none-any.whl --output-format pinned
johnnydep==0.5
anytree==2.4.3
cachetools==2.1.0
colorama==0.3.9
oyaml==0.7
packaging==18.0
pip==18.0
pkginfo==1.4.2
pytoml==0.1.19
setuptools==40.4.3
structlog==18.2.0
tabulate==0.8.2
wheel==0.32.1
wimpy==0.4
six==1.11.0
pyyaml==3.13
pyparsing==2.2.2
wim
  • 338,267
  • 99
  • 616
  • 750