[PEAK] setuptools dependencies installed from os packages

Phillip J. Eby pje at telecommunity.com
Mon Dec 19 13:11:05 EST 2005


At 07:11 PM 12/19/2005 +0200, alexander smishlajev wrote:
>hello!
>
>it would be very nice if setuptools could find required modules installed 
>with os package management system (binary packages on windows, redhat and 
>debian, ports on *bsd, ebuilds on gentoo...)
>
>perhaps there could be a standard way for setuptools-aware package to 
>declare it's installed version?
>
>the long story: i am trying to run SQLObject tests.  SQLObject test system 
>verifies dependency requirements.  one of the requirements is 
>"FormEncode>=0.2.2".  i have FormEncode-0.4 installed from windows 
>installer.  but SQLObject tests fail with error 
>"pkg_resources.DistributionNotFound: FormEncode>=0.2.2".
>
>now i have two options: remove installed FormEncode and reinstall it from 
>egg, or hack SQLObject.egg-info and remove requirement for FormEncode.  i 
>don't like the first option because setuptools don't provide a way (other 
>than manual file removal) to uninstall obsolete packages, and i don't like 
>the second option because it smells very bad.
>
>... any thoughts?

The current version of setuptools in SVN allows you to make a bdist_wininst 
of an egg.

So, if you use these commands:

     easy_install -eb. FormEncode
     cd formencode
     setup.py bdist_wininst

you will have a FormEncode .exe that can uninstall itself, but which is 
nonetheless a valid egg.  The .exe will not use a .pth, and the files will 
be installed unzipped in a "traditional" package layout, but there will 
also be an .egg-info directory installed to site-packages that will tell 
other packages that it is installed.

If you need to do this with a package that does not use setuptools, you can 
do this:

     easy_install -eb. SomePackage
     cd somepackage
     python -c "import setuptools; execfile('setup.py')" bdist_wininst

which will force the use of setuptools to build a bdist_wininst egg.

The "bdist_rpm" command is also supported for this, and the third-party 
"bdist_nsi" (NSIS installer) and "bdist_msi" (Microsoft installer) commands 
should probably work also.

If you want to create packages for some other system, you can use "install 
--single-version-externally-managed" along with --root and/or --record to 
prebuild an installation for packaging.  If you are using something like 
bdist_deb that uses "setup.py install" you will need to modify the tool to 
include the --single-version-externally-managed option.  And if the package 
does not use setuptools, you will need the "python -c" hack shown above in 
order to force the setup script to use setuptools.

To sum up: you can build system packages for eggs now, and you can build 
system packages wrapping eggs even for packages that do not currently use 
setuptools.  But there is not a way to detect the presence and version of 
arbitrary system packages on arbitary platforms.

If you wish to flag the presence of such packages, however, you can now add 
.egg-info files to the directory on sys.path where they are installed.  The 
.egg-info file should be named with the project name and version (e.g. 
FormEncode-0.4.egg-info) and its contents should be the distutils PKG-INFO 
file found in the project's source distribution.  The above-described 
packaging techniques do this automatically, although they use an .egg-info 
directory instead.

To use any of these features, you must have the latest setuptools, i.e. one 
less than 48 hours old or so (these features were added late last 
week).  To upgrade, run:

     ez_setup.py setuptools==dev

or if you prefer to wrap setuptools itself in a bdist_wininst wrapper, do:

     ez_setup.py -eb. setuptools==dev
     cd setuptools
     setup.py bdist_wininst

and then install the resulting .exe.




More information about the PEAK mailing list