Skip to main content

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:

  1. A variable initialized to import('python').find_installation().
  2. 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__.py file 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

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meson_python_sources_fixer-1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

meson_python_sources_fixer-1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file meson_python_sources_fixer-1.0.tar.gz.

File metadata

File hashes

Hashes for meson_python_sources_fixer-1.0.tar.gz
Algorithm Hash digest
SHA256 888d4c5eedc2cea8f986e46e5cabd157905e89ceafd4d23c9605f3a8fb951cc2
MD5 8b276ef142916e80ea7f359293fa47ec
BLAKE2b-256 afce0a858ead7c3ebff48e3e4df14055a544af5b0652afd84792cb5a1f6d3eca

See more details on using hashes here.

File details

Details for the file meson_python_sources_fixer-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for meson_python_sources_fixer-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92c363bedddaab233309a94dce6886941f7b498c32a318a03b2f4c6d786c7787
MD5 0bd7211c68c995f1979a5f0274d4e29c
BLAKE2b-256 8009e0817bd28c769bbcdfb5534316a9e6958b7e39de9970c3f0bc6cc97eef1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page