requires keyword allows a package to declare a dependency. I can't for the life of me make this do anything useful. What I expect to happen is when I use easy_install to download a package with another requirement, that required package should also be downloaded.Here's what I have:
from distutils.core import setup
import os
setup (
name = 'BlogBackup',
version = '1.2',
description = 'Script to dump a blog feed to files suitable for backing up or reprocessing.',
long_description = """
This script uses the feedparser module to access an Atom or RSS feed and
download the individual entries to a backup directory. It tracks both
etag and modified headers for each feed to reduce processing overhead.
""",
author = 'Doug Hellmann',
author_email = 'doug.hellmann@example.com',
url = 'http://www.doughellmann.com/projects/BlogBackup/',
download_url = 'http://www.doughellmann.com/downloads/BlogBackup-1.2.tar.gz',
classifiers = [ 'Development Status :: 4 - Beta',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Intended Audience :: End Users/Desktop',
'Environment :: Console',
'Topic :: System :: Archiving :: Backup',
'Topic :: Utilities',
],
platforms = ('Any',),
keywords = ('backup', 'archive', 'atom', 'rss', 'blog', 'weblog'),
packages = [ 'blogbackuplib',
],
package_dir = { '': '.' },
scripts = ['blogbackup'],
requires=['CommandLineApp (>=2.5)'],
)
I set up a new virtual environment without any site-packages. I have verified that if I run the virtual environment interpreter, I cannot import
CommandLineApp (so it is not already installed). When I run easy_install BlogBackup, it downloads and installs the correct version (1.2). Here's the output:$ easy_install BlogBackup
Searching for BlogBackup
Reading http://pypi.python.org/simple/BlogBackup/
Reading http://www.doughellmann.com/projects/BlogBackup/
Best match: BlogBackup 1.2
Downloading http://www.doughellmann.com/downloads/BlogBackup-1.2.tar.gz
Processing BlogBackup-1.2.tar.gz
Running BlogBackup-1.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-p9F4P3/BlogBackup-1.2/egg-dist-tmp-VRoy9D
zip_safe flag not set; analyzing archive contents...
Adding BlogBackup 1.2 to easy-install.pth file
Installing blogbackup script to /Users/dhellmann/Devel/personal/Projects/BlogBackup/Test/bin
Installed /Users/dhellmann/Devel/personal/Projects/BlogBackup/Test/lib/python2.5/site-packages/BlogBackup-1.2-py2.5.egg
Processing dependencies for BlogBackup
Finished processing dependencies for BlogBackup
It says "Processing dependencies", but does not download the CommandLineApp package.
Have I specified the requirements value incorrectly? Or am I expecting too much?
12 comments:
Try to use setuptools?
from setuptools import setup
instead of from distutils import setup
Switching to setuptools didn't resolve the problem. I have slightly different output, but it still does not download dependencies.
I'm still not 100% sure I understand the features implemented for the requires value, though. It's possible I'm asking for more than is available.
Try with:
requires=['CommandLineApp >=2.5'],
(without parenthesis)
The parens are definitely required. I get a ValueError when I try to build the package if I take them out.
Hi Doug,
Use setuptools.setup and instead of 'requires', use the key 'install_requires;.
For reasons only known to itself, setuptools doesn't use the distutils keyword for requires.
Ok, switching to setuptools and using the keyword install_requires seems to have done the trick.
Thanks to all of you for helping out!
The question remains, though: Is this something that should have worked with distutils, or did I misunderstand the purpose of the requires keyword?
The distutils "requires" keyword has no semantics attached. The setuptools folk took it upon themselves to ignore it and create their own "requires" keyword. Effectively the distutils "requires" keyword is useless.
Thanks for the info, Richard. That's pretty disappointing. Do you know if there are plans to enhance distutils to make requries meaningful?
"""The setuptools folk took it upon themselves to ignore it and create their own "requires" keyword."""
That's because the "requires" keyword has too restrictive of a syntax. It doesn't even support Python's own version numbering scheme, let alone the vast varieties of versioning schemes used by released packages. See the PEPs for details, as well as my previous mailing list commentary on the problems with said PEPs.
distutils requires could be made more useful, but I believe the horse bolted when setuptools version 1 was released.
Perhaps "requires" should be removed from the distutils documentation.
(Blogger keeps breaking when I try to add this comment logged in)
@pje & richard: Thanks for filling in the missing pieces.
So, it sounds like distutils requires doesn't serve any purpose other than documenting the requirements. I'll switch my package to use setuptools to get the benefits of automatic dependency resolution. I don't really like doing that, because it introduces an artificial dependency on setuptools, but I guess that's the price I pay. :-)
Post a Comment