This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Use importlib.resources in venv
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: barry, brett.cannon, vinay.sajip
Priority: low Keywords:

Created on 2019-07-25 17:50 by brett.cannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg348448 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-07-25 17:50
Right now the venv module directly reads the file system to find the activation scripts and then copies them over. Moving over to importlib.resources would be a more portable solution.

Unfortunately the venv API is specifically tied to the file system via EnvBuilder.install_scripts() (https://github.com/python/cpython/blob/master/Lib/venv/__init__.py#L341). I'm not sure how doable this idea would be due to this.
msg351429 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-09-09 11:10
The install_scripts() API is intended to allow users to add their own venv-specific scripts from their own project folders. We could add an install_resources() method, which would add all the resources in a given package. The signature would be

    def install_resources(self, context, package_name):
        ...

To do this for the existing scripts directory would require adding __init__.py files to each directory in this scripts tree, right? This wouldn't really give any particular benefits, as the __init__.py files would need to be filtered out when copying to the venv's binaries folder.
msg351518 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-09-09 16:20
Since no one has ever asked for this I won't worry about it. This was mostly to start using the proper API for reading data out of a package, but it isn't critical.
msg351535 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2019-09-09 16:56
See also this ticket: https://gitlab.com/python-devs/importlib_resources/issues/58

We've basically agreed that you should be able to load resources from subdirectories that aren't packages.  It turns out to be not a simple change in importlib.resources, but contributions are welcome!
msg351603 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-09-10 09:50
> We've basically agreed that you should be able to load resources from subdirectories that aren't packages.  It turns out to be not a simple change in importlib.resources, but contributions are welcome!

In case anyone is interested, I've already done this in distlib.resources:

https://distlib.readthedocs.io/en/latest/reference.html#the-distlib-resources-package

Possibly a similar approach could be used.
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81864
2019-09-10 09:50:09vinay.sajipsetmessages: + msg351603
2019-09-09 16:56:20barrysetmessages: + msg351535
2019-09-09 16:20:31brett.cannonsetstatus: open -> closed
resolution: rejected
messages: + msg351518

stage: resolved
2019-09-09 11:10:59vinay.sajipsetmessages: + msg351429
2019-07-25 17:50:21brett.cannoncreate