1 year ago

#388845

test-img

Sean DeNigris

Python: Single Module Package Structure

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.

python

python-packaging

0 Answers

Your Answer

Accepted video resources