8000 chore: Template upgrade · ssbarnea/python@c15a10b · GitHub
[go: up one dir, main page]

Skip to content

Commit c15a10b

Browse files
committed
chore: Template upgrade
1 parent 480d0c3 commit c15a10b

File tree

11 files changed

+143
-92
lines changed

11 files changed

+143
-92
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.9.0
2+
_commit: 0.9.7
33
_src_path: gh:pawamoy/copier-pdm
44
author_email: pawamoy@pm.me
55
author_fullname: Timothée Mazzucotelli

.github/FUNDING.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
github:
2-
- pawamoy
3-
ko_fi: pawamoy
4-
liberapay: pawamoy
5-
patreon: pawamoy
2+
- pawamoy
63
custom:
7-
- https://www.paypal.me/pawamoy
4+
- https://www.paypal.me/pawamoy

.github/workflows/ci.yml

Lines changed: 3 additions & 3 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@v2.5
31+
uses: pdm-project/setup-pdm@v2.6
3232
with:
3333
python-version: "3.8"
3434

@@ -86,7 +86,7 @@ jobs:
8686
uses: actions/checkout@v2
8787

8888
- name: Set up PDM
89-
uses: pdm-project/setup-pdm@v2.5
89+
uses: pdm-project/setup-pdm@v2.6
9090
with:
9191
python-version: ${{ matrix.python-version }}
9292

@@ -105,7 +105,7 @@ jobs:
105105
key: tests-cache-${{ runner.os }}-${{ matrix.python-version }}
106106

107107
- name: Install dependencies
108-
run: pdm install -G duty -G tests
108+
run: pdm install --no-editable -G duty -G tests
109109

110110
- name: Run the test suite
111111
run: pdm run duty test

CONTRIBUTING.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cd python
1414
make setup
1515
```
1616

17-
> NOTE
17+
> NOTE:
1818
> If it fails for some reason,
1919
> you'll need to install
2020
> [PDM](https://github.com/pdm-project/pdm)
@@ -57,17 +57,14 @@ As usual:
5757
1. create a new branch: `git checkout -b feature-or-bugfix-name`
5858
1. edit the code and/or the documentation
5959
60-
If you updated the documentation or the project dependencies:
61-
62-
1. run `make docs-regen`
63-
1. run `make docs-serve`,
64-
go to http://localhost:8000 and check that everything looks good
65-
6660
**Before committing:**
6761
6862
1. run `make format` to auto-format the code
6963
1. run `make check` to check everything (fix any warning)
7064
1. run `make test` to run the tests (fix any issue)
65+
1. if you updated the documentation or the project dependencies:
66+
1. run `make docs-serve`
67+
1. go to http://localhost:8000 and check that everything looks good
7168
1. follow our [commit message convention](#commit-message-convention)
7269
7370
If you are unsure about how to fix or ignore a warning,

docs/credits.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```python exec="yes"
2+
--8<-- "scripts/gen_credits.py"
3+
```

docs/gen_credits.py

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

docs/gen_ref_nav.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66

77
nav = mkdocs_gen_files.Nav()
88

9-
for path in sorted(Path("src").glob("**/*.py")):
9+
for path in sorted(Path("src").rglob("*.py")):
1010
module_path = path.relative_to("src").with_suffix("")
1111
doc_path = path.relative_to("src").with_suffix(".md")
1212
full_doc_path = Path("reference", doc_path)
1313

14-
parts = list(module_path.parts)
14+
parts = tuple(module_path.parts)
15+
1516
if parts[-1] == "__init__":
1617
parts = parts[:-1]
1718
doc_path = doc_path.with_name("index.md")
1819
full_doc_path = full_doc_path.with_name("index.md")
1920
elif parts[-1] == "__main__":
2021
continue
21-
nav_parts = list(parts)
22-
nav[nav_parts] = doc_path
22+
23+
nav[parts] = doc_path.as_posix()
2324

2425
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
2526
ident = ".".join(parts)
26-
print("::: " + ident, file=fd)
27+
fd.write(f"::: {ident}")
2728

2829
mkdocs_gen_files.set_edit_path(full_doc_path, path)
2930

mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ site_url: "https://mkdocstrings.github.io/python"
44
repo_url: "https://github.com/mkdocstrings/python"
55
repo_name: "mkdocstrings/python"
66
site_dir: "site"
7-
watch: [src, README.md]
7+
watch: [README.md, CONTRIBUTING.md, CHANGELOG.md, src/mkdocstrings_handlers]
88

99
nav:
1010
- Home:
@@ -27,6 +27,7 @@ theme:
2727
logo: logo.png
2828
features:
2929
- navigation.tabs
30+
- navigation.tabs.sticky
3031
- navigation.top
3132
palette:
3233
- media: "(prefers-color-scheme: light)"
@@ -65,9 +66,9 @@ markdown_extensions:
6566

6667
plugins:
6768
- search
69+
- markdown-exec
6870
- gen-files:
6971
scripts:
70-
- docs/gen_credits.py
7172
- docs/gen_ref_nav.py
7273
- literate-nav:
7374
nav_file: SUMMARY.md

pyproject.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ build-backend = "pdm.pep517.api"
66
name = "mkdocstrings-python"
77
description = "A Python handler for mkdocstrings."
88
authors = [{name = "Timothée Mazzucotelli", email = "pawamoy@pm.me"}]
9-
license = {file = "LICENSE"}
9+
license-expression = "ISC"
1010
readme = "README.md"
1111
requires-python = ">=3.7"
1212
keywords = []
1313
dynamic = ["version"]
1414
classifiers = [
1515
"Development Status :: 4 - Beta",
1616
"Intended Audience :: Developers",
17-
"License :: OSI Approved :: ISC License (ISCL)",
1817
"Programming Language :: Python",
1918
"Programming Language :: Python :: 3",
2019
"Programming Language :: Python :: 3 :: Only",
@@ -47,18 +46,19 @@ Funding = "https://github.com/sponsors/mkdocstrings"
4746
[tool.pdm]
4847
version = {use_scm = true}
4948
includes = ["src/mkdocstrings_handlers"]
49+
editable-backend = "editables"
5050

5151
[tool.pdm.dev-dependencies]
5252
duty = ["duty>=0.7"]
5353
docs = [
54-
"markdown-callouts>=0.2.0",
55-
"mkdocs>=1.2",
54+
"mkdocs>=1.3",
5655
"mkdocs-coverage>=0.2",
5756
"mkdocs-gen-files>=0.3",
5857
"mkdocs-literate-nav>=0.4",
5958
"mkdocs-material>=7.3",
6059
"mkdocs-section-index>=0.3",
61-
"mkdocstrings>=0.16",
60+
"markdown-callouts>=0.2",
61+
"markdown-exec>=0.5",
6262
"toml>=0.10",
6363
]
6464
format = [
@@ -67,7 +67,6 @@ format = [
6767
"isort>=5.10",
6868
]
6969
maintain = [
70-
# TODO: remove this section when git-changelog is more powerful
7170
"git-changelog>=0.4",
7271
]
7372
quality = [
@@ -89,7 +88,6 @@ tests = [
8988
"pytest>=6.2",
9089
"pytest-cov>=3.0",
9190
"pytest-randomly>=3.10",
92-
"pytest-sugar>=0.9",
9391
"pytest-xdist>=2.4",
9492
]
9593
typing = [

scripts/gen_credits.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import re
2+
from importlib.metadata import metadata, PackageNotFoundError
3+
from itertools import chain
4+
from pathlib import Path
5+
from textwrap import dedent
6+
7+
import toml
8+
from jinja2 import StrictUndefined
9+
from jinja2.sandbox import SandboxedEnvironment
10+
11+
project_dir = Path(".")
12+
pyproject = toml.load(project_dir / "pyproject.toml")
13+
project = pyproject["project"]
14+
pdm = pyproject["tool"]["pdm"]
15+
lock_data = toml.load(project_dir / "pdm.lock")
16+
lock_pkgs = {pkg["name"].lower(): pkg for pkg in lock_data["package"]}
17+
project_name = project["name"]
18+
regex = re.compile(r"(?P<dist>[\w.-]+)(?P<spec>.*)$")
19+
20+
def get_license(pkg_name):
21+
try:
22+
data = metadata(pkg_name)
23+
except PackageNotFoundError:
24+
return "?"
25+
license = data.get("License", "").strip()
26+
multiple_lines = bool(license.count("\n"))
27+
# TODO: remove author logic once all my packages licenses are fixed
28+
author = ""
29+
if multiple_lines or not license or license == "UNKNOWN":
30+
for header, value in data.items():
31+
if header == "Classifier" and value.startswith("License ::"):
32+
license = value.rsplit("::", 1)[1].strip()
33+
elif header == "Author-email":
34+
author = value
35+
if license == "Other/Proprietary License" and "pawamoy" in author:
36+
license = "ISC"
37+
return license or "?"
38+
39+
def get_deps(base_deps):
40+
deps = {}
41+
for dep in base_deps:
42+
parsed = regex.match(dep).groupdict()
43+
dep_name = parsed["dist"].lower()
44+
deps[dep_name] = {"license": get_license(dep_name), **parsed, **lock_pkgs[dep_name]}
45+
46+
again = True
47+
while again:
48+
again = False
49+
for pkg_name in lock_pkgs:
50+
if pkg_name in deps:
51+
for pkg_dependency in lock_pkgs[pkg_name].get("dependencies", []):
52+
parsed = regex.match(pkg_dependency).groupdict()
53+
dep_name = parsed["dist"].lower()
54+
if dep_name not in deps:
55+
deps[dep_name] = {"license": get_license(dep_name), **parsed, **lock_pkgs[dep_name]}
56+
again = True
57+
58+
return deps
59+
60+
dev_dependencies = get_deps(chain(*pdm.get("dev-dependencies", {}).values()))
61+
prod_dependencies = get_deps(
62+
chain(
63+
project.get("dependencies", []),
64+
chain(*project.get("optional-dependencies", {}).values()),
65+
)
66+
)
67+
68+
template_data = {
69+
"project_name": project_name,
70+
"prod_dependencies": sorted(prod_dependencies.values(), key=lambda dep: dep["name"]),
71+
"dev_dependencies": sorted(dev_dependencies.values(), key=lambda dep: dep["name"]),
72+
"more_credits": "http://pawamoy.github.io/credits/",
73+
}
74+
template_text = dedent(
75+
"""
76+
These projects were used to build `{{ project_name }}`. **Thank you!**
77+
78+
[`python`](https://www.python.org/) |
79+
[`pdm`](https://pdm.fming.dev/) |
80+
[`copier-pdm`](https://github.com/pawamoy/copier-pdm)
81+
82+
{% macro dep_line(dep) -%}
83+
[`{{ dep.name }}`](https://pypi.org/project/{{ dep.name }}/) | {{ dep.summary }} | {{ ("`" ~ dep.spec ~ "`") if dep.spec else "" }} | `{{ dep.version }}` | {{ dep.license }}
84+
{%- endmacro %}
85+
86+
### Runtime dependencies
87+
88+
Project | Summary | Version (accepted) | Version (last resolved) | License
89+
------- | ------- | ------------------ | ----------------------- | -------
90+
{% for dep in prod_dependencies -%}
91+
{{ dep_line(dep) }}
92+
{% endfor %}
93+
94+
### Development dependencies
95+
96+
Project | Summary | Version (accepted) | Version (last resolved) | License
97+
------- | ------- | ------------------ | ----------------------- | -------
98+
{% for dep in dev_dependencies -%}
99+
{{ dep_line(dep) }}
100+
{% endfor %}
101+
102+
{% if more_credits %}**[More credits from the author]({{ more_credits }})**{% endif %}
103+
"""
104+
)
105+
jinja_env = SandboxedEnvironment(undefined=StrictUndefined)
106+
print(jinja_env.from_string(template_text).render(**template_data))

scripts/setup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ install_with_pipx() {
1414

1515
install_with_pipx pdm
1616

17+
restore_previous_python_version() {
18+
if pdm use -f "$1" &>/dev/null; then
19+
echo "> Restored previous Python version: ${1##*/}"
20+
fi
21+
}
22+
1723
if [ -n "${PYTHON_VERSIONS}" ]; then
24+
if old_python_version="$(pdm config python.path 2>/dev/null)"; then
25+
echo "> Currently selected Python version: ${old_python_version##*/}"
26+
trap "restore_previous_python_version ${old_python_version}" EXIT
27+
fi
1828
for python_version in ${PYTHON_VERSIONS}; do
1929
if pdm use -f "python${python_version}" &>/dev/null; then
2030
echo "> Using Python ${python_version} interpreter"

0 commit comments

Comments
 (0)
0