scripts versus console_scripts
First things first: what I want to accomplish is to install pyflakes and docutils in a buildout. That is, I want to have a bin/pyflakes and bin/rst2* scripts. - Buildout listens to the console_scripts entry point. - pyflakes and docutils use the (apparently old) scripts=['scripts/pyflakes'] option instead of a console_scripts entry point. So I have three choices: - Ask pyflakes and docutils to use the console_scripts entry point. Is there a reason not to use console_scripts? The "scripts=[]" comes from plain distutils which is in the official python distribution and setuptools is an add-on. Can this be a cause? - Fix up buildout to also support scripts=[]. (I'm trying that one right now). - Write a wrapper library that depends on pyflakes/docutils and provides proper entry points. Feels a bit dirty. I have two questions: - Has the console_scripts entry point superseded scripts=[]? Should it be considered a bug in pyflakes? Or is it OK to still use it? - How do I access that 'scripts=[....]' which is sitting right there in my setup() call? From buildout? Buildout does something like: req = pkg_resources.Requirement.parse('my.package') dist = working_set.find('my.package') dist ends up as a pkg_resources.Distribution class, which doesn't seem to have anything with which to do "dist.scripts" or so. Anyone know the magic call? In easy_install there's a "self.distribution.scripts", but after 4 levels of inheritance and a monkey patch I lost track where self.distribution comes from... Reinout -- Reinout van Rees - reinout@vanrees.org - http://reinout.vanrees.org Software developer at http://www.thehealthagency.com "Military engineers build missiles. Civil engineers build targets"
On Wed, Sep 2, 2009 at 3:07 PM, Reinout van Rees
First things first: what I want to accomplish is to install pyflakes and docutils in a buildout. That is, I want to have a bin/pyflakes and bin/rst2* scripts.
- Buildout listens to the console_scripts entry point.
- pyflakes and docutils use the (apparently old) scripts=['scripts/pyflakes'] option instead of a console_scripts entry point.
So I have three choices:
- Ask pyflakes and docutils to use the console_scripts entry point. Is there a reason not to use console_scripts? The "scripts=[]" comes from plain distutils which is in the official python distribution and setuptools is an add-on. Can this be a cause?
- Fix up buildout to also support scripts=[]. (I'm trying that one right now).
- Write a wrapper library that depends on pyflakes/docutils and provides proper entry points. Feels a bit dirty.
if the code called in scripts/pyflakes is using a function from the pyflakes package, you could also add in a zc.recipe.eggs section in your buildout an explicit entry_point like this: [scripts] recipe= zc.recipe.eggs eggs = pyflakes entry-points = pyflakes=pyflakes.somemodule:main where main is the function to launch is the somemodule module in pyflakes for instance Cheers Tarek -- Tarek Ziadé | http://ziade.org
On 2009-09-02, Reinout van Rees
- pyflakes and docutils use the (apparently old) scripts=['scripts/pyflakes'] option instead of a console_scripts entry point.
Just for easy reference: here's the setup.py of pyflakes: #!/usr/bin/python # (c) 2005-2009 Divmod, Inc. See LICENSE file for details from distutils.core import setup setup( name="pyflakes", license="MIT", version="0.3.0", description="passive checker of Python programs", author="Phil Frost", maintainer="Moe Aboulkheir", maintainer_email="moe@divmod.com", url="http://www.divmod.org/trac/wiki/DivmodPyflakes", packages=["pyflakes", "pyflakes.scripts", "pyflakes.test"], scripts=["bin/pyflakes"], long_description="""Pyflakes is program to analyze Python programs and detect various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It's also much faster.""") Reinout -- Reinout van Rees - reinout@vanrees.org - http://reinout.vanrees.org Software developer at http://www.thehealthagency.com "Military engineers build missiles. Civil engineers build targets"
On Wed, Sep 2, 2009 at 9:07 AM, Reinout van Rees
First things first: what I want to accomplish is to install pyflakes and docutils in a buildout. That is, I want to have a bin/pyflakes and bin/rst2* scripts.
- Buildout listens to the console_scripts entry point.
- pyflakes and docutils use the (apparently old) scripts=['scripts/pyflakes'] option instead of a console_scripts entry point.
So I have three choices:
- Ask pyflakes and docutils to use the console_scripts entry point. Is there a reason not to use console_scripts? The "scripts=[]" comes from plain distutils which is in the official python distribution and setuptools is an add-on. Can this be a cause?
Perhaps. Note that, as Tarek reminded us, buildout lets you define entry points yourself. In fact, I happen to have done this for pyflakes myself a couple of weeks ago: [pyflakes] recipe = zc.recipe.egg eggs = pyflakes entry-points = pyflakes=pyflakes.scripts.pyflakes:main
- Fix up buildout to also support scripts=[]. (I'm trying that one right now).
For a long time, I maintained that this wasn't practical. I do think 90% (maybe a 100%) solution of possible. It will require generating scripts that set up the path and then include the source of the original scripts. This is rather ugly but probably doable. Of course, there's also the pain that the script meta data isn't available cleanly, as you point out below.
- Write a wrapper library that depends on pyflakes/docutils and provides proper entry points. Feels a bit dirty.
I have two questions:
- Has the console_scripts entry point superseded scripts=[]? Should it be considered a bug in pyflakes? Or is it OK to still use it?
I personally think entry points are cleaner, but I think it would be rather bold to call use of scripts a bug. :)
- How do I access that 'scripts=[....]' which is sitting right there in my setup() call? From buildout? Buildout does something like:
req = pkg_resources.Requirement.parse('my.package') dist = working_set.find('my.package')
dist ends up as a pkg_resources.Distribution class, which doesn't seem to have anything with which to do "dist.scripts" or so. Anyone know the magic call? In easy_install there's a "self.distribution.scripts", but after 4 levels of inheritance and a monkey patch I lost track where self.distribution comes from...
Yeah, it's too bad that the meta data is lost. It amazes me how willing distutils and setuptools are to toss meta data passed to setup. You could probably invoke the install command telling it to install the scripts in some place and then grab them, but that sounds nasty too. Jim -- Jim Fulton
On 2009-09-02, Jim Fulton
Note that, as Tarek reminded us, buildout lets you define entry points yourself. In fact, I happen to have done this for pyflakes myself a couple of weeks ago:
[pyflakes] recipe = zc.recipe.egg eggs = pyflakes entry-points = pyflakes=pyflakes.scripts.pyflakes:main
That's much shorter than the one I've been using, which makes it seem less painful. Due to the way the docutils scripts are set up (without a clear 'main()' method), this is much more painful.
- Fix up buildout to also support scripts=[]. (I'm trying that one right now).
For a long time, I maintained that this wasn't practical. I do think 90% (maybe a 100%) solution of possible. It will require generating scripts that set up the path and then include the source of the original scripts. This is rather ugly but probably doable. Of course, there's also the pain that the script meta data isn't available cleanly, as you point out below.
I went from "probably an easy fix" to "ouch, distutils/setuptools makes this impossible without resorting to ugly hacks" within one day...
- How do I access that 'scripts=[....]' which is sitting right there in my setup() call? From buildout? Buildout does something like:
req = pkg_resources.Requirement.parse('my.package') dist = working_set.find('my.package')
dist ends up as a pkg_resources.Distribution class, which doesn't seem to have anything with which to do "dist.scripts" or so. Anyone know the magic call? In easy_install there's a "self.distribution.scripts", but after 4 levels of inheritance and a monkey patch I lost track where self.distribution comes from...
Yeah, it's too bad that the meta data is lost. It amazes me how willing distutils and setuptools are to toss meta data passed to setup.
You could probably invoke the install command telling it to install the scripts in some place and then grab them, but that sounds nasty too.
And it is especially nasty as you'd have to do it for every egg in order to discover whether they *have* a 'scripts=[...]'. Unless you'd specify it. What about making the problem explicit and doing something like: [distutilscripts] recipe = zc.recipe.egg:distutils eggs = pyflakes docutils scripts = scripts/pyflakes tools/rst2html tools/rst2s5 Reinout -- Reinout van Rees - reinout@vanrees.org - http://reinout.vanrees.org Software developer at http://www.thehealthagency.com "Military engineers build missiles. Civil engineers build targets"
On Thu, Sep 3, 2009 at 11:46 AM, Reinout van Rees
On 2009-09-02, Jim Fulton
wrote: Note that, as Tarek reminded us, buildout lets you define entry points yourself. In fact, I happen to have done this for pyflakes myself a couple of weeks ago:
[pyflakes] recipe = zc.recipe.egg eggs = pyflakes entry-points = pyflakes=pyflakes.scripts.pyflakes:main
That's much shorter than the one I've been using, which makes it seem less painful. Due to the way the docutils scripts are set up (without a clear 'main()' method), this is much more painful.
Yeah, I ended up creating a wrapper package for docutuls. In fact, I should have mentioned it sooner: http://pypi.python.org/pypi/zc.rst2 You might find it useful. :) ...
What about making the problem explicit and doing something like:
[distutilscripts] recipe = zc.recipe.egg:distutils eggs = pyflakes docutils scripts = scripts/pyflakes tools/rst2html tools/rst2s5
Something like that might work. Note that there is already a scripts option. Maybe: distutils-scripts = x y=z Jim -- Jim Fulton
On Wed, Sep 2, 2009 at 7:50 PM, Jim Fulton
Yeah, it's too bad that the meta data is lost. It amazes me how willing distutils and setuptools are to toss meta data passed to setup.
Are your referring to the Package Metadata ? (eg the PEP 314 that lands in the PKG-INFO) 'scripts' is just an argument that is used by the commands to generate the scripts, I don't think they should land in the Package Metadata, but I think we should have an API for any installed distribution to list them. Right now PEP 376 proposes a RECORD file that lists all files installed for a distribution, but maybe we could have a flag that indicates that a file is an executable script How does that sounds ? Tarek
On Thu, Sep 3, 2009 at 12:34 PM, Tarek Ziadé
On Wed, Sep 2, 2009 at 7:50 PM, Jim Fulton
wrote: Yeah, it's too bad that the meta data is lost. It amazes me how willing distutils and setuptools are to toss meta data passed to setup.
Are your referring to the Package Metadata ? (eg the PEP 314 that lands in the PKG-INFO)
Not necessarily. I mainly want it to land somewhere in the egg info.
'scripts' is just an argument that is used by the commands to generate the scripts,
I don't think they should land in the Package Metadata, but I think we should have an API for any installed distribution to list them.
I consider everything that ends up in egg info directories to be package meta data. The information needs to be saved somewhere for an API to dig it out of an egg.
Right now PEP 376 proposes a RECORD file that lists all files installed for a distribution, but maybe we could have a flag that indicates that a file is an executable script
How does that sounds ?
I think the script information should be included somehow so that it can be gotten from eggs. Jim -- Jim Fulton
On Wednesday,2009-09-02, at 7:07 , Reinout van Rees wrote:
First things first: what I want to accomplish is to install pyflakes and docutils in a buildout. That is, I want to have a bin/ pyflakes and bin/rst2* scripts.
See also http://pypi.python.org/pypi/setuptools_pyflakes Which adds a setuptools command to run pyflakes. Regards, Zooko
On 2009-09-05, Zooko Wilcox-O'Hearn
On Wednesday,2009-09-02, at 7:07 , Reinout van Rees wrote:
First things first: what I want to accomplish is to install pyflakes and docutils in a buildout. That is, I want to have a bin/ pyflakes and bin/rst2* scripts.
See also
http://pypi.python.org/pypi/setuptools_pyflakes
Which adds a setuptools command to run pyflakes.
I had not spotted that one. Anyway, when my branch is merged, buildout supports it out of the box :-) I think I've nailed down everything there is to nail down (apart from running tests on windows which I cannot). Reinout -- Reinout van Rees - reinout@vanrees.org - http://reinout.vanrees.org Software developer at http://www.thehealthagency.com "Military engineers build missiles. Civil engineers build targets"
participants (4)
-
Jim Fulton
-
Reinout van Rees
-
Tarek Ziadé
-
Zooko Wilcox-O'Hearn