Skip to content

Commit 5a28266

Browse files
committed
generate license list from cargo tree
1 parent bd49fcc commit 5a28266

File tree

3 files changed

+81
-48
lines changed

3 files changed

+81
-48
lines changed

docs/docs/other-licenses.md

+3-48
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,5 @@
11
# Third-party Licenses
22

3-
- [clap](https://crates.io/crates/clap):
4-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
5-
- [git2](https://crates.io/crates/git2):
6-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
7-
8-
The following are conditionally included in binaries (using the `openssl-vendored` feature on a
9-
case-by-case basis) because it is a dependency of git2:
10-
11-
- [openssl](https://crates.io/crates/openssl): Licensed under [Apache 2.0][Apache2]
12-
- [openssl-probe](https://crates.io/crates/openssl-probe):
13-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
14-
15-
- [lenient_semver](https://crates.io/crates/lenient_semver):
16-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
17-
- [log](https://crates.io/crates/log):
18-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
19-
- [regex](https://crates.io/crates/regex):
20-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
21-
- [reqwest](https://crates.io/crates/reqwest):
22-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
23-
- [semver](https://crates.io/crates/semver):
24-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
25-
- [serde](https://crates.io/crates/serde):
26-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
27-
- [serde-xml-rs](https://crates.io/crates/serde-xml-rs): Licensed under [MIT].
28-
- [serde_json](https://crates.io/crates/serde_json):
29-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
30-
- [which](https://crates.io/crates/which): Licensed under [MIT].
31-
- [tokio](https://crates.io/crates/tokio): Licensed under [MIT].
32-
- [futures](https://crates.io/crates/futures):
33-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
34-
- [chrono](https://crates.io/crates/chrono):
35-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
36-
- [colored](https://crates.io/crates/colored): Licensed under [MPL-2.0]
37-
38-
The python binding uses
39-
40-
- [pyo3](https://crates.io/crates/pyo3):
41-
Dual-licensed under [Apache 2.0][Apache2] or [MIT].
42-
43-
The node binding uses
44-
45-
- [napi](https://crates.io/crates/napi): Licensed under [MIT]
46-
- [napi-derive](https://crates.io/crates/napi-derive): Licensed under [MIT]
47-
48-
[MIT]: https://choosealicense.com/licenses/mit
49-
[Apache2]: https://choosealicense.com/licenses/apache-2.0/
50-
[MPL-2.0]: https://choosealicense.com/licenses/mpl-2.0
3+
This page is generated when mkdocs builds.
4+
All content here is overwritten when building the docs.
5+
See [license_gen.py](../license_gen.py) to make changes to this doc.

docs/license_gen.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from pathlib import Path
2+
from typing import Dict, Any
3+
import yaml
4+
import mkdocs_gen_files
5+
from subprocess import run
6+
7+
FILENAME = "other-licenses.md"
8+
9+
INTRO = """# Third-party Licenses
10+
11+
[MIT]: https://choosealicense.com/licenses/mit
12+
[Apache-2.0]: https://choosealicense.com/licenses/apache-2.0/
13+
[MPL-2.0]: https://choosealicense.com/licenses/mpl-2.0
14+
"""
15+
16+
OPTIONAL_DEPS = """## Optional dependencies
17+
18+
The following are conditionally included in binaries (using the `openssl-vendored`
19+
feature on a case-by-case basis) because it is a dependency of
20+
[git2](https://crates.io/crates/git2):
21+
22+
23+
- [openssl](https://crates.io/crates/openssl): Licensed under [Apache-2.0].
24+
- [openssl-probe](https://crates.io/crates/openssl-probe):
25+
Dual-licensed under [Apache-2.0] or [MIT].
26+
"""
27+
28+
BINDING_DEPS = """## Bindings' dependencies
29+
30+
The python binding uses
31+
32+
- [pyo3](https://crates.io/crates/pyo3):
33+
Dual-licensed under [Apache-2.0] or [MIT].
34+
35+
The node binding uses
36+
37+
- [napi](https://crates.io/crates/napi): Licensed under [MIT]
38+
- [napi-derive](https://crates.io/crates/napi-derive): Licensed under [MIT]
39+
"""
40+
41+
with mkdocs_gen_files.open(FILENAME, "w") as io_doc:
42+
options_versions = Path(__file__).parent / "cli.yml"
43+
versions: Dict[str, Any] = yaml.safe_load(options_versions.read_bytes())
44+
45+
print(INTRO, file=io_doc)
46+
output = run(
47+
[
48+
"cargo",
49+
"tree",
50+
"-f",
51+
r"[{p}]({r}): Licensed under {l}",
52+
"-e",
53+
"normal",
54+
"-p",
55+
"cpp-linter",
56+
"--depth",
57+
"1",
58+
],
59+
capture_output=True,
60+
check=True,
61+
)
62+
doc = "\n".join(
63+
[
64+
"- "
65+
+ line[3:]
66+
.replace(" MIT", " [MIT]")
67+
.replace(" Apache-2.0", " [Apache-2.0]")
68+
.replace(" MPL-2.0", " [MPL-2.0]")
69+
for line in output.stdout.decode(encoding="utf-8").splitlines()[1:]
70+
]
71+
)
72+
# print(doc)
73+
print(doc, file=io_doc)
74+
print(f"\n{OPTIONAL_DEPS}\n", file=io_doc)
75+
print(f"\n{BINDING_DEPS}\n", file=io_doc)
76+
77+
mkdocs_gen_files.set_edit_path(FILENAME, "license-gen.py")

docs/mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ plugins:
7979
- gen-files:
8080
scripts:
8181
- gen_cli_doc.py
82+
- license_gen.py
8283

8384
markdown_extensions:
8485
- pymdownx.superfences

0 commit comments

Comments
 (0)