Python:单模块包结构
我想应用包装python项目只有一个模块/.py
文件。
我是Python的新手,所以我可能会误解这里的某些内容(但是数十年来编码),但是我看到的许多包装教程导致了必须访问的名称,这些名称必须像mypackage.mymodule.mymodule.xyz
。他们显示的琐碎示例通常是samelongname.samelongname
的形式。对于单个模块项目,这似乎是过度的。
我的主要目的是只为用户范围界定一个级别,即modulename
。
“ noreferrer”> packaging python projects 建议结构:
packaging_tutorial/
├── LICENSE
├── pyproject.toml
├── README.md
├── setup.cfg
├── src/
│ └── example_package/
│ ├── __init__.py
│ └── example.py
└── tests/
我特别喜欢放置的想法.py
src
下的文件清楚区分它。
对于一个模块,没有包装,我认为那是(摘录):
packaging_tutorial/
├── src/
│ └── example.py
他们提供的配置是(摘录):
[options]
package_dir =
= src
packages = find:
python_requires = >=3.6
[options.packages.find]
where = src
但是,当我做python3 -m build
时,.py
.py < /代码>文件最终不会进入内置区域。
在找到链接的文档之前,我将.py
保留在软件包root(即不在src
下),并使用setup.py而不是setup.cfg这样:
from setuptools import setup
setup(
py_modules=['mpvsilence']
)
这有效,但是当我试图使其更像文档时:
py_modules
似乎在setup.cfg中不起作用。py_modules = ['src/mpvsilence']
似乎在设置中不起作用
。任何指导将不胜感激。
I'd like to apply the Packaging Python Projects process to a package with only one module/.py
file.
I'm new to Python so I'm probably misunderstanding something here (but coding for decades), but many packaging tutorials I've seen lead to names that must be accessed like mypackage.mymodule.xyz
. The trivial examples they show are often of the form samelongname.samelongname
. For single module projects, that seems overkill.
My main objective is to just have one level of scoping for users i.e. modulename
.
Packaging Python Projects suggests the structure:
packaging_tutorial/
├── LICENSE
├── pyproject.toml
├── README.md
├── setup.cfg
├── src/
│ └── example_package/
│ ├── __init__.py
│ └── example.py
└── tests/
I specifically like the idea of putting the .py
file under src
to clearly distinguish it.
For one module and no package, I was thinking that would be (excerpted):
packaging_tutorial/
├── src/
│ └── example.py
The configuration they offer is (excerpted):
[options]
package_dir =
= src
packages = find:
python_requires = >=3.6
[options.packages.find]
where = src
However, when I do python3 -m build
, the .py
file does not end up in the built dist.
Before finding the linked docs, I was keeping the .py
in the package root (i.e. not under src
) and using a setup.py instead of a setup.cfg like this:
from setuptools import setup
setup(
py_modules=['mpvsilence']
)
That worked, but when I tried to make it more like the docs:
py_modules
doesn't seem to work in a setup.cfg.py_modules=['src/mpvsilence']
didn't seem to work in the setup.py
I'm really just flopping around here. Any guidance would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论