在setup.py

时间:2019-02-11 09:23:14

标签: python setuptools setup.py distutils

我正在使用setuptools中的安装程序来创建setup.py,我想知道是否有可能通过编程方式更改输出目录以将其从dist/进行更改。

我知道您可以使用--dist-dir标志从命令行执行此操作,但是我希望能够在setup.py文件的 in 中执行此操作

有人有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您需要覆盖set the default name

from distutils.command.bdist import bdist as _bdist
from distutils.command.sdist import sdist as _sdist

dist_dir = 'my-dist-dir'

class bdist(_bdist):
    def finalize_options(self):
        _bdist.finalize_options(self)
        self.dist_dir = dist_dir

class sdist(_sdist):
    def finalize_options(self):
        _sdist.finalize_options(self)
        self.dist_dir = dist_dir

setup(
    cmdclass={
        'bdist': bdist,
        'sdist': sdist,
    },
    …
)

其他bdist_*条命令copy the value from bdist