fresh-cat-90827
06/13/2022, 11:42 AM.pex
properly without using Pants (using standalone pex
utility). The sources directory is not copied itself, only its contents. See the thread.fresh-cat-90827
06/13/2022, 11:43 AM./pants package helloworld:pex_binary
, then the .pex
file is produced having the helloworld
directory with the sources under it.
├── .bootstrap
│ └── pex
├── .deps
│ ├── ansicolors-1.1.8-py2.py3-none-any.whl
│ ├── setuptools-56.2.0-py3-none-any.whl
│ └── types_setuptools-57.4.14-py3-none-any.whl
├── PEX-INFO
├── __main__.py
├── helloworld
│ ├── __init__.py
│ ├── greet
│ ├── main.py
│ └── translator
If I run pex
on its own with: pex --requirement=requirements.txt --sources-directory=helloworld -m main -o dist/purepex.pex
, then the root helloworld
directory is not included:
├── .bootstrap
│ └── pex
├── .deps
│ ├── ansicolors-1.1.8-py2.py3-none-any.whl
│ ├── setuptools-56.2.0-py3-none-any.whl
│ └── types_setuptools-57.4.17-py3-none-any.whl
├── BUILD
├── PEX-INFO
├── __init__.py
├── __main__.py
├── greet
├── main.py
└── translator
Running the .pex
file won’t work because of the import
line (there isn’t helloworld
package, because the greet
and translator
ended up in the “root” of the .pex
):
from helloworld.greet.greeting import Greeter
ModuleNotFoundError: No module named 'helloworld'
I wonder if it’s possible to do with pex
what Pants does and copy the sources directory itself, not just its contents?
The only workaround I found is to copy the helloworld
directory into another directory:
$ mkdir dummy-placeholder; cp -r helloworld dummy-placeholder/helloworld/
$ pex --requirement=requirements.txt --sources-directory=dummy-placeholder -m helloworld.main -o dist/purepex.pex
Is it what I have to do or is there a better way?fresh-cat-90827
06/14/2022, 9:22 AMenough-analyst-54434
06/15/2022, 6:46 PMpex
package at repo root:
$ python -mpex -D . -m pex -o pex-with-lots-of-extra-files-too.pex
jsirois@siroisdesign:~/pex$ ./pex-with-lots-of-extra-files-too.pex -V 2.1.92
$ zipinfo -1 pex-with-* | head .bootstrap/
.bootstrap/pex/
.bootstrap/pex/__init__.py
.bootstrap/pex/__main__.py
.bootstrap/pex/argparse.py
.bootstrap/pex/attrs.py
.bootstrap/pex/auth.py
.bootstrap/pex/bootstrap.py
.bootstrap/pex/common.py
.bootstrap/pex/compatibility.py
$ zipinfo -1 pex-with-* | tail
tests/test_variables.py
tests/test_vendor.py
tests/tools/
tests/tools/__init__.py
tests/tools/commands/
tests/tools/commands/__init__.py
tests/tools/commands/test_interpreter_command.py
tests/tools/commands/test_repository.py
tests/tools/commands/test_venv.py
tox.ini
fresh-cat-90827
06/15/2022, 9:54 PM-D .
did the trick! Will now try to convert packaging workflows for repos outside of the Pants monorepo to use pex
instead!fresh-cat-90827
06/16/2022, 10:16 AMpex
won’t let me choose what directories to copy? E.g. say I don’t want to tests
from your example above.enough-analyst-54434
06/16/2022, 12:19 PMpex pex/git/clone/directory -c pex -o much-tidier.pex
enough-analyst-54434
06/17/2022, 2:20 AMpex --requirement=requirements.txt --sources-directory=".|helloworld" -m main -o dist/purepex.pex
work for you? That uses new syntax for -D / --sources-directory
where you can mention the module or package name to restrict the sources directory addition to after a pipe symbol. The symbol could also probably be :
.enough-analyst-54434
06/17/2022, 2:23 AMfresh-cat-90827
06/17/2022, 8:26 AM--sources-directory
argument is worth it — I realized now that most likely I’d want to include a few directories (sources, resources directories, etc), and standalone files (license files etc). So I think I am better off creating a new directory, copying everything I need into it, and then passing it as a sources directory. This of course is wrapped in a shell script 🙂enough-analyst-54434
06/17/2022, 1:22 PM