Skip to content

Commit 41b0900

Browse files
authored
Publish reports by including analysis snippets (#13)
* Publish reports by including analysis snippets * Reformat with pre-commit
1 parent d38e363 commit 41b0900

16 files changed

+751
-616
lines changed

devstats/__main__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import requests
99

1010
from .query import GithubGrabber
11-
from .publish import publisher
11+
from .publish import publish
1212

1313

1414
@click.group()
@@ -62,8 +62,4 @@ def query(repo_owner, repo_name):
6262
data.dump(f"{repo_name}_{ftype.get(qtype, qtype)}.json")
6363

6464

65-
@cli.command("publish")
66-
@click.argument("project")
67-
def publish(project):
68-
"""Generate myst report for `repo_owner`/`repo_name`."""
69-
publisher(project)
65+
cli.add_command(publish)

devstats/publish.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import os
22
import sys
33
from glob import glob
4+
import click
45

56

6-
def publisher(project):
7-
os.makedirs("_generated", exist_ok=True)
7+
@click.command()
8+
@click.argument("project")
9+
@click.option(
10+
"-o", "--outdir", default="build", help="Output directory", show_default=True
11+
)
12+
def publish(project, outdir):
13+
"""Generate myst report for `repo_owner`/`repo_name`."""
14+
os.makedirs(outdir, exist_ok=True)
15+
os.makedirs(os.path.join(outdir, project), exist_ok=True)
16+
817
report_files = glob(os.path.join(os.path.dirname(__file__), "reports/*.md"))
918

19+
variables = {"project": project}
20+
21+
print(f"Generating [{project}] report in [{outdir}]...", end="", flush=True)
22+
1023
for report in report_files:
11-
print(f"Generating {project} report...", end="")
1224
with open(report) as fh:
1325
template = fh.read()
14-
with open(f"_generated/{project}.md", "w") as fh:
15-
fh.write(template.replace("{{ project }}", project))
16-
print("OK")
26+
with open(f"{outdir}/{project}/{os.path.basename(report)}", "w") as fh:
27+
for v in variables:
28+
template = template.replace("{{ " + v + " }}", variables[v])
29+
fh.write(template)
30+
31+
print("OK")

0 commit comments

Comments
 (0)