【问题标题】:How do I build multiple wheel files from a single setup.py?如何从单个 setup.py 构建多个轮文件?
【发布时间】:2018-07-12 01:32:30
【问题描述】:

在我的项目中,我有一个 setup.py 文件,它使用以下命名空间模式构建多个模块:

from setuptools import setup

setup(name="testmoduleserver",
      packages=["testmodule.server","testmodule.shared"],
      namespace_packages=["testmodule"])

setup(name="testmoduleclient",
      packages=["testmodule.client","testmodule.shared"],
      namespace_packages=["testmodule"])

我正在尝试为这两个包构建轮文件。但是,当我这样做时:

python -m pip wheel .

它只为其中一个定义构建包。

为什么只构建一个包?

【问题讨论】:

  • 这不是你应该使用的setuptools.setup()。你能举一个更完整的例子来说明你的setup.py 是什么样的吗?

标签: python pip python-3.6 python-wheel


【解决方案1】:

您不能在setup.py 中多次调用setuptools.setup(),即使您想从一个代码库中创建多个包。

相反,您需要将所有内容分离到 separate namespace packages,并为每个设置一个 setup.py(它们都可以驻留在一个 Git 存储库中!):

testmodule/
    testmodule-client/
        setup.py
        testmodule/
            client/
                __init__.py
    testmodule-server/
        setup.py
        testmodule/
            server/
                __init__.py
    testmodule-shared/
        setup.py
        testmodule/
            shared/
                __init__.py

每个setup.py 都包含类似的内容

from setuptools import setup

setup(
    name='testmodule-client',
    packages=['testmodule.client'],
    install_requires=['testmodule-shared'],
    ...
)

from setuptools import setup

setup(
    name='testmodule-server',
    packages=['testmodule.server'],
    install_requires=['testmodule-shared'],
    ...
)

from setuptools import setup

setup(
    name='testmodule-shared',
    packages=['testmodule.shared'],
    ...
)

要构建所有三个轮子,然后运行

pip wheel testmodule-client
pip wheel testmodule-server
pip wheel testmodule-shared

【讨论】:

  • 谢谢!这绝对是正确的方法,我已经验证它会起作用。我最终通过使用以下答案以 hacky 方式修复它:stackoverflow.com/a/50468000/10067085 您的答案帮助我找到了。
  • 我刚遇到这个问题,那些pip wheel 命令对我来说不太适用。我需要添加一个尾随/,并指定--no-deps(至少对于两个install_requires。所以例如我有pip wheel --no-deps testmodule-client/
猜你喜欢
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
  • 2019-07-09
  • 1970-01-01
  • 2020-01-26
  • 1970-01-01
  • 2023-03-27
  • 2019-07-01
相关资源
最近更新 更多