How to install distutils packages using distutils api or setuptools api

I am working on a buildout script that needs to install the distutils package on a remote server.

PyPi has 2 recipes for this collect.recipe.distutils 0.1 and zerokspot.recipe.distutils 0.1.1 .

The later module is a derivative of the first, and is slightly more convenient than the first, but both suffer from the same problem, which I will discuss now.

When bootstrap.py is loaded, it downloads the zc.buildout package and places it in the buildout eggs directory. This gives. / bin / buildout accesses the zc.buildout code, but / usr / local / python doesn't know anything about zc.buildout at the moment.

Buildout attepts to install a package by running "python setup.py install" inside a subprocess. This raises an ImportError because zc.buildout is not installed for / usr / local / python.

So, I have several solutions.

  • Install zc.buildout with easy_install on a remote server. I don't like this option at all, it makes a special case for the module, which is very minor.

  • Modify zerokspot.recipe.distutils to put a try around "import zc.buildout" so it will be installed even if zc.buildout is not installed. This is a good solution, but a bit hackish.

  • Replace the subprocess with code that will install the package using distutils api or setuptools api. This would be the best solution in my opinion.

The question is, how would I do # 3?

Thanks, Taras

PS: I solved the problem by creating another package that has no dependency on zc.buildout. My package is called taras.recipe.distutils and it's available on pypi.

+2


source to share


3 answers


You can invoke a command line program in your Python program using the subprocess module :

import subprocess
subprocess.call('python setup.py install')

      



However, how much control do you have over the environment in which this installation will run? If this is a package that you distribute, you are likely to have problems no matter what solution they suggest. How would you handle cases where root access is needed (e.g. install sudo python setup.py)?

You may want to consider Paver as it provides an API that is in some way an extension of setuptools.

+1


source


zerokspot.recipe.distutils is fundamentally broken by adding a dependency on zc.buildout in the setup.py file like this:

  • setup.py

    imports get_version

    fromzerokspot.recipe.distutils

  • Everything is zerokspot.recipe.distutils

    defined in it __init__.py

    , includingget_version

  • __init__.py

    in zerokspot.recipe.distutils

    importzc.buildout

Why the author determines get_version

is a mystery to me; best practice keeps a simple version string in setup.py

and allows setuptools to handle dev (via setup.cfg

) and distutils versions to extract version metadata.



In general, it is impractical to import the entire package into setup.py

, since the installation will require all package dependencies to be present during installation. Obviously, the author of the package has zc.buildout installed as a package on the site and hasn't noticed his oversight.

Your best bet is to split the package on github, remove the get_version dependency, and suggest the change to the original author while you are using your fork.

+1


source


Are you sure you don't want to generate bdist ?

0


source







All Articles