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

2

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.

Nutrilite answered 9/5, 2020 at 6:57 Comment(4)
What is the problem with the current code? Error message? Could you please show that?Flavoprotein
@Xilpex, here is an example code: github.com/pybind/cmake_example/blob/…Nutrilite
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?Paulinapauline
@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.Nutrilite
M
13

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

Melone answered 14/5, 2020 at 8:14 Comment(0)
E
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
    }
)
Ermin answered 14/5, 2020 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.