Search code examples
pythonubuntusetuptoolsdistutilssetup.py

Distutils ignores build/lib on Ubuntu


I have a setup.py script which builds files to be installed to the ./build/lib directory. The files are populated by the run() method of my custom distutils.command.build.build subclass:

from distutils.command.build import build
from distutils.core import setup

class MyBuild(build):
    def run(self):
        # Populate files to ./build/lib

setup(
    # ...
    cmdclass=dict(build=MyBuild)
)

Now, according to this article the setup script should copy everything in the ./build/lib directory to the installation directory, which works as expected on OSX but not on Ubuntu 14.04 where it ignores the ./build/lib directory but rather installs files found in ./build/lib.<plat>, which in turn doesn't work on OSX where the ./build/lib.<plat> directory is ignored.

Is there a consistent, platform independent way to build and install files with distutils? The files are platform-independent.


Solution

  • In the MyBuild.run() method, populate files to the path given in self.build_lib instead of a hardcoded path.

    from distutils.command.build import build
    from distutils.core import setup
    
    class MyBuild(build):
        def run(self):
            build_path = self.build_lib
            # Populate files to 'build_path'
    
    setup(
        # ...
        cmdclass=dict(build=MyBuild)
    )
    

    Do not change the value of self.build_lib in MyBuild.run() as it is generated from command line arguments and/or various default values. The same goes for several other attributes such as build_scripts, build_base, build_purelib, etc.