packaging icon indicating copy to clipboard operation
packaging copied to clipboard

Allow requirement.Marker.evaluate() with arbitrary environment

Open pombredanne opened this issue 3 years ago • 1 comments

One of the use case of the packaging library is to support tooling that may run in a different environment than the processed packages are intended for. For instance, I may want to process a Requirement.marker and evaluate() it on a different platform environment that is not the environment of the current Python interpreter. However, the evaluate() method environment arg can only update the environment and can never override/replace it entirely. https://github.com/pypa/packaging/blob/8c78c35bc20fc7b4aacb7a71ad5f5db9817630c1/packaging/markers.py#L302

It would be useful for tools to be able to entirely override the environment rather than just updating it.

pombredanne avatar May 25 '21 06:05 pombredanne

But for replacing to work, don’t you need to pass the whole environment anyway? In which case the dict.update would simply replace everything from the original environment. Or am I missing something?

With that said, the fact that packaging currently implicitly depending a lot on the current environment is problematic (not just packaging.markers, but packaging.tags as well). It would be much easier to work with it if instead of providing a point for partial override, the user is always required to pass in a complete environment to replace the current one (and we can provide some helper functions to generate a complete environment dict).

uranusjr avatar May 25 '21 11:05 uranusjr