Download Python PEX

I'm trying to wrap my head around the pexon pex utility ( https://pex.readthedocs.org/en/latest/ ) for bundling some applications into .pex files for deployment.

My app is not big enough to require tweeter building tools, and I also have some assembly requirements that pants don't address. However, I tried to build a pants build system with help python_binary

, which resulted in the source pex files being loaded into the pex root directory. The pants BUILD files accept a property sources

for python_binary, which can be a glob for files in the directory where the build is being performed, however the pants use the pex API, not the command line utility.

The problem is that I am using the pex command line utility on its own, it seems to want to get distributions (i.e. folders configured with setup.py, etc.) and wants to set my code to .deps folder in the pex file, not just copying the python files to the root of the pex file like pants.

Can't copy files (not install the package) through the command line pex tool?

+3


source to share


1 answer


As with pex 1.0.0, there is no way to quickly access files and directories, you must have setup.py as you suggest, or use pants (no longer Twitter, by the way - independent).

So you have 3 ways forward (# 1 that you already know, but this is a fix for others):



  • Create setup.py and point the pex tool in your directory

    $ tree -h
    .
    ├── [4.0K]  lib
    │   ├── [   0]  __init__.py
    │   ├── [  38]  lib.py
    │   └── [  68]  main.py
    └── [  76]  setup.py
    
    1 directory, 4 files
    $ cat lib/lib.py 
    def func():
        return 'func in lib'
    
    $ cat lib/main.py 
    from .lib import func
    
    if __name__ == '__main__':
        print(func())
    
    $ cat setup.py 
    from setuptools import setup
    
    setup(
        name='lib',
        packages=['lib']
    )
    
    $ pex . -e lib.main -o lib.pex
    $ ./lib.pex 
    func in lib
    
          

    Note: .

    on the command line, pex is the bit indicating pex in that setup.py directory

  • Ask pex to maintain a set of files instead of requiring /setup.py. You can do it here .

  • Problems with files against pants to support claims you have that it does not address. You can do it here

As a member of the trousers team, I can say that we are working to make the trousers easier and easier to use, so that no project is too small. You should be able to pip install pantsbuild.pants.backend.python && touch pants.ini

both work and work in the python repo only, but we are not here today.

+5


source







All Articles