English 中文(简体)
Can a Python package depend on a specific version control revision of another Python package?
原标题:

Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in setup.py e.g

requires = svn://example.org/useful.package/trunk@1234 ?

最佳回答

You need to do two things. First, require the exact version you want, e.g.:

install_requires = "useful.package==1.9dev-r1234"

and then include a dependency_links setting specifying where to find it:

dependency_links = ["svn://example.org/useful.package/trunk@1234#egg=useful.package-1.9dev-r1234"]

Note that the version #egg= part of the dependency_links URL must exactly match what you specified in install_requires; this is what links the two pieces together.

What happens is that setuptools sees the #egg tag on the link and saves the URL as an available download URL for that precise version of the package. Then, when it tries to resolve that requirement later, it should download that precise SVN URL.

(Note, however, that for this to really work, the targeted SVN revision has to actually build an egg with that name and version. Otherwise, your dependency will fail at runtime! So, this really only works if the package you re depending on uses SVN revision tags in their default build version numbers.)

问题回答

If you really require an obscure version of another package, and there s no way to make do with other versions, you might want to simply distribute that version of the package with your own. If necessary put it in your own namespace to ensure that your version is the one that is used.

I haven t figured out how to reference this from setup.py but pip can check out specific revisions of Python packages with a simple requirements file. With a requirements file called requires.txt, pip install -r requires.txt will install all the packages listed in that file (and their dependencies).

Here is part of my requirements file. The lines starting with -e check out specific revisions of packages from version control (git, svn, or mercurial), including my project, and install them in an editable form. pip freeze lists all installed packages in this format.

requires.txt:

-e hg+file:///home/me/my-private-project#egg=myproject
-e hg+http://bitbucket.org/ianb/webob@tip#egg=WebOb
-e svn+http://svn.sqlalchemy.org/sqlalchemy/trunk@6638#egg=SQLAlchemy
-e svn+http://svn.zope.org/repos/main/z3c.saconfig/trunk@106508#egg=z3c.saconfig
## The following requirements were added by pip --freeze:
APScheduler==1.01
simplejson==2.0.9
... (many more)

You can release packages of specific versions, but you have to distribute them together. There is no way to automatically download them with standard Python.

However, you can use Buildout and create a buildout.cfg that makes it possible to replicate the environment. It can check out and install specific revisions if you use extensions like mr.developer.

http://pypi.python.org/pypi/zc.buildout http://pypi.python.org/pypi/mr.developer





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签