Skip to main content

Generate __about__.py with dunder meta.

Project description

metametameta

Generate dunder metadata file with __title__, __author__, etc. Also tools to discover these in other packages.

Installation

pipx install metametameta

Usage

Defaults to putting an __about__.py file in the module directory, assuming your package name is your main module name.

metametameta poetry

Or set everything explicitly:

metametameta poetry --name "something" --source some.toml --output OUTPUT "mod/meta/__meta__.py"

Subcommand per source.

usage: metametameta [-h] {setup_cfg,pep621,poetry,importlib} ...

metametameta: Generate __about__.py from various sources.

positional arguments:
  {setup_cfg,pep621,poetry,importlib}
                        sub-command help
    setup_cfg           Generate from setup.cfg
    pep621              Generate from PEP 621 pyproject.toml
    poetry              Generate from poetry pyproject.toml
    importlib           Generate from installed package metadata

options:
  -h, --help            show this help message and exit

Subcommand help (they all have the same switches)

usage: metametameta poetry [-h] [--name NAME] [--source SOURCE] [--output OUTPUT]

options:
  -h, --help       show this help message and exit
  --name NAME      Name of the project (from file if omitted)
  --source SOURCE  Path to pyproject.toml
  --output OUTPUT  Output file

TODO: Programmatic interface.

import metametameta as mmm

# not implemented yet
mmm.find_metadata("path/to/module")

Motivation

There are many modern ways to get metadata about packages, as of 2024, importlib.metadata and it's backports will get you lots of metadata for yours and other packages.

The newest way is PEP-621, see also packaging.python.org

The oldest way to provide metadata was to use dunder variables in your package, e.g. __author__, __version__, etc.

The method was never strongly standardized, neither officially nor informally. Here is one early proponent of this sort of metadata.

  • Metadata fields can appear in any or no python file in a project.
  • Sometimes they are at the top of a single file python module, common locations for metadata:
    • __init__.py
    • __meta__.py
    • __about__.py
  • Some metadata elements could reasonably be in every single file.
  • There are no particular standards for the type of __author__. It could be a string, space delimited string, list or tuple. That is true for the other metadata elements as well.
  • Sometimes the metadata values are code, e.g. __version__ could be a string or some tuple or data class representing a version.

Workflow

On each build, regenerate the __about__.py. Pick one source of your canonical metadata, e.g. pyproject.toml, setup.py, setup.cfg.

Using metadata

If you have a lot of packages and you are doing analytics or something with them, you could compile all the metadata as declared in the source code. It could be different from the metadata that shows on the PyPI page. If you are searching for contact info for a package maintainer, this might be useful.

Another marginal use case is in error logging. Error loggers gather up info from just about anywhere, anything can be a clue including metadata of dependencies. So this is one more source of that. See bug_trail for a proof of concept for this usage.

Another marginal use case is that is a folksonomy, a taxonomy created by the people. The official metadata is governed by the Python Packaging Authority and the Python Software Foundation. If, say, you wanted to add a metadata item for __mailing_address__ you could easily do it with source code metadata.

Project details


Download files

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

Source Distribution

metametameta-0.1.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

metametameta-0.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file metametameta-0.1.1.tar.gz.

File metadata

  • Download URL: metametameta-0.1.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for metametameta-0.1.1.tar.gz
Algorithm Hash digest
SHA256 86bfb063f93a895065823dd6cbc21a49083a979b87083c3f6b6d2899d1dcdca0
MD5 b2908b8671df4b51cd9a93c9a36245f6
BLAKE2b-256 284ed5cea961b0c18c268cb843cd0f6a6be96433c3c703197d884bfa70f3748d

See more details on using hashes here.

File details

Details for the file metametameta-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: metametameta-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for metametameta-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed965042c2aef558e9e6499327b38a1165ea469171005070165f8aa719f064b4
MD5 173c0a78d495e5d4902308c9a3d8e975
BLAKE2b-256 f0deef0bcafdef2c83b69794836fb73ce6e833096d9119456838865e333a94fe

See more details on using hashes here.

Supported by

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