Skip to content

Commit 77ef67f

Browse files
committed
Prebuild setup.cfg
1 parent 766b210 commit 77ef67f

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This Makefile is used to manage development and distribution.
33
#
44
# Created: 2022-08-11
5-
# Updated: 2022-08-31
5+
# Updated: 2022-09-01
66
#
77

88
.PHONY: build create-venv help prebuild publish test test-all update-venv
@@ -64,7 +64,7 @@ dev-venv-create: dev-venv-base dev-venv-install
6464

6565
dev-venv-install:
6666
${VENV} pip install --upgrade pip setuptools wheel
67-
${VENV} pip install --upgrade build sphinx tox twine typing-extensions
67+
${VENV} pip install --upgrade build sphinx tomli tox twine typing-extensions
6868
${VENV} pip install -e "${SRC_DIR}"
6969

7070

prebuild.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""
2-
This script generates files required for source and wheel distributions.
2+
This script generates files required for source and wheel distributions,
3+
and legacy installations.
34
"""
45

56
import argparse
7+
import configparser
68
import sys
79

10+
import tomli
11+
812

913
def generate_readme_dist() -> None:
1014
"""
@@ -25,6 +29,43 @@ def generate_readme_dist() -> None:
2529
fh.write(output)
2630

2731

32+
def generate_setup_cfg() -> None:
33+
"""
34+
Generate the "setup.cfg" file from "pyproject.toml" in order to
35+
support legacy installation with "setup.py".
36+
"""
37+
print("Read: pyproject.toml")
38+
with open("pyproject.toml", 'rb') as fh:
39+
config = tomli.load(fh)
40+
41+
print("Write: setup.cfg")
42+
output = configparser.ConfigParser()
43+
output['metadata'] = {
44+
'author': config['project']['authors'][0]['name'],
45+
'author_email': config['project']['authors'][0]['email'],
46+
'classifiers': "\n" + "\n".join(config['project']['classifiers']),
47+
'description': config['project']['description'],
48+
'license': config['project']['license']['text'],
49+
'long_description': f"file: {config['project']['readme']}",
50+
'long_description_content_type': "text/x-rst",
51+
'name': config['project']['name'],
52+
'url': config['project']['urls']['Source Code'],
53+
'version': f"attr: {config['tool']['setuptools']['dynamic']['version']['attr']}",
54+
}
55+
output['options'] = {
56+
'packages': "find:",
57+
'python_requires': config['project']['requires-python'],
58+
'setup_requires': ", ".join(config['build-system']['requires']),
59+
'test_suite': "tests",
60+
}
61+
output['bdist_wheel'] = {
62+
'universal': "1",
63+
}
64+
65+
with open("setup.cfg", 'w') as fh:
66+
output.write(fh)
67+
68+
2869
def main() -> int:
2970
"""
3071
Run the script.
@@ -34,6 +75,7 @@ def main() -> int:
3475
parser.parse_args(sys.argv[1:])
3576

3677
generate_readme_dist()
78+
generate_setup_cfg()
3779

3880
return 0
3981

setup.cfg

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[metadata]
2+
author = Caleb P. Burns
3+
author_email = cpburnz@gmail.com
4+
classifiers =
5+
Development Status :: 4 - Beta
6+
Intended Audience :: Developers
7+
License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
8+
Operating System :: OS Independent
9+
Programming Language :: Python
10+
Programming Language :: Python :: 3
11+
Programming Language :: Python :: 3.7
12+
Programming Language :: Python :: 3.8
13+
Programming Language :: Python :: 3.9
14+
Programming Language :: Python :: 3.10
15+
Programming Language :: Python :: 3.11
16+
Programming Language :: Python :: Implementation :: CPython
17+
Programming Language :: Python :: Implementation :: PyPy
18+
Topic :: Software Development :: Libraries :: Python Modules
19+
Topic :: Utilities
20+
description = Utility library for gitignore style pattern matching of file paths.
21+
license = MPL 2.0
22+
long_description = file: README-dist.rst
23+
long_description_content_type = text/x-rst
24+
name = pathspec
25+
url = https://github.com/cpburnz/python-pathspec
26+
version = attr: pathspec._meta.__version__
27+
28+
[options]
29+
packages = find:
30+
python_requires = >=3.7
31+
setup_requires = setuptools>=40.8.0
32+
test_suite = tests
33+
34+
[bdist_wheel]
35+
universal = 1
36+

setup.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
"""
2-
This setup script only exists to support installations where pip cannot
3-
be used such as for system packages.
2+
This setup script only exists to support legacy installations where pip
3+
is cumbersome be used such as for system packages.
44
"""
55

6-
import setuptools
7-
import sys
6+
from setuptools import setup
87

9-
if int(setuptools.__version__.split(".")[0]) < 61:
10-
sys.stderr.write((
11-
"WARNING: Installed version of setuptools, {version}, is too old. "
12-
"Version 61.0.0 is required for the pyproject.toml configuration "
13-
"to load. This will most likely build and install as a packaged "
14-
"named 'UNKNOWN'.\n"
15-
).format(version=setuptools.__version__))
16-
17-
setuptools.setup()
8+
setup()

0 commit comments

Comments
 (0)