简体   繁体   English

Python setup.py:如何获取 find_packages() 以识别子目录中的包

[英]Python setup.py: How to get find_packages() to identify packages in subdirectories

I'm trying to create a setup.py file where find_packages() recursively finds packages.我正在尝试创建一个 setup.py 文件,其中 find_packages() 递归地查找包。 In this example, foo , bar , and baz are all modules that I want to be installed and available on the python path.在这个例子中, foobarbaz都是我想要安装并在 python 路径上可用的模块。 For example, I want to be able to do import foo, bar, baz .例如,我希望能够执行import foo, bar, baz The bar-pack and foo-pack are just regular non-python directories that will contain various support files/dirs (such as tests, READMEs, etc. specific to the respective module). bar-packfoo-pack只是常规的非 python 目录,它们将包含各种支持文件/目录(例如特定于相应模块的测试、自述文件等)。

├── bar-pack
│   └── bar
│       └── __init__.py
├── baz
│   └── __init__.py
├── foo-pack
│   └── foo
│       └── __init__.py
├── setup.py

Then say that setup.py is as follows:然后说setup.py如下:

from setuptools import setup, find_packages
setup(
    name="mypackage",
    version="0.1",
    packages=find_packages(),
)

However, when I run python setup.py install or python setup.py sdist , only the baz directory is identified and packaged.但是,当我运行python setup.py installpython setup.py sdist ,只有baz目录被识别和打包。

I can simplify it down further, and run the following command, but again, only baz is identified.我可以进一步简化它,并运行以下命令,但同样,只有baz被识别。

python -c "from setuptools import setup, find_packages; print(find_packages())"
['baz']

Do you know how I might extend the search path (or manually hard-code the search path) of the find_packages()?您知道我如何扩展 find_packages() 的搜索路径(或手动硬编码搜索路径)吗?

Any help is appreciated.任何帮助表示赞赏。

Setuptools' find_packages supports a "where" keyword ( docs ), and returns a plain old list. Setuptools 的find_packages支持“where”关键字( docs ),并返回一个普通的旧列表。 You could use that:你可以这样使用:

from setuptools import setup, find_packages

setup(
    ...,
    packages=find_packages()
    + find_packages(where="./bar-pack")
    + find_packages(where="./foo-pack"),
)

Or, you can just list them manually.或者,您可以手动列出它们。

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

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