Skip to content

Support only packaging specified requirements rather than the whole venv #1388

@nickovs

Description

@nickovs

Currently "Zappa will automatically package your active virtual environment", which means that by default everything you are using for testing, linting, formatting and developing your code, and all the things that they depend upon, get included. While it is possible to exclude specific packages from the build, you need to know which ones are dependencies of your code and which are dependencies of the test environment. This tends to lead to package bloat.

It would be very helpful if Zappa supported providing a requirements file, and then only bundled up the packages listed in there and their dependencies. This would be in keeping with line two of the Zen of Python:

Explicit is better than implicit.

A generalised tool to resolve all dependencies is large and complex, but given the way that Zappa works at the moment, it doesn't need a generalised tool; all that is needed is a filter to limit which of the packages that are in the current virtual environment get packaged. For this all you need to do is parse the requirements (by calling packaging.requirements.Requirement on each meaningful line of the file), check the dependencies of the currently installed version (using importlib.metadata.requires(), checking the 'extra' tags), and repeat until you've done them all. This would yield a subset of the installed packages that is at least as version-consistent as the local venv and would not contain anything that has not explicitly been requested.

Would anyone else find this useful?

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-reviewNeeds attention from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions