Non-generated script with SetupTools/Distribute in setup.py
I'm trying to get a non-generated script when I run setup.py install
for a Python Package that I am building.
I have read the distutils documentation but couldn't find clear examples on how to accomplish this.
Mercurial does this in some part by importing the install_scripts
:
from distutils.command.install_scripts import install_scripts
And then goes on to replace some things within their hg
script. This hg
executable ends up being used overriding the default behavior of using something like this:
#!/Users/alfredo/python/foo/bin/python
# EASY-INSTALL-SCRIPT: 'foo==0.0.1','foo'
__requires__ = 'foo==0.0.1'
import pkg_resources
pkg_resources.run_script('foo==0.0.1', 'foo')
I am trying not to end up using pkg_resources importing my foo
package, but rather
end up with a script I am using. I'm aware why this is auto-generated and still want to
go the other route.
This is a copy of the base setup.py that I am using:
import distribute_setup
distribute_setup.use_setuptools()
from setuptools import setup
tests_require = ['pytest']
setup(
name = "foo",
version = "0.0.1",
packages = ['_foo'],
scripts = ['foo'],
zip_safe = False,
package_data = {'': ['distribute_setup.py']},
author = "Alfredo Deza",
author_email = "alfredodeza [at] gmail [dot] com",
d开发者_StackOverflowescription = "",
long_description = """\
Foo
""",
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development :: Build Tools',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
],
license = "MIT",
keywords = "",
url = "",
)
After days of digging around... it turns out that Mercurial is not doing anything special.
Even though their setup.py
does a lot of things it actually does not do anything to interfere with installing a script correctly without pkg_resources linking to it.
What is the difference then?
The difference is that I am using Distribute, and the way it works it overrides the setup
module with its own (instead of setuptools) and thus it has its own different behavior for installation.
In my case, that different way of installing scripts, means that a script foo
will get copied over to the egg location and linked through a foo
script that imports pkg_resources and links to that version.
This is not what I want and I couldn't find any Distribute documentation on it. However, it is clear they do so to provide a way of uninstallation later on.
So beware! If you do want to go my path, you will have issues if you want to uninstall stuff.
Until Distribute doesn't provide a way for me to customize what to copy in my scripts I will have to switch back to regular setuptools
IIRC, using the --single-version-externally-managed
argument when installing should do as you like.
精彩评论