Skip to main content

apply a consistent format to `setup.cfg` files

Project description

Build Status Azure DevOps coverage 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.0.0
    hooks:
    -   id: setup-cfg-fmt

cli

Consult the help for the latest usage:

$ setup-cfg-fmt --help
usage: setup-cfg-fmt [-h] [filenames [filenames ...]]

positional arguments:
  filenames

optional arguments:
  -h, --help  show this help message and exit

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-py3-version argument (currently defaulting to 3.6)

If the minimum version is detected as python2, the --min-py3-version argument will be used to exclude python3.x versions (see below).

 [options]
 py_modules = pre_commit
+python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*

adds python version classifiers

classifiers are generated based on:

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

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

 name = pkg
 version = 1.0
+classifiers =
+    Programming Language :: Python :: 2
+    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.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

setup_cfg_fmt-2.0.0-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: setup_cfg_fmt-2.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for setup_cfg_fmt-2.0.0.tar.gz
Algorithm Hash digest
SHA256 be9e41df8a74ad7cbbfde581f0f3e28db25961d714dfb35e6a0e886b209a71da
MD5 de8a3d21f4a194d234bec1a66e17daba
BLAKE2b-256 ff434a3722ffa8e99a9bf59f06a6eb713e428f99a83bc91c567e751acd8150cf

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: setup_cfg_fmt-2.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for setup_cfg_fmt-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4d7cf9d36138e730bf857dc11da979d76c713f9c2d30b30ba592baffcf6dedf4
MD5 313fce5170034fc8773f58d50d6b343b
BLAKE2b-256 4d304680a8fec8fbe19f95aa6fe704a213c8fc12099bbbdd90abf39a8901d787

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