编写pyproject.toml文件来构建子模块以进行独立导入

问题描述 投票:0回答:1

我正在尝试为我的项目编写一个 pyproject.toml 文件,其中包含几个子模块(注意:我没有对此结构的最终决定权),并且我想独立构建子模块。

我的项目结构是:

project/
   pyproject.toml
   src_dir/
      module1_dir/
         module1_file1.py
         module1_file2.py
         mod1_tests_dir/
      module2_dir/

module1_file2.py
中,我有一个看起来像
from module1_dir.module1_file1 import var
的导入。这在单元测试中没有问题。但在功能测试中
python module1_file2.py
我收到一个错误,
ModuleNotFoundError: No module named 'module1_dir'

我想编写一个 pyproject.toml 文件,该文件允许我独立构建

module1
module2
,以便我可以按照上述样式从它们中的每一个导入。

现在我有

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
 
[project]
name = "project"
version = "0.0.1"
authors = [{name="Me", email="[email protected]"}]
requires-python = ">=3.11"
 
[tool.setuptools.packages.find]
where = ["src_dir/module1_dir"]
include = ["module1_dir"]
 
[tool.poetry]
packages = [
    { include = "module1_dir" }
]
python setuptools pyproject.toml
1个回答
0
投票

如果我必须猜测,我会说问题是你的“where”参数,它指向包内,所以无法找到 module1_dir.module_fileX ,只有 module_fileX 可以。改变

© www.soinside.com 2019 - 2024. All rights reserved.