meson-python-sources-fixer
This is a minimal linter that checks that all Python source files in a Python
package are listed in a meson.build file.
Installation and Usage
To use it via pre-commit, add the following to your
.pre-commit-config.yaml:
repos:
- repo: https://github.com/osandov/meson-python-sources-fixer
rev: v1.0
hooks:
- id: meson-python-sources-fixer
To run it manually:
$ pip install meson-python-sources-fixer
$ cd <project-directory>
$ meson-python-sources-fixer
By default, meson-python-sources-fixer will automatically create or rewrite
meson.build files for Python packages as needed. This behavior can be changed
with the --check and --diff options.
Expected Format
meson-python-sources-fixer expects a specific layout and format.
Root meson.build File
By default, the root meson.build file must have two things:
- A variable initialized to
import('python').find_installation(). - A
subdir()call for each top-level Python package in the project.
For example:
$ tree
.
├── meson.build
└── pkg
├── foo.py
├── __init__.py
├── meson.build
└── nested
├── bar.py
└── __init__.py
$ cat meson.build
...
py = import('python').find_installation()
subdir('pkg')
By default, each package is assumed to be installed at the top-level of the
Python installation. E.g., subdir('pkg') and subdir('src/pkg') would both
be installed as /usr/lib/pythonX.Y/site-packages/pkg.
The import('python').find_installation() requirement can be overridden with
the --py-installation option.
The list of packages and their installation locations can be overridden with
the --package option.
meson-python-sources-fixer will not modify the root meson.build file.
Package meson.build Files
Each top-level Python package should have its own meson.build file listing
its sources files with a call to
py.install_sources()
(where py is the python_installation object defined in the root
meson.build file) per subpackage. The sources should be lexicographically
sorted, as should the subpackages. For example:
$ cat pkg/meson.build
py.install_sources(
'__init__.py',
'foo.py',
subdir: 'pkg',
)
py.install_sources(
'nested/__init__.py',
'nested/bar.py',
subdir: 'pkg/nested',
)
Note that subpackages (e.g., pkg/nested) should not have their own
meson.build files. They are represented in the top-level package.
Limitations
meson-python-sources-fixer is relatively simple and has a few limitations:
- It requires an
__init__.pyfile in each package. - It does not require a specific code style, but if a file needs to be updated, it will not maintain the existing code style.
- It allows comments inside of and between calls to
py.install_sources(), but if a file needs to be updated, it cannot preserve comments and will therefore refuse to update the file. - It does not understand variables, dynamic lists of sources, loops, conditionals, etc.
Release files for meson-python-sources-fixer 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| meson_python_sources_fixer-1.0.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| meson_python_sources_fixer-1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.8 kB
Release files / meson_python_sources_fixer-1.0.tar.gz
| Download URL | meson_python_sources_fixer-1.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
888d4c5eedc2cea8f986e46e5cabd157905e89ceafd4d23c9605f3a8fb951cc2
|
|
BLAKE2b-256 checksum How to use checksums |
afce0a858ead7c3ebff48e3e4df14055a544af5b0652afd84792cb5a1f6d3eca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / meson_python_sources_fixer-1.0-py3-none-any.whl
| Download URL | meson_python_sources_fixer-1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92c363bedddaab233309a94dce6886941f7b498c32a318a03b2f4c6d786c7787
|
|
BLAKE2b-256 checksum How to use checksums |
8009e0817bd28c769bbcdfb5534316a9e6958b7e39de9970c3f0bc6cc97eef1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|