How can I subclass a build command?

The object is self-describing: I need to subclass the setup.py build in order to complete the additional build steps. However, I could not find the build command class for inheritance. I have tried:

 class BuildCommandProxy(setuptools.command.build): pass 

and

 class BuildCommandProxy(distutils.command.build): pass 

and even:

 class BuildCommandProxy(setuptools.distutils.command.build): pass 

without any success.

UPDATE : Finding how to implement something like this with setuptools .

UPDATE2 . I have a custom command implementation:

 class CustomCommand(setuptools.Command): # ... 

What I would like to implement is to pass this cmdclass command as follows:

 cmdclass={ "build": CustomCommand, } 

and then call the original build in CustomCommand.run after doing some custom steps.

+6
source share
2 answers

Setuptools does not override the distutils build ; only build_py and build_ext .

So, to create your own subclass, you need to import from the distutils.command.build module, which contains the build class ( Command subclass):

 import distutils.command.build class BuildCommandProxy(distutils.command.build.build): pass 
+8
source

For completeness, here is a complete example of how to add custom build operations:

 import distutils.command.build # Override build command class BuildCommand(distutils.command.build.build): def run(self): # Run the original build command distutils.command.build.build.run(self) # Custom build stuff goes here # Replace the build command with ours setup(..., cmdclass={"build": BuildCommand}) 
+1
source

All Articles