Skip to content

Commit

Permalink
Prebuild setup.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
cpburnz committed Sep 2, 2022
1 parent 766b210 commit 77ef67f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This Makefile is used to manage development and distribution.
#
# Created: 2022-08-11
# Updated: 2022-08-31
# Updated: 2022-09-01
#

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

dev-venv-install:
${VENV} pip install --upgrade pip setuptools wheel
${VENV} pip install --upgrade build sphinx tox twine typing-extensions
${VENV} pip install --upgrade build sphinx tomli tox twine typing-extensions
${VENV} pip install -e "${SRC_DIR}"


Expand Down
44 changes: 43 additions & 1 deletion prebuild.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""
This script generates files required for source and wheel distributions.
This script generates files required for source and wheel distributions,
and legacy installations.
"""

import argparse
import configparser
import sys

import tomli


def generate_readme_dist() -> None:
"""
Expand All @@ -25,6 +29,43 @@ def generate_readme_dist() -> None:
fh.write(output)


def generate_setup_cfg() -> None:
"""
Generate the "setup.cfg" file from "pyproject.toml" in order to
support legacy installation with "setup.py".
"""
print("Read: pyproject.toml")
with open("pyproject.toml", 'rb') as fh:
config = tomli.load(fh)

print("Write: setup.cfg")
output = configparser.ConfigParser()
output['metadata'] = {
'author': config['project']['authors'][0]['name'],
'author_email': config['project']['authors'][0]['email'],
'classifiers': "\n" + "\n".join(config['project']['classifiers']),
'description': config['project']['description'],
'license': config['project']['license']['text'],
'long_description': f"file: {config['project']['readme']}",
'long_description_content_type': "text/x-rst",
'name': config['project']['name'],
'url': config['project']['urls']['Source Code'],
'version': f"attr: {config['tool']['setuptools']['dynamic']['version']['attr']}",
}
output['options'] = {
'packages': "find:",
'python_requires': config['project']['requires-python'],
'setup_requires': ", ".join(config['build-system']['requires']),
'test_suite': "tests",
}
output['bdist_wheel'] = {
'universal': "1",
}

with open("setup.cfg", 'w') as fh:
output.write(fh)


def main() -> int:
"""
Run the script.
Expand All @@ -34,6 +75,7 @@ def main() -> int:
parser.parse_args(sys.argv[1:])

generate_readme_dist()
generate_setup_cfg()

return 0

Expand Down
36 changes: 36 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[metadata]
author = Caleb P. Burns
author_email = cpburnz@gmail.com
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Operating System :: OS Independent
Programming Language :: Python
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
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Utilities
description = Utility library for gitignore style pattern matching of file paths.
license = MPL 2.0
long_description = file: README-dist.rst
long_description_content_type = text/x-rst
name = pathspec
url = https://github.com/cpburnz/python-pathspec
version = attr: pathspec._meta.__version__

[options]
packages = find:
python_requires = >=3.7
setup_requires = setuptools>=40.8.0
test_suite = tests

[bdist_wheel]
universal = 1

17 changes: 4 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
"""
This setup script only exists to support installations where pip cannot
be used such as for system packages.
This setup script only exists to support legacy installations where pip
is cumbersome be used such as for system packages.
"""

import setuptools
import sys
from setuptools import setup

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

setuptools.setup()
setup()

0 comments on commit 77ef67f

Please sign in to comment.