-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprebuild.py
More file actions
71 lines (55 loc) · 1.85 KB
/
prebuild.py
File metadata and controls
71 lines (55 loc) · 1.85 KB
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
"""
This script generates files required for source and wheel distributions.
"""
import argparse
import sys
def generate_readme() -> None:
"""
Generate the "README.rst" file from "README.rst.in".
"""
print("Read: README.rst.in")
with open("README.rst.in", 'r', encoding='utf8') as fh:
readme = fh.read()
for old, new in [
(":class:`dict`", "*dict*"),
(":class:`tuple`", "*tuple*"),
(":class:`.SQLParams`", "`SQLParams`_"),
(":meth:`.SQLParams.format`", "`SQLParams.format`_"),
(":meth:`.SQLParams.formatmany`", "`SQLParams.formatmany`_"),
(":mod:`sqlparams`", "*sqlparams*"),
]:
readme = readme.replace(old, new)
readme += "\n"
readme += ".. _`SQLParams`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams\n"
readme += ".. _`SQLParams.format`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams.format\n"
readme += ".. _`SQLParams.formatmany`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams.formatmany\n"
print("Write: README.rst")
with open("README.rst", 'w', encoding='UTF-8') as fh:
fh.write(readme)
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 main() -> int:
"""
Run the script.
"""
# Parse command-line arguments.
parser = argparse.ArgumentParser(description=__doc__)
parser.parse_args(sys.argv[1:])
generate_readme()
generate_readme_dist()
return 0
if __name__ == '__main__':
sys.exit(main())