Skip to content

Commit 999088d

Browse files
authored
docs: render licenses of deps in tables (#91)
Also generates tables for the dependencies of the bindings using the `cargo tree` command. typos in bindings/node/README
1 parent 23c30d9 commit 999088d

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

bindings/node/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ This script runs a simple test to ensure the native module was built correctly.
5353
| Name | Description |
5454
|-----:|:------------|
5555
| `__test__` | The location of the unit test(s). |
56-
| `npm` | The required metadata for publishing platform-specific packages to npm. |
56+
| `npm` | The required metadata for publishing platform-specific binary packages to npm. |
5757
| `src` | The location for all rust sources related to binding the cpp-linter library. |
5858
| `build.rs` | The cargo-specific build script used when compiling the binding. |
5959
| `Cargo.toml` | Metadata about the binding's rust package (which _is not_ intended to be published to crates.io). |
60-
| `package.json` | Metadata about the npm package (platform agnostic). |
60+
| `package.json` | Metadata about the npm package (platform agnostic - no binary). |
6161
| `cli.js` | The executable script invoked as a Command Line Interface. |
62-
| `index.d.ts` | The generated TypeScript typing info the describes the exposing functionality in the built native module. |
63-
| `index.js` | The generated script that delegates which platform-specific package to import. |
64-
| `cpp-linter.x-y-z.node` | Then native module built for a specific platform (where `x-y-z` denotes the platform's name using compilation target). |
62+
| `index.d.ts` | The generated TypeScript typing and doc info that describes the exposed API in the built native module. |
63+
| `index.js` | The generated script that delegates which native binary (platform-specific package or dev build) to import. |
64+
| `cpp-linter.x-y-z.node` | The native module built for a specific platform (where `x-y-z` denotes the platform's name using the compilation target). |
6565

6666
Hidden files and folders are not described in the table above.
6767
If they are not ignored by a gitignore specification, then they should be considered

docs/license_gen.py

+56-31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import mkdocs_gen_files
23
from subprocess import run
34

@@ -10,61 +11,85 @@
1011
[MPL-2.0]: https://choosealicense.com/licenses/mpl-2.0
1112
"""
1213

13-
OPTIONAL_DEPS = """## Optional dependencies
14+
TABLE_HEADER = "| Dependency | License |\n|:------------|:-------|\n"
15+
16+
OPTIONAL_DEPS = f"""## Optional dependencies
1417
1518
The following are conditionally included in binaries (using the `openssl-vendored`
1619
feature on a case-by-case basis) because it is a dependency of
1720
[git2](https://crates.io/crates/git2):
1821
19-
- [openssl](https://crates.io/crates/openssl): Licensed under [Apache-2.0].
20-
- [openssl-probe](https://crates.io/crates/openssl-probe):
21-
Dual-licensed under [Apache-2.0] or [MIT].
22+
{TABLE_HEADER}\
23+
| [openssl](https://crates.io/crates/openssl) | [Apache-2.0] |
24+
| [openssl-probe](https://crates.io/crates/openssl-probe) | [MIT] OR [Apache-2.0] |
2225
"""
2326

24-
BINDING_DEPS = """## Bindings' dependencies
27+
PY_BINDING_HEADER = f"""## Bindings' dependencies
2528
26-
The python binding uses
29+
### Python binding
2730
28-
- [pyo3](https://crates.io/crates/pyo3):
29-
Dual-licensed under [Apache-2.0] or [MIT].
31+
{TABLE_HEADER}"""
3032

31-
The node binding uses
33+
JS_BINDING_HEADER = f"""### Node.js binding
3234
33-
- [napi](https://crates.io/crates/napi): Licensed under [MIT]
34-
- [napi-derive](https://crates.io/crates/napi-derive): Licensed under [MIT]
35-
"""
35+
{TABLE_HEADER}"""
3636

37-
with mkdocs_gen_files.open(FILENAME, "w") as io_doc:
38-
print(INTRO, file=io_doc)
39-
output = run(
40-
[
37+
SELF_DEP = re.compile(r"(\| \[cpp-linter v[0-9.]+[^\s]*)[^\]]+(\]\(.*)$")
38+
39+
40+
class TreeGetter:
41+
def __init__(self):
42+
self.args = [
4143
"cargo",
4244
"tree",
4345
"-f",
44-
r"[{p}]({r}): Licensed under {l}",
46+
r"| [{p}]({r}) | {l} |",
4547
"-e",
4648
"normal",
4749
"-p",
4850
"cpp-linter",
4951
"--depth",
5052
"1",
51-
],
52-
capture_output=True,
53-
check=True,
54-
)
55-
doc = "\n".join(
56-
[
57-
"- "
58-
+ line[3:]
59-
.replace(" MIT", " [MIT]")
60-
.replace(" Apache-2.0", " [Apache-2.0]")
61-
.replace(" MPL-2.0", " [MPL-2.0]")
62-
for line in output.stdout.decode(encoding="utf-8").splitlines()[1:]
6353
]
64-
)
54+
55+
def package(self, value: str) -> None:
56+
self.args[7] = value
57+
58+
def get_output(self) -> str:
59+
output = run(
60+
self.args,
61+
capture_output=True,
62+
check=True,
63+
)
64+
result = []
65+
for line in output.stdout.decode(encoding="utf-8").splitlines()[1:]:
66+
dep = (
67+
line[3:]
68+
.replace(" MIT", " [MIT]")
69+
.replace(" Apache-2.0", " [Apache-2.0]")
70+
.replace(" MPL-2.0", " [MPL-2.0]")
71+
.strip()
72+
)
73+
self_match = SELF_DEP.match(dep)
74+
if self_match is not None:
75+
dep = SELF_DEP.sub(r"\1\2", dep)
76+
result.append(dep)
77+
return "\n".join(result)
78+
79+
80+
with mkdocs_gen_files.open(FILENAME, "w") as io_doc:
81+
tg = TreeGetter()
82+
print(INTRO, file=io_doc)
83+
doc = TABLE_HEADER
84+
doc += tg.get_output()
6585
# print(doc)
6686
print(doc, file=io_doc)
6787
print(f"\n{OPTIONAL_DEPS}\n", file=io_doc)
68-
print(f"\n{BINDING_DEPS}\n", file=io_doc)
88+
tg.package("cpp-linter-py")
89+
doc = tg.get_output()
90+
print(f"\n{PY_BINDING_HEADER}{doc}", file=io_doc)
91+
tg.package("cpp-linter-js")
92+
doc = tg.get_output()
93+
print(f"\n{JS_BINDING_HEADER}{doc}", file=io_doc)
6994

7095
mkdocs_gen_files.set_edit_path(FILENAME, "license-gen.py")

0 commit comments

Comments
 (0)