且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从distutils二进制发行版中剥离源代码?

更新时间:2023-11-15 23:15:28

distutils build_py命令很重要,因为它(间接地)被所有创建命令重用分布。如果您重写byte_compile(files)方法,则类似以下内容:

The distutils "build_py" command is the one that matters, as it's (indirectly) reused by all the commands that create distributions. If you override the byte_compile(files) method, something like:

try:
    from setuptools.command.build_py import build_py
except ImportError:
    from distutils.command.build_py import build_py

class build_py(build_py)
   def byte_compile(self, files):
       super(build_py, self).byte_compile(files)
       for file in files:
           if file.endswith('.py'):
               os.unlink(file)

setup(
    ...
    cmdclass = dict(build_py=build_py),
    ...
)

您应该能够做到这一点,以便在将源文件复制到安装目录(这是一个临时目录)之前,将其从构建树中删除。

You should be able to make it so that the source files are deleted from the build tree before they're copied to the "install" directory (which is a temporary directory when bdist commands invoke them).

注意:我尚未测试此代码; YMMV。

Note: I have not tested this code; YMMV.