Skip to content

Commit 596bbbd

Browse files
committed
chore: Template upgrade
1 parent 77283bb commit 596bbbd

32 files changed

+201
-187
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 0.2.2
2+
_commit: 0.4.0
33
_src_path: gh:pawamoy/copier-pdm
44
author_email: pawamoy@pm.me
55
author_fullname: "Timoth\xE9e Mazzucotelli"

.github/workflows/ci.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/checkout@v2
2929

3030
- name: Set up PDM
31-
uses: pdm-project/setup-pdm@v1.1
31+
uses: pdm-project/setup-pdm@v2
3232
with:
3333
python-version: 3.8
3434

@@ -80,7 +80,7 @@ jobs:
8080
uses: actions/checkout@v2
8181

8282
- name: Set up PDM
83-
uses: pdm-project/setup-pdm@v1.1
83+
uses: pdm-project/setup-pdm@v2
8484
with:
8585
python-version: ${{ matrix.python-version }}
8686

@@ -99,9 +99,7 @@ jobs:
9999
key: tests-cache-${{ runner.os }}-${{ matrix.python-version }}
100100

101101
- name: Install dependencies
102-
run: |
103-
pdm use -f ${{ matrix.python-version }}
104-
pdm install -s duty -s tests
102+
run: pdm install -s duty -s tests
105103

106104
- name: Run the test suite
107105
run: pdm run duty test

config/flake8.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
exclude = tests,docs,site
2+
exclude = fixtures,site
33
max-line-length = 132
44
docstring-convention = google
55
ban-relative-imports = true

config/mypy.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
ignore_missing_imports = true
33
exclude = tests/fixtures/
44

5-
[mypy-tests.fixtures.*]
6-
ignore_errors = true
5+
[mypy-toml.*]
6+
ignore_missing_imports = true
7+
8+
[mypy-dataclasses.*]
9+
ignore_missing_imports = true

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--8<-- "CHANGELOG.md"
1+
--8<-- "CHANGELOG.md"

docs/code_of_conduct.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--8<-- "CODE_OF_CONDUCT.md"
1+
--8<-- "CODE_OF_CONDUCT.md"

docs/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--8<-- "CONTRIBUTING.md"
1+
--8<-- "CONTRIBUTING.md"

docs/credits.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/css/mkdocstrings.css

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,3 @@ div.doc-contents:not(.first) {
44
border-left: 4px solid rgba(230, 230, 230);
55
margin-bottom: 80px;
66
}
7-
8-
/* Don't capitalize names. */
9-
h5.doc-heading {
10-
text-transform: none !important;
11-
}
12-
13-
/* Don't use vertical space on hidden ToC entries. */
14-
.hidden-toc::before {
15-
margin-top: 0 !important;
16-
padding-top: 0 !important;
17-
}
18-
19-
/* Don't show permalink of hidden ToC entries. */
20-
.hidden-toc a.headerlink {
21-
display: none;
22-
}
23-
24-
/* Avoid breaking parameters name, etc. in table cells. */
25-
td code {
26-
word-break: normal !important;
27-
}
28-
29-
/* For pieces of Markdown rendered in table cells. */
30-
td p {
31-
margin-top: 0 !important;
32-
margin-bottom: 0 !important;
33-
}

docs/gen_credits.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""Generate the credits page."""
2+
3+
import functools
4+
import re
5+
from itertools import chain
6+
from pathlib import Path
7+
from urllib.request import urlopen
8+
9+
import mkdocs_gen_files
10+
import toml
11+
from jinja2 import StrictUndefined
12+
from jinja2.sandbox import SandboxedEnvironment
13+
14+
15+
def get_credits_data() -> dict:
16+
"""Return data used to generate the credits file.
17+
18+
Returns:
19+
Data required to render the credits template.
20+
"""
21+
project_dir = Path(__file__).parent.parent
22+
metadata = toml.load(project_dir / "pyproject.toml")["project"]
23+
metadata_pdm = toml.load(project_dir / "pyproject.toml")["tool"]["pdm"]
24+
lock_data = toml.load(project_dir / "pdm.lock")
25+
project_name = metadata["name"]
26+
27+
all_dependencies = chain(
28+
metadata.get("dependencies", []),
29+
chain(*metadata.get("optional-dependencies", {}).values()),
30+
chain(*metadata_pdm.get("dev-dependencies", {}).values()),
31+
)
32+
direct_dependencies = {re.sub(r"[^\w-].*$", "", dep) for dep in all_dependencies}
33+
direct_dependencies = {dep.lower() for dep in direct_dependencies}
34+
indirect_dependencies = {pkg["name"].lower() for pkg in lock_data["package"]}
35+
indirect_dependencies -= direct_dependencies
36+
37+
return {
38+
"project_name": project_name,
39+
"direct_dependencies": sorted(direct_dependencies),
40+
"indirect_dependencies": sorted(indirect_dependencies),
41+
"more_credits": "http://pawamoy.github.io/credits/",
42+
}
43+
44+
45+
@functools.lru_cache(maxsize=None)
46+
def get_credits():
47+
"""Return credits as Markdown.
48+
49+
Returns:
50+
The credits page Markdown.
51+
"""
52+
jinja_env = SandboxedEnvironment(undefined=StrictUndefined)
53+
commit = "c78c29caa345b6ace19494a98b1544253cbaf8c1"
54+
template_url = f"https://raw.githubusercontent.com/pawamoy/jinja-templates/{commit}/credits.md"
55+
template_data = get_credits_data()
56+
template_text = urlopen(template_url).read().decode("utf8") # noqa: S310
57+
return jinja_env.from_string(template_text).render(**template_data)
58+
59+
60+
with mkdocs_gen_files.open("credits.md", "w") as fd:
61+
fd.write(get_credits())
62+
mkdocs_gen_files.set_edit_path("credits.md", "gen_credits.py")

0 commit comments

Comments
 (0)