File size: 2,111 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
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:
	"""
	Generate the "README-dist.rst" file from "README.rst" and
	"CHANGES.rst".
	"""
	print("Read: README.rst")
	with open("README.rst", 'r', encoding='utf8') as fh:
		output = fh.read()

	print("Read: CHANGES.rst")
	with open("CHANGES.rst", 'r', encoding='utf8') as fh:
		output += "\n\n"
		output += fh.read()

	print("Write: README-dist.rst")
	with open("README-dist.rst", 'w', encoding='utf8') as fh:
		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': "attr: pathspec._meta.__version__",
	}
	output['options'] = {
		'packages': "find:",
		'python_requires': config['project']['requires-python'],
		'setup_requires': "setuptools>=40.8.0",
		'test_suite': "tests",
	}
	output['options.packages.find'] = {
		'include': "pathspec, pathspec.*",
	}

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


def main() -> int:
	"""
	Run the script.
	"""
	# Parse command-line arguments.
	parser = argparse.ArgumentParser(description=__doc__)
	parser.parse_args(sys.argv[1:])

	generate_readme_dist()
	generate_setup_cfg()

	return 0


if __name__ == '__main__':
	sys.exit(main())