在setup.py中更改输出目录 [英] Change output directory in setup.py

查看:120
本文介绍了在setup.py中更改输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using setup from setuptools to create a setup.py, and I was wondering if it's possible to change the output directory programmatically to change it from dist/.

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

I'm aware that you can do this from the command line using the --dist-dir flag, but I want to be able to do from within the setup.py file instead.

有人有什么想法吗?

推荐答案

您需要重写代码设置默认名称

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 _ * 命令 bdist

这篇关于在setup.py中更改输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆