Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow specifying a script to run in lieu of an entry point #59

Closed
wickman opened this issue Apr 5, 2015 · 10 comments
Closed

allow specifying a script to run in lieu of an entry point #59

wickman opened this issue Apr 5, 2015 · 10 comments
Milestone

Comments

@wickman
Copy link
Contributor

wickman commented Apr 5, 2015

If you build a simple flask app but don't want to go through the ceremony of defining a setup.py and the like, you should be able to just do 'pex -r flask_requirements.txt --entry_script=my_flask.py -o my_flask.pex' rather than have to keep the two separate.

@wickman wickman added this to the 1.0 milestone Apr 5, 2015
@warsaw
Copy link
Contributor

warsaw commented Apr 5, 2015

Would this help the following situation? I've had someone try my instructions at http://www.wefearchange.org/2015/04/creating-python-snaps.html but he wasn't able to make it work because his project doesn't use entry points. https://pypi.python.org/pypi/ssh-import-id He just has some scripts that get install in bin.

@wickman
Copy link
Contributor Author

wickman commented Apr 5, 2015

sure, I see no reason why it couldn't be used to support that use-case.

I've been thinking for a while it'd be useful, as an example of how to use pex as a library, to write a small application that takes a .tar.gz or requirement and spits out pex files for each of its entry_points and scripts that you could then take and drop in ~/local/bin or what have you.

@warsaw
Copy link
Contributor

warsaw commented Apr 5, 2015

On Apr 05, 2015, at 10:51 AM, brian wickman wrote:

I've been thinking for a while it'd be useful, as an example of how to use
pex as a library, to write a small application that takes a .tar.gz or
requirement and spits out pex files for each of its entry_points and scripts
that you could then take and drop in ~/local/bin or what have you.

That would be pretty awesome :)

@wickman
Copy link
Contributor Author

wickman commented Apr 13, 2015

@jdevera
Copy link

jdevera commented Jul 24, 2015

I see this issue is closed but when I try to do exactly what is described here pex fails:

⌂ ↬  pex -r requirements.txt --script git-branches.py -o git-branches2.pex
Traceback (most recent call last):
  File "/home/jdevera/.local/bin/pex", line 9, in <module>
    load_entry_point('pex==1.0.1', 'console_scripts', 'pex')()
  File "/home/jdevera/.local/lib/python2.7/site-packages/pex/bin/pex.py", line 509, in main
    pex_builder = build_pex(reqs, options, resolver_options_builder)
  File "/home/jdevera/.local/lib/python2.7/site-packages/pex/bin/pex.py", line 486, in build_pex
    pex_builder.set_script(options.script)
  File "/home/jdevera/.local/lib/python2.7/site-packages/pex/pex_builder.py", line 207, in set_script
    raise self.InvalidExecutableSpecification('Could not find script %s in PEX!' % script)
pex.pex_builder.InvalidExecutableSpecification: Could not find script git-branches.py in PEX!

It looks exactly like the use case mentioned in the first message, where I did not create a package for my little git-branches script, I just want to create a pex so I can run it with its dependencies.

@wickman
Copy link
Contributor Author

wickman commented Jul 24, 2015

is git-branches.py defined in a scripts=[] array in one of the project setup.py files?

@jdevera
Copy link

jdevera commented Jul 25, 2015

No, there is no setup.py, just git-branches.py and requirements.txt, I assummed that

If you build a simple flask app but don't want to go through the ceremony of defining a setup.py and the like

meant this case.

@jdevera
Copy link

jdevera commented Jul 25, 2015

I realise that I can create a minimal setup.py like this:

from setuptools import setup
setup(name='git-branches', scripts=['git-branches.py'])

Then run:

pex . -r requirements.txt --script git-branches.py -o git-branches

And get a runnable version of my script.

I thought this is what this issue was about. If not, is this something that could be somehow integrated? Shall I then open a new request?

@jsirois
Copy link
Member

jsirois commented Jul 25, 2015

I think opening a new issue for the more general enhancement of doing something sane when the requirement is a directory without a setup.py (whether or not --script is used), would make sense... iff you can supply some reasoning in the issue as to why / how a sane thing can be done. Is recursively globbing *.py from that dir good enough?, are non *.py files handled as resources (package_data) or are you out of luck and must upgrade to writing a setup.py at that point, etc.

This general thing was asked about here: http://stackoverflow.com/questions/30654854/python-pex-loading/30678446

@jsirois jsirois modified the milestones: 1.1, 1.0 Jul 25, 2015
@alex-leonhardt
Copy link

In case it helps anyone, I've used the latest pex 1.1.10 w/ python27 and had to create a valid setup.py with following content (which I now create dynamically as/when I build a new pex for my script/s)

from setuptools import setup
import os
del os.link # this is necessary if you run this inside a docker container as hard linking will not work
_version = os.getenv('BUILD_COUNTER', '1')
setup(
    name='script',
    scripts=['script.py'],
    author='you',
    author_email='you@domain.com',
    url='http://github.com',
    version=_version
    )

it also needs a README file in the same directory..

The directory then looks like

build/setup.py
build/script.py
build/requirements.txt
build/README

I then use

cd build
pex --disable-cache --python-shebang='/usr/bin/python27' . -r requirements.txt -c script.py -o ../script.pex

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants