繁体   English   中英

Python setup.py - 运行 setup.py install 时不要构建轮子

[英]Python setup.py - dont build wheel when running setup.py install

我想使用 setup.py 及其所有功能,但我不想为可安装项目构建轮子。 是否有旗帜或其他东西只是跳过建筑轮子?

这背后的原因是我使用 setuptools 提供的自定义 InstallCommand 将环境变量传递给下一个可安装项目(依赖项),并且在构建轮子时 - 看不到环境变量,因此只有安装(而不是轮子构建)有效。

编辑:

由于我正在使用构建选项,因此我收到警告:

pip/_internal/commands/install.py:211: UserWarning: 由于使用 --build-options / --global-options / --install-options 禁用所有轮子的使用。

因为我使用了这个自定义 InstallCommand:

class InstallCommand(install):
    user_options = install.user_options + [
    ('environment=', None, 'Specify a production or development environment.'),
]

def initialize_options(self):
    install.initialize_options(self)
    self.environment = None

def finalize_options(self):
    install.finalize_options(self)

    global ENVIRONMENT

    try:
        # Check if environment is set
        is_dev()
    except AssertionError:
        # If not - assert that this class has a set environment
        assert self.environment in ['dev', 'prod'], 'Bad environment propagated from parent project.'
        ENVIRONMENT = self.environment

def run(self):
    install.run(self)

我收到此错误:

installing to build/bdist.linux-x86_64/wheel
running install
Traceback (most recent call last):
File "/tmp/pip-req-build-xnp6kolm/setup_helper.py", line 26, in finalize_options
  is_dev()
File "/tmp/pip-req-build-xnp6kolm/setup_helper.py", line 126, in is_dev
assert (prod or dev) is True, 'Environment should be set to dev or prod'
AssertionError: Environment should be set to dev or prod

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/tmp/pip-req-build-xnp6kolm/setup_helper.py", line 29, in finalize_options
  assert self.environment in ['dev', 'prod'], 'Bad environment propagated from parent project.'
AssertionError: Bad environment propagated from parent project.

----------------------------------------
Failed building wheel for ivs-repository-manager - HAVE A NOTICE AT THIS LINE !!! I HAVE RUN SETUP.PY INSTALL, NOT BDIST
Running setup.py clean for ivs-repository-manager
Failed to build ivs-repository-manager

但! 在此异常之后,安装仍然成功,并且我看到了已安装的软件包。 我只是在 setuptools 尝试构建轮子时收到这些错误。

所以似乎在构建用 --install-options 传播的轮子环境时是看不到的。

找到了解决办法:

不要使用setup.py install,最好创建一个源码分发setup.py sdist,然后用pip安装。 这是示例:

python setup.py sdist
python -m pip install dist/* --install-option=--environment='dev'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM