I'd like to embed console_scripts in a pex file and be able to use them by 
specifying them when invoking the pex file.

The details are...
Python module with the following file structure:

    .
    ├── mefoo
    │   ├── __init__.py
    │   ├── bar.py
    │   └── command_line
    │       ├── __init__.py
    │       ├── cli1.py
    │       └── cli2.py
    └── setup.py

Stripped down `setup.py` is 

    #!/usr/bin/env python3
    
    import setuptools
    
    setuptools.setup(
        name='mefoo',
        version='0.0.1',
        entry_points={
            'console_scripts' : [
                'mefoo1 = mefoo.command_line.cli1:main',
                'mefoo2 = mefoo.command_line.cli2:main'
                ]
            },
        scripts=['scripts/mefooscript1'],
        packages=setuptools.find_packages()
        )

Build a wheel with `python3 setup.py sdist bdist_wheel` which outputs to `dist` 
directory.
Install wheel with `pip install --no-index dist/mefoo-0.0.1-py3-none-any.whl`
This correctly creates my `console_script` entry point so from command prompt I 
can call:

    > mefoo1
    Could not open mefoo1 in the environment [./themefoo.pex]: [Errno 2] No 
such file or directory: 'mefoo1'

Then I move on and create a pex file:

    pex --python=python3 --disable-cache --no-index --find-links=./dist mefoo 
--output-file themefoo.pex -v

This creates a pex file, but attempts to use the `console_script` entry point 
fails.

    > ./themefoo.pex mefoo1

*How do I make this work ?*

What I can do is specify the `console_script` entry point as an entry point to 
pex

<pre><code>
    pex --python=python3 --disable-cache --no-index --find-links=./dist <b>-c 
mefoo1</b> mefoo --output-file themefoo.pex -v
</code></pre>

Unzipping the pex file doesn't shows it doesn't contain any extra archived 
content, so I'm guessing there's some extra config embedded in the file itself 
which is interpreted appropriately.

The [wheel documentation](https://wheel.readthedocs.io/en/stable/) talks about 
`install-scripts`, but I cannot work out how to use it.
The docs mention:
> If the scripts are needed, use a real installer like pip. The wheel
> tool python -m wheel install-scripts package [package …] can also be
> used at any time to call setuptools to write the appropriate scripts
> wrappers.

I'm not sure what writing the appropriate script wrappers means.

There's some discussion leading to `install-scripts` being implemented 
[here](https://github.com/pypa/pip/issues/1067), and I had a look at the code 
but couldn't work out whether this addresses my problem.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to