我之前使用 src 布局来创建模块,但被要求以平面布局进行。我已经阅读了 setuptools 中的所有文档,但它们非常令人困惑(我觉得它们不可读并且缺乏示例)。 src 布局的 .toml 是:
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "detection_engine"
authors = [
{name = "Josiah Carberry", email = "[email protected]"},
]
description = "Detection Engine"
readme = "README.md"
requires-python = ">=3.8"
dependencies = [
"requests",
'importlib-metadata; python_version<"3.10"',
]
dynamic = ["version"]
[project.optional-dependencies]
yolox = [
"loguru==0.7.2",
"tqdm==4.66.1",
"thop==0.1.1.post2209072238",
"ninja==1.11.1.1",
"tabulate==0.9.0",
"psutil==5.9.6",
"tensorboard==2.14.0",
"pycocotools>=2.0.7",
"onnx>=1.13.0",
"onnx-simplifier",
]
mmcv = [
"loguru==0.5.3",
"mmdet==2.28.1",
"mmcv-full",
"numpy",
"opencv-python==4.7.0.72",
"pydantic",
"pytest-cov==4.0.0",
"pytest==7.2.2",
"torch==2.0.1",
"torchvision==0.15.2"
]
[tool.setuptools.packages.find]
where = ["src"]
include = ["*"]
namespaces = true # set false to not include folders without __init__.py file.
但是当我放置 where = ["."] 时,它会在 lib 文件夹中创建 4 个文件夹,而不是一个包含 4 个文件夹的模块“detection_engine”包。我不知道我做错了什么,非常感谢任何帮助。
├── detection
├── detection_engine.egg-info
├── dist
├── engines
├── environment.yml
├── MANIFEST.in
├── mmcv_install.sh
├── models
├── pyproject.toml
├── README.md
├── requirements_mmcv.txt
├── requirements_yolox.txt
├── setup.py
└── tracking
提前致谢。
当你写下:
[tool.setuptools.packages.find]
where = ["."]
include = ["*"]
namespaces = true
您告诉 setuptools 扫描根目录中看起来像 Python 包的所有文件夹(即使它们不包含
__init__.py
或任何 .py
文件 [^1])并将它们全部添加到轮子中以稍后将其安装在用户的 site-packages
目录中的方式进行存档。
看来你的项目结构确实包含4个文件夹,可能可以理解为包:
detection
,engines
,models
,tracking
。
如果您希望您的用户编写
import detection_engine
,我建议创建一个detection_engine
文件夹,移动应安装在其中的所有相关文件夹和文件(请注意setuptools
文档中的示例的作用)使用“父”文件夹)。
或者,如果您想忽略顶层的某些文件夹,您也可以将
tool.setuptools.packages.find.include
配置更改为 include = ["<name-of-your-top-level-package>*"]
[^1]:Python 允许您将文件夹作为命名空间包导入,即使它们不包含
.py
文件。