-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·75 lines (56 loc) · 2.35 KB
/
manage.py
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
#!/usr/bin/env python
import os.path
import re
import sys
from glob import glob
from pathlib import Path
from textwrap import dedent
import click
from ocdsextensionregistry import build_profile
basedir = Path(__file__).resolve().parent
sys.path.append(str(basedir / "docs"))
@click.group()
def cli():
pass
@cli.command()
def update():
"""
Update the profile to the latest versions of extensions. If conf.py sets managed_codelist to True, regenerate
docs/reference/codelists.md to list all codelists from OCDS and extensions.
"""
import conf
path_prefix = conf.html_theme_options["root_url"]
ref = conf.release.replace("-", "__").replace(".", "__")
schema_base_url = f"https://standard.open-contracting.org{path_prefix}/schema/{ref}/"
build_profile(basedir / "schema", conf.standard_tag, conf.extension_versions, schema_base_url=schema_base_url)
if not getattr(conf, "managed_codelist", False):
return
file = basedir / "docs" / "reference" / "codelists.md"
with file.open("w+") as f:
filenames = glob(str(basedir / "schema" / "patched" / "codelists" / "*.csv"))
codelists = [os.path.basename(filename) for filename in filenames]
f.write(
dedent(
f"""\
# Codelists
<!-- Do not edit this file. This file is managed by manage.py -->
For more information on codelists, refer to the [codelists reference](https://standard.open-contracting.org/1.1/en/schema/codelists/) in the OCDS documentation.
The codelists below are from the OCDS and its extensions, and are provided here for convenience only.
The codelists can be downloaded as CSV files from <https://standard.open-contracting.org/profiles/{conf.profile_identifier}/latest/en/_static/patched/codelists/>.
""" # noqa: E501
)
)
for filename in sorted(codelists):
heading = re.sub(r"(?<=[a-z])(?=[A-Z])", " ", filename.replace(".csv", "")).title()
f.write(f"\n## {heading}\n\n")
f.write(
dedent(f"""\
```{{csv-table-no-translate}}
:header-rows: 1
:class: codelist-table
:file: ../_static/patched/codelists/{filename}
```
""")
)
if __name__ == "__main__":
cli()