Install local extras in Python
setup.py of my package X uses setuptools to optionally install an extra package Y, via the extras_require
parameter.
Now package Y disappeared 开发者_JAVA百科from PyPi and, as far as I can tell, from the visible Internet. easy_install X[Y]
fails with error: Could not find suitable distribution for Y
.
However, I still have a local copy of Y's tarball. Y is a pure-Python package.
What is the best way to modify setup.py to allow this (local?) optional extra?
EDIT: The fix is meant to be temporary, until I figure out a proper replacement. I do not want to start officially maintaining Y myself :)
You could subclass setuptools.Command
and then overload the default install
command. Then you could have THAT execute a subprocess that installs the dependency. It's a hack, but that's what you were asking for!
In setup.py:
from setuptools import Command
class MyInstallCommand(Command):
# Overload the 'install' command to do default install but also install
# your provided tarball. Blah blah blah read the docs on what to do here.
setup(
name='mypackage',
# etc ... and then...
# Overload the 'install' command
cmdclass={
'install': MyInstallCommand,
}
)
I'm grossly oversimplifying it, but this is the basic gist.
I found a quick workaround via the dependency_links
option of setuptools.
- Upload Y's tarball to some url
http://URL_Y
. - Add the line:
dependency_links = ['http://URL_Y'],
to my setup.py.
Now easy_install X[Y]
works and I didn't have to register Y anywhere. I will delete it from URL_Y as soon as I have a proper fix.
精彩评论