How do I subclass the build command?

后端 未结 2 841
难免孤独
难免孤独 2021-01-11 19:38

The subject is self-descriptive: I need to subclass the setup.py build command in order to perform additional build steps. However I\'ve failed to find any

相关标签:
2条回答
  • 2021-01-11 20:05

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

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

    import distutils.command.build
    
    class BuildCommandProxy(distutils.command.build.build):
        pass
    
    0 讨论(0)
  • 2021-01-11 20:11

    For completeness, here is a full 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})
    
    0 讨论(0)
提交回复
热议问题