7

When I execute a command python setup.py install or python setup.py develop it would execute build_ext command as one of the steps. How can I pass --debug option to it as if it was invoked as python setup.py build_ext --debug?

UPDATE Here is a setup.py very similar to mine: https://github.com/pybind/cmake_example/blob/11a644072b12ad78352b6e6649db9dfe7f406676/setup.py#L43

I'd like to invoke python setup.py install but turn debug property in build_ext class instance to 1.

Gill Bates
  • 14,330
  • 23
  • 70
  • 138
  • What is the problem with the current code? Error message? Could you please show that? – xilpex May 13 '20 at 23:35
  • @Xilpex, here is an example code: https://github.com/pybind/cmake_example/blob/11a644072b12ad78352b6e6649db9dfe7f406676/setup.py#L43 – Gill Bates May 14 '20 at 09:08
  • So you want to always pass the option to *build\_ext*. Do you want to pass it just to any sub command? What doesn't work for the file given as an example? – CristiFati May 15 '20 at 10:51
  • 1
    @CristiFati, of course I don't want to always pass it. Option should be optional. The use case is that sometimes I want to install a release build and sometimes - a development build. – Gill Bates May 15 '20 at 12:11

2 Answers2

12

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

sinoroc
  • 18,409
  • 2
  • 39
  • 70
1

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
    }
)
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265