python setuptools install_requires is ignored when overriding cmdclass

The same problem just happened to me. It somehow seems like something triggers setuptools to do an ‘old-style install’ with distutils, which indeed does not support install_requires. You call install.run(self) which calls run(self) in setuptools/setuptools/command/install.py, line 51-74 https://bitbucket.org/pypa/setuptools/src/8e8c50925f18eafb7e66fe020aa91a85b9a4b122/setuptools/command/install.py?at=default def run(self): # Explicit request for old-style install? Just do it if self.old_and_unmanageable or self.single_version_externally_managed: return _install.run(self) … Read more

How to extend distutils with a simple post install script?

I dug through distutils source for a day to learn enough about it to make a bunch of custom commands. It’s not pretty, but it does work. import distutils.core from distutils.command.install import install … class my_install(install): def run(self): install.run(self) # Custom stuff here # distutils.command.install actually has some nice helper methods # and interfaces. I … Read more

How to build a Python C Extension so I can import it from a module

Just change Extension(‘c_extension’, …) to Extension(‘foo.bar.c_extension’, …) You will need __init__.py files in each of the foo and bar directories, as usual. To have these packaged with the module in your setup.py, you need to add packages = [‘foo’, ‘foo.bar’], to your setup() call, and you will need the directory structure setup.py foo/ __init__.py bar/ … Read more

Custom distutils commands

This can easily be done with distutils by subclassing distutils.core.Command inside of setup.py. For example: from distutils.core import setup, Command import os, sys class CleanCommand(Command): description = “custom clean command that forcefully removes dist/build directories” user_options = [] def initialize_options(self): self.cwd = None def finalize_options(self): self.cwd = os.getcwd() def run(self): assert os.getcwd() == self.cwd, ‘Must … Read more

Python distutils, how to get a compiler that is going to be used?

This is an expanded version of Luper Rouch’s answer that worked for me to get an openmp extension to compile using both mingw and msvc on windows. After subclassing build_ext you need to pass it to setup.py in the cmdclass arg. By subclassing build_extensions instead of finalize_options you’ll have the actual compiler object to look … Read more

Is it possible to express a platform-specific dependency in setup.py without building platform-specific versions of my egg?

For sdist, egg and wheel release from : https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#platform-specific-dependencies Sometimes a project might require a dependency to run on a specific platform. This could to a package that back ports a module so that it can be used in older python versions. Or it could be a package that is required to run on a … Read more

Managing resources in a Python project

You may want to use pkg_resources library that comes with setuptools. For example, I’ve made up a quick little package “proj” to illustrate the resource organization scheme I’d use: proj/setup.py proj/proj/__init__.py proj/proj/code.py proj/proj/resources/__init__.py proj/proj/resources/images/__init__.py proj/proj/resources/images/pic1.png proj/proj/resources/images/pic2.png Notice how I keep all resources in a separate subpackage. “code.py” shows how pkg_resources is used to refer to … Read more