Skip to content

docs: render licenses of deps in tables #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 56 additions & 31 deletions docs/license_gen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import mkdocs_gen_files
from subprocess import run

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

OPTIONAL_DEPS = """## Optional dependencies
TABLE_HEADER = "| Dependency | License |\n|:------------|:-------|\n"

OPTIONAL_DEPS = f"""## Optional dependencies

The following are conditionally included in binaries (using the `openssl-vendored`
feature on a case-by-case basis) because it is a dependency of
[git2](https://crates.io/crates/git2):

- [openssl](https://crates.io/crates/openssl): Licensed under [Apache-2.0].
- [openssl-probe](https://crates.io/crates/openssl-probe):
Dual-licensed under [Apache-2.0] or [MIT].
{TABLE_HEADER}\
| [openssl](https://crates.io/crates/openssl) | [Apache-2.0] |
| [openssl-probe](https://crates.io/crates/openssl-probe) | [MIT] OR [Apache-2.0] |
"""

BINDING_DEPS = """## Bindings' dependencies
PY_BINDING_HEADER = f"""## Bindings' dependencies

The python binding uses
### Python binding

- [pyo3](https://crates.io/crates/pyo3):
Dual-licensed under [Apache-2.0] or [MIT].
{TABLE_HEADER}"""

The node binding uses
JS_BINDING_HEADER = f"""### Node.js binding

- [napi](https://crates.io/crates/napi): Licensed under [MIT]
- [napi-derive](https://crates.io/crates/napi-derive): Licensed under [MIT]
"""
{TABLE_HEADER}"""

with mkdocs_gen_files.open(FILENAME, "w") as io_doc:
print(INTRO, file=io_doc)
output = run(
[
SELF_DEP = re.compile(r"(\| \[cpp-linter v[0-9.]+[^\s]*)[^\]]+(\]\(.*)$")


class TreeGetter:
def __init__(self):
self.args = [
"cargo",
"tree",
"-f",
r"[{p}]({r}): Licensed under {l}",
r"| [{p}]({r}) | {l} |",
"-e",
"normal",
"-p",
"cpp-linter",
"--depth",
"1",
],
capture_output=True,
check=True,
)
doc = "\n".join(
[
"- "
+ line[3:]
.replace(" MIT", " [MIT]")
.replace(" Apache-2.0", " [Apache-2.0]")
.replace(" MPL-2.0", " [MPL-2.0]")
for line in output.stdout.decode(encoding="utf-8").splitlines()[1:]
]
)

def package(self, value: str) -> None:
self.args[7] = value

def get_output(self) -> str:
output = run(
self.args,
capture_output=True,
check=True,
)
result = []
for line in output.stdout.decode(encoding="utf-8").splitlines()[1:]:
dep = (
line[3:]
.replace(" MIT", " [MIT]")
.replace(" Apache-2.0", " [Apache-2.0]")
.replace(" MPL-2.0", " [MPL-2.0]")
.strip()
)
self_match = SELF_DEP.match(dep)
if self_match is not None:
dep = SELF_DEP.sub(r"\1\2", dep)
result.append(dep)
return "\n".join(result)


with mkdocs_gen_files.open(FILENAME, "w") as io_doc:
tg = TreeGetter()
print(INTRO, file=io_doc)
doc = TABLE_HEADER
doc += tg.get_output()
# print(doc)
print(doc, file=io_doc)
print(f"\n{OPTIONAL_DEPS}\n", file=io_doc)
print(f"\n{BINDING_DEPS}\n", file=io_doc)
tg.package("cpp-linter-py")
doc = tg.get_output()
print(f"\n{PY_BINDING_HEADER}{doc}", file=io_doc)
tg.package("cpp-linter-js")
doc = tg.get_output()
print(f"\n{JS_BINDING_HEADER}{doc}", file=io_doc)

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