Python setup.py - 在 运行 setup.py 安装时不要构建轮子

Python setup.py - dont build wheel when running setup.py install

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

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

编辑:

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

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

因为我使用了这个自定义安装命令:

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 尝试构建 wheel 时,我只是遇到了这些错误。

因此似乎无法看到使用 --install-options 传播的 building wheel 环境。

找到解决方案:

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

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