Linter to list all Python sources in meson.build
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file meson_python_sources_fixer-1.0.tar.gz.
File metadata
- Download URL: meson_python_sources_fixer-1.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
888d4c5eedc2cea8f986e46e5cabd157905e89ceafd4d23c9605f3a8fb951cc2
|
|
| MD5 |
8b276ef142916e80ea7f359293fa47ec
|
|
| BLAKE2b-256 |
afce0a858ead7c3ebff48e3e4df14055a544af5b0652afd84792cb5a1f6d3eca
|
File details
Details for the file meson_python_sources_fixer-1.0-py3-none-any.whl.
File metadata
- Download URL: meson_python_sources_fixer-1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92c363bedddaab233309a94dce6886941f7b498c32a318a03b2f4c6d786c7787
|
|
| MD5 |
0bd7211c68c995f1979a5f0274d4e29c
|
|
| BLAKE2b-256 |
8009e0817bd28c769bbcdfb5534316a9e6958b7e39de9970c3f0bc6cc97eef1b
|