Using an egg like a Java jar file

In Java, it is possible to create a .jar file with a main() method embedded somewhere in one of the .class files. It is then possible to run the main() method from the command line something like this: java -jar foo.jar I believe this will work with only one main() defined - if there are multiple ones, then you have to specify the path (internal to the jar file). I gather from previous googling that there isn't a python command line option equivalent to -jar for eggs (although that might be kind of handy) but that you can add an egg to your path without installing it by doing something like the following (in a bash shell): export PYTHONPATH=foo.egg This will then allow you to run a python script at the command line without having to actually install the egg to the normal "site- packages" directory. My questions: - Is it possible to embed a script with a "main" entry point in an egg, and run that from the command line? - If so, how do you pass command line arguments to that main? - Is this a massive abuse of the intended usage of setuptools? Thanks, Mike

2009/7/27 mhearne808 <mhearne808@gmail.com>:
My questions: - Is it possible to embed a script with a "main" entry point in an egg, and run that from the command line? - If so, how do you pass command line arguments to that main? - Is this a massive abuse of the intended usage of setuptools?
In Python 2.6, you can definitely use a zip file like this. See http://docs.python.org/using/cmdline.html#command-line python foo.zip arg1 arg2 ... foo.zip should contain a __main__.py which is run. sys.argv holds the arguments as usual. This is not an abuse, it's a standard feature. Whether this is possible with eggs is another matter. I don't know the answer to this, beyond saying that eggs are zip format files, so you can always do it as above, at a pinch (assuming you can force setuptools to generate the correct layout). Paul.

On Mon, Jul 27, 2009 at 10:57:28PM +0100, Paul Moore wrote:
2009/7/27 mhearne808 <mhearne808@gmail.com>:
My questions: - Is it possible to embed a script with a "main" entry point in an egg, and run that from the command line? - If so, how do you pass command line arguments to that main? - Is this a massive abuse of the intended usage of setuptools?
In Python 2.6, you can definitely use a zip file like this. See http://docs.python.org/using/cmdline.html#command-line
python foo.zip arg1 arg2 ...
foo.zip should contain a __main__.py which is run. sys.argv holds the arguments as usual.
On UNIX systems you can even do something like IIRC: $ echo '#!/usr/bin/python' > tmp $ cat tmp foo.zip > foo $ chmod +x foo $ ./foo arg1 arg2 ... Regards Floris -- Debian GNU/Linux -- The Power of Freedom www.debian.org | www.gnu.org | www.kernel.org

All: This may be a duplicate post - I can't see the post I just submitted, so I'm trying again. Thanks for the suggestions. I can't use 2.6 because it isn't installed on the systems where my script will be running. I'm attempting to use the 'eggsecutable' suggestion. How do I get command line parameters passed into my entry point main() function? Code is appended below. setup.py: from setuptools import setup, find_packages setup(name='testme', version='1.0.0', py_modules=['testme'], description = 'foo', author = 'Somebody', author_email = 'somebody@foo.com', url = 'www.foo.com', entry_points = { 'setuptools.installation': ['eggsecutable = testme:main',]} ) testme.py: #!/usr/bin/env python import sys def main(input): print 'Command line arguments are ' % input if __name__ == '__main__': main(sys.argv) On Jul 28, 1:53 am, Floris Bruynooghe <floris.bruynoo...@gmail.com> wrote:
On Mon, Jul 27, 2009 at 10:57:28PM +0100, Paul Moore wrote:
2009/7/27 mhearne808 <mhearne...@gmail.com>:
My questions: - Is it possible to embed a script with a "main" entry point in an egg, and run that from the command line? - If so, how do you pass command line arguments to that main? - Is this a massive abuse of the intended usage of setuptools?
In Python 2.6, you can definitely use a zip file like this. See http://docs.python.org/using/cmdline.html#command-line
python foo.zip arg1 arg2 ...
foo.zip should contain a __main__.py which is run. sys.argv holds the arguments as usual.
On UNIX systems you can even do something like IIRC:
$ echo '#!/usr/bin/python' > tmp $ cat tmp foo.zip > foo $ chmod +x foo $ ./foo arg1 arg2 ...
Regards Floris
-- Debian GNU/Linux -- The Power of Freedomwww.debian.org|www.gnu.org|www.kernel.org _______________________________________________ Distutils-SIG maillist - Distutils-...@python.orghttp://mail.python.org/mailman/listinfo/distutils-sig
participants (3)
-
Floris Bruynooghe
-
mhearne808
-
Paul Moore