Setuptools软件包发现
我的项目注释下面有下面的包装树
└── src
| ├── mypkg1
| │ ├── module1.py
| │ ├── module2.py
| │ └── __init__.py
| | |-- setup.py
| | |__ requirements.py
| └── mypkg2
| ├── module1.py
| └── __init__.p
|
|---- base
| |----- init.py
| |----- module1.py
-SRC和基础处于同一级别。
我应该如何配置setup.py
文件,以便我可以仅使用base
和mypkg1
packages,并排除mypkg2
。
我已经尝试提及['base','mypkg1']
in packages中,但没有使用find_packages()
它将仅显示mypkg1 < /code>和
mypkg2
。
I have below package tree for my project
└── src
| ├── mypkg1
| │ ├── module1.py
| │ ├── module2.py
| │ └── __init__.py
| | |-- setup.py
| | |__ requirements.py
| └── mypkg2
| ├── module1.py
| └── __init__.p
|
|---- base
| |----- init.py
| |----- module1.py
Note - src and base are at same level.
How should I configure setup.py
file, so that I can install base
and mypkg1
packages only and exclude mypkg2
.
I have tried mentioning ['base','mypkg1']
in packages but didn't worked also tried using find_packages()
it will show up only mypkg1
and mypkg2
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于复杂的代码库布局,有很多事情要处理。另外,我不确定为什么您要在
src/mypkg1
中显示设置脚本 - 从那里调用它会找不到src
之外的任何东西,因此您将拥有没有机会包括base
。在下面的示例中,我切换到包含src
和base
dirs的根目录:base发现,
因为
base
在项目root下,将通过plainfind_packages
调用来发现:要在
src
下查找软件包,请通过 where 参数:排除
mypkg2 ,通过
排除
参数中的列表将其传递:软件包结构映射和文件包含
调用
setuptools.setup()
与收集的软件包一样,仅适用于>基本
,因为mypkg1
不在根级别上。您必须通过package_dir
映射其位置:但是,这是指令
setup()
在 src中查找 all> All packages的文件,在base
下制作文件。因此,您必须明确地映射:现在完成最小设置脚本,
例如构建车轮时,这将产生以下文件布局:
There are multiple things to take care of due to the complex codebase layout. Also, I'm not sure why you are showing the setup script inside
src/mypkg1
- invoking it from there will not find anything outside ofsrc
and thus you'll have no chance to includebase
. In the below example, I switched to the root directory containing bothsrc
andbase
dirs:Package discovery
Since
base
is under the project root, it will be discovered by plainfind_packages
invocation:To find packages under
src
, pass it viawhere
argument:To exclude
mypkg2
, pass it via the list inexclude
argument:Package structure mapping and file inclusion
Calling
setuptools.setup()
as is with the collected packages will only work forbase
, sincemypkg1
is not on the root level. You have to map its location viapackage_dir
:This, however, instructs
setup()
to look for files of all packages insrc
, which makes files underbase
not findable. You thus have to map it explicitly:Complete minimal setup script
Now when e.g. building a wheel, this will produce the following file layout: