Skip to main content

apply a consistent format to `setup.cfg` files

Project description

build status pre-commit.ci status

setup-cfg-fmt

apply a consistent format to setup.cfg files

installation

pip install setup-cfg-fmt

as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/asottile/setup-cfg-fmt
    rev: v2.5.0
    hooks:
    -   id: setup-cfg-fmt

cli

Consult the help for the latest usage:

$ setup-cfg-fmt --help

what does it do?

sets a consistent ordering for attributes

For example, name and version (the most important metadata) will always appear at the top.

 [metadata]
-version = 1.14.4
-name = pre_commit
+name = pre_commit
+version = 1.14.4

normalizes dashes to underscores in project name

  • pip will normalize names to dashes foo_bar => foo-bar
  • python setup.py sdist produces a filename with the name verbatim
  • pip wheel . produces a filename with an underscore-normalized name
$ # with dashed name
$ python setup.py sdist && pip wheel -w dist .
...
$ ls dist/ | cat
setup_cfg_fmt-0.0.0-py2.py3-none-any.whl
setup-cfg-fmt-0.0.0.tar.gz
$ # with underscore name
$ python setup.py sdist && pip wheel -w dist .
...
$ ls dist/ | cat
setup_cfg_fmt-0.0.0-py2.py3-none-any.whl
setup_cfg_fmt-0.0.0.tar.gz

This makes it easier to upload packages to pypi since they end up with the same filename prefix.

 [metadata]
-name = pre-commit
+name = pre_commit

normalizes dashes to underscores in keys

setuptools allows dashed names but does not document them.

 [metadata]
 name = pre-commit
-long-description = file: README.md
+long_description = file: README.md

adds long_description if README is present

This will show up on the pypi project page

 [metadata]
 name = pre_commit
 version = 1.14.5
+long_description = file: README.md
+long_description_content_type = text/markdown

adds license_file / license / license classifier if LICENSE exists

 [metadata]
 name = pre_commit
 version = 1.14.5
+license = MIT
+license_file = LICENSE
+classifiers =
+    License :: OSI Approved :: MIT License

set python_requires

A few sources are searched for guessing python_requires:

  • the existing python_requires setting itself
  • envlist in tox.ini if present
  • python version classifiers that are already set
  • the --min-py-version argument

adds python version classifiers

classifiers are generated based on:

  • the python_requires setting
  • the --max-py-version argument (currently defaulting to 3.11)
  • --include-version-classifiers is specified
 name = pkg
 version = 1.0
+classifiers =
+    Programming Language :: Python :: 3
+    Programming Language :: Python :: 3.7
+    Programming Language :: Python :: 3.8
+    Programming Language :: Python :: 3.9
+    Programming Language :: Python :: 3.10
+    Programming Language :: Python :: 3.11

without --include-version-classifiers only the major version will be included:

 name = pkg
 version = 1.0
+classifiers =
+    Programming Language :: Python :: 3

sorts classifiers

 [metadata]
 name = pre_commit
 version = 1.14.5
 classifiers =
-    Programming Language :: Python :: 3
-    License :: OSI Approved :: MIT License
+    License :: OSI Approved :: MIT License
+    Programming Language :: Python :: 3
     Programming Language :: Python :: 3.6

removes empty options in any section

 [options]
-dependency_links =
 python_requires = >= 3.6.1

related projects

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

setup_cfg_fmt-2.5.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

setup_cfg_fmt-2.5.0-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file setup_cfg_fmt-2.5.0.tar.gz.

File metadata

  • Download URL: setup_cfg_fmt-2.5.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for setup_cfg_fmt-2.5.0.tar.gz
Algorithm Hash digest
SHA256 95d2f87cc77ec763d0de5127f03a274127cc3f458ca46bd9d644ada71d115f58
MD5 7f7ceeff1fecf71f13c924971ba0dcbb
BLAKE2b-256 1184cf83c14d93cf5cdf97b6601d9b6a2988e266dd9bc35db2074bb45c7e8816

See more details on using hashes here.

Provenance

File details

Details for the file setup_cfg_fmt-2.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for setup_cfg_fmt-2.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 631dc66dd799f8177f56cf3c881779a166fea8cb34312baa2f01e32686d27840
MD5 d66ed36575e435d9ba8ba2c7b6c2346f
BLAKE2b-256 8584f555788e3b71f8e9a309afc37fc234569661e47c90d973c84ddb279a80cb

See more details on using hashes here.

Provenance

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