How to pass --debug to build_ext when invoking setup.py install?

Viewed 4171
2 Answers

A. If I am not mistaken, one could achieve that by adding the following to a setup.cfg file alongside the setup.py file:

[build_ext]
debug = 1

B.1. For more flexibility, I believe it should be possible to be explicit on the command line:

$ path/to/pythonX.Y setup.py build_ext --debug install

B.2. Also if I understood right it should be possible to define so-called aliases

# setup.cfg
[aliases]
release_install = build_ext install
debug_install = build_ext --debug install
$ path/to/pythonX.Y setup.py release_install
$ path/to/pythonX.Y setup.py debug_install

References

You can use something like below to do it

from distutils.core import setup
from distutils.command.install import install
from distutils.command.build_ext import build_ext

class InstallLocalPackage(install):
    def run(self):
        build_ext_command = self.distribution.get_command_obj("build_ext")
        build_ext_command.debug = 1
        build_ext.run(build_ext_command)
        install.run(self)

setup(
    name='psetup',
    version='1.0.1',
    packages=[''],
    url='',
    license='',
    author='tarunlalwani',
    author_email='',
    description='',
    cmdclass={
        'install': InstallLocalPackage
    }
)
Related