英文:
Poetry: build a package with a non-standard directory structure
问题
I created a repo with this non-standard structure:
- src
- resources
-- a.py
-- b.py ...
I want to make a package out of it (let's call it pack
).
In my pyproject.toml, the relevant lines are:
[tool.poetry]
name = "pack"
include=[{include="src"}]
Then after a pip install
everything is installed under src. Using it would mean from src import ...
not from pack import ...
.
If I follow the standard tree (everything under src/pack), then it works as expected.
Question
Is there a way, with my tree, to have the package built so as from pack import ...
works?
英文:
I created a repo with this non-standard structure:
- src
- resources
-- a.py
-- b.py ...
I want to make a package out of it (let's call it pack
).
In my pyproject.toml, the relevant lines are:
[tool.poetry]
name = "pack"
include=[{include="src"}]
Then after a pip install
everything is installed under src. Using it would mean from src import ...
not from pack import ...
.
If I follow the standard tree (everything under src/pack), then it works as expected.
Question
Is there a way, with my tree, to have the package built so as from pack import ...
works?
答案1
得分: 1
如果你想在你的import
语句中使用pack
,你需要一个叫做这样的文件夹。这是Python发现一个包的方式。
它的位置以及你的项目如何命名是另一回事。如果你的项目结构像这样:
pack
├── README.md
├── pyproject.toml
└── src
└── pack
├── __init__.py
├── a.py
└── b.py
你必须在你的pyproject.toml
中有这样的配置:
[tool.poetry]
name = "pack"
packages = [{include = "pack", from = "src"}]
英文:
If you want to use pack
in your import
statements, you need a folder that is called like this. This is how python discovers a package.
Where it is located and how your project is named is a different story. If you have a project structure like this:
pack
├── README.md
├── pyproject.toml
└── src
└── pack
├── __init__.py
├── a.py
└── b.py
you must have this in your pyproject.toml
[tool.poetry]
name = "pack"
packages = [{include = "pack", from = "src"}]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论