In PEX I can ship arbitrary directories using `-D`...
# general
In PEX I can ship arbitrary directories using
- these end up in the target
. Is there a way to install data files outside
as well, without using or Python build mechanisms? If not, I can repurpose
to ship data files into, say
. However is there an easy way to discover the path of the venv when running the pex-file? We build with pex tools but do not unpack the pex-file manually.
There is no way to add data files besides a Python build mechanism of your choice at the moment. The venv path is exported in
per the tradition. The original virtualenv tool:
Copy code
$ pex virtualenv -c virtualenv -- test.virtualenv
created virtual environment in 225ms
  creator CPython3Posix(dest=/home/jsirois/dev/BruceEckel/tmp-pants-bug/test.virtualenv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/jsirois/.local/share/virtualenv)
    added seed packages: pip==22.3.1, setuptools==65.6.3, wheel==0.38.4
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
$ source test.virtualenv/bin/activate
(test.virtualenv) $ echo $VIRTUAL_ENV
(test.virtualenv) $ deactivate
Python builtin venv module:
Copy code
$ python3.7 -mvenv test.venv
$ source test.venv/bin/activate
(test.venv) $ echo $VIRTUAL_ENV
(test.venv) $ deactivate
Copy code
$ pex --venv -- -c 'import os; print(os.environ["VIRTUAL_ENV"])'
Alternatively, one way to handle this would be to use pkgutil or importlib to load the data files as resources. Another would be to add a utility module side-by-side with the data files with a function that returned the paths to the files using
Copy code
has ~contents:
Copy code
def data_files() -> Iterable[str]:
  me = PurePath(__file__)
  return [f for f in me.parent.iterdir() if f != me]
@abundant-autumn-67998 all that said, I have never really understood data files. From my work on Pex I've seen lots of distributions through bug reports and fwict where data files end up going seems semi-random from dist to dist. From a logical perspective, I get that data files are distinct from sys.path contents, but - unless the data files include .py files you never want imported by mistake, I have never understood why, in a post-egg world, placing them anywhere other than in site-packages inside your installed dist tree, was a thing. If you know this world and there is some standard for data files, I'd be happy to have Pex grow a
option similar to the existing
for convenience.
Ah we could use
. I said data files but really this is for code. We support a lightweight way to deploy code outside any python package by just pointing a directory with a .py file. I don't think any special data file support is needed since we could put this in a special directory in site-packages. Data files within a package are easily supported by