setup: require specific versions of dependencies, both at run-time (if pkg_resources is available) and at build-time, and make there be only once place where we specify those versions

Using pkg_resources.require() like this also apparently allows people to install multiple different versions of packages on their system and tahoe (if pkg_resources is available to it) will import the version of the package that it requires.  I haven't tested this feature.
This commit is contained in:
Zooko O'Whielacronx 2008-01-22 17:24:33 -07:00
parent 8fc26ea4c4
commit 348eecd615
4 changed files with 46 additions and 18 deletions

View File

@ -160,9 +160,11 @@ signal-error-pyopenssl-dep:
@echo @echo
exit 1 exit 1
check-all-deps: check-deps check-auto-deps:
$(PP) \ $(PP) \
$(PYTHON) -c 'import allmydata, zfec, foolscap, simplejson, nevow, pycryptopp' || $(MAKE) signal-error-deps $(PYTHON) -c 'import _auto_deps ; _auto_deps.require_auto_deps()' || $(MAKE) signal-error-deps
check-all-deps: check-deps check-auto-deps
check-twisted-dep: check-twisted-dep:
$(PYTHON) -c 'import twisted, zope.interface' || $(MAKE) signal-error-twisted-dep $(PYTHON) -c 'import twisted, zope.interface' || $(MAKE) signal-error-twisted-dep

24
_auto_deps.py Normal file
View File

@ -0,0 +1,24 @@
install_requires=["zfec >= 1.3.0",
"foolscap >= 0.2.3",
"simplejson >= 1.7.3",
"pycryptopp >= 0.2.9",
"nevow >= 0.6.0",
"zope.interface >= 3.1.0",
]
def require_auto_deps():
try:
import pkg_resources
except:
# Then we can't assert that the versions of these packages are the right
# versions, but we can still try to use them anyway...
pass
else:
for requirement in install_requires:
pkg_resources.require(requirement)
for requirement in install_requires:
name, cmpop, verstr = requirement.split()
__import__(name)
if __name__ == "__main__":
require_auto_deps()

View File

@ -23,6 +23,16 @@ else:
from setuptools import Extension, find_packages, setup from setuptools import Extension, find_packages, setup
# Make the dependency-version-requirement, which is used by the Makefile at
# build-time, also available to the app at runtime:
import shutil
try:
shutil.copyfile("_auto_deps.py", os.path.join("src", "allmydata", "_auto_deps.py"))
except EnvironmentError:
# Nevermind then -- perhaps it is already in place and in any case we can do
# without it.
pass
trove_classifiers=[ trove_classifiers=[
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",
"Environment :: Console", "Environment :: Console",
@ -103,13 +113,7 @@ setup_requires.append('darcsver >= 1.0.0')
if not os.path.exists('PKG-INFO'): if not os.path.exists('PKG-INFO'):
setup_requires.append('setuptools_darcs >= 1.1.0') setup_requires.append('setuptools_darcs >= 1.1.0')
install_requires=["zfec >= 1.3.0", import _auto_deps
"foolscap >= 0.2.3",
"simplejson >= 1.7.3",
"pycryptopp >= 0.2.9",
"nevow >= 0.6.0",
"zope.interface >= 3.1.0",
]
setup(name='allmydata-tahoe', setup(name='allmydata-tahoe',
version=verstr, version=verstr,
@ -123,7 +127,7 @@ setup(name='allmydata-tahoe',
packages=find_packages("src"), packages=find_packages("src"),
classifiers=trove_classifiers, classifiers=trove_classifiers,
test_suite="allmydata.test", test_suite="allmydata.test",
install_requires=install_requires, install_requires=_auto_deps.install_requires,
include_package_data=True, include_package_data=True,
setup_requires=setup_requires, setup_requires=setup_requires,
dependency_links=dependency_links, dependency_links=dependency_links,

View File

@ -20,17 +20,15 @@ hush_pyflakes = __version__
del hush_pyflakes del hush_pyflakes
try: try:
import pkg_resources import _auto_deps
except ImportError: except ImportError:
# nevermind # Never mind -- even if we can't use pkg_resources to check the required
# version numbers and to select the right one in the case that more than one
# version is available, we can still barrel on and if "import thingie" gives
# us a thingie that works, we're okay.
pass pass
else: else:
pkg_resources.require("zfec >= 1.3.0") _auto_deps.require_auto_deps()
pkg_resources.require("foolscap >= 0.2.3")
pkg_resources.require("simplejson >= 1.7.3")
pkg_resources.require("pycryptopp >= 0.2.9")
pkg_resources.require("nevow >= 0.6.0")
pkg_resources.require("zope.interface >= 3.1.0")
def get_package_versions(): def get_package_versions():
import OpenSSL, allmydata, foolscap, nevow, pycryptopp, simplejson, twisted, zfec import OpenSSL, allmydata, foolscap, nevow, pycryptopp, simplejson, twisted, zfec