Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jun 8, 2023
1 parent 3dd47c2 commit 92e0238
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 0.15.2
_commit: 0.15.11
_src_path: gh:pawamoy/copier-pdm
author_email: [email protected]
author_fullname: Timothée Mazzucotelli
Expand Down
31 changes: 27 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
python-version: "3.8"

- name: Resolving dependencies
run: pdm lock -v -G:all
run: pdm lock -v --no-cross-platform -G ci-quality

- name: Install dependencies
run: pdm install -G:all
run: pdm install -G ci-quality

- name: Check if the documentation builds correctly
run: pdm run duty check-docs
Expand All @@ -56,9 +56,31 @@ jobs:
- name: Check for breaking changes in the API
run: pdm run duty check-api

exclude-test-jobs:
runs-on: ubuntu-latest
outputs:
jobs: ${{ steps.exclude-jobs.outputs.jobs }}
steps:
- id: exclude-jobs
run: |
if ${{ github.repository_owner == 'pawamoy-insiders' }}; then
echo 'jobs=[
{"os": "macos-latest"},
{"os": "windows-latest"},
{"python-version": "3.8"},
{"python-version": "3.9"},
{"python-version": "3.10"},
{"python-version": "3.11"}
]' | tr -d '[:space:]' >> $GITHUB_OUTPUT
else
echo 'jobs=[]' >> $GITHUB_OUTPUT
fi
tests:

needs: exclude-test-jobs
strategy:
max-parallel: 4
matrix:
os:
- ubuntu-latest
Expand All @@ -70,6 +92,7 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
exclude: ${{ fromJSON(needs.exclude-test-jobs.outputs.jobs) }}

runs-on: ${{ matrix.os }}

Expand All @@ -83,10 +106,10 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Resolving dependencies
run: pdm lock -v
run: pdm lock -v --no-cross-platform -G ci-tests

- name: Install dependencies
run: pdm install --no-editable -G duty -G tests
run: pdm install --no-editable -G ci-tests

- name: Run the test suite
run: pdm run duty test
2 changes: 2 additions & 0 deletions .github/workflows/dists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v3
- name: Install build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pip-wheel-metadata/
site/
pdm.lock
pdm.toml
.pdm-plugins/
.pdm-python
__pypackages__/
.venv/
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.DEFAULT_GOAL := help
SHELL := bash

DUTY = $(shell [ -n "${VIRTUAL_ENV}" ] || echo pdm run) duty
DUTY := $(if $(VIRTUAL_ENV),,pdm run) duty

args = $(foreach a,$($(subst -,_,$1)_args),$(if $(value $a),$a="$($a)"))
check_quality_args = files
Expand Down Expand Up @@ -32,7 +31,7 @@ help:

.PHONY: lock
lock:
@pdm lock
@pdm lock -G:all

.PHONY: setup
setup:
Expand Down
4 changes: 2 additions & 2 deletions docs/.overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
is now available!
<span class="twemoji heart pulse">
{% include ".icons/octicons/heart-fill-16.svg" %}
</span>
</span> &mdash;

&mdash; For updates follow <strong>@pawamoy</strong> on
For updates follow <strong>@pawamoy</strong> on
<a rel="me" href="https://fosstodon.org/@pawamoy">
<span class="twemoji mastodon">
{% include ".icons/fontawesome/brands/mastodon.svg" %}
Expand Down
23 changes: 23 additions & 0 deletions docs/css/insiders.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,27 @@ a.insiders {
transition: all .25s;
vertical-align: bottom !important;
width: 1.2rem;
}

.premium-sponsors {
text-align: center;
}

.premium-sponsors .silver img {
height: 140px;
}

.premium-sponsors .bronze img {
height: 140px;
}

.premium-sponsors .bronze p {
display: flex;
flex-wrap: wrap;
justify-content: center;
}

.premium-sponsors .bronze a {
display: block;
flex-shrink: 0;
}
21 changes: 21 additions & 0 deletions docs/css/mkdocstrings.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,24 @@ div.doc-contents:not(.first) {
padding-left: 25px;
border-left: .05rem solid var(--md-typeset-table-color);
}

/* Mark external links as such. */
a.external::after,
a.autorefs-external::after {
/* https://primer.style/octicons/arrow-up-right-24 */
mask-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.25 15.5a.75.75 0 00.75-.75v-9a.75.75 0 00-.75-.75h-9a.75.75 0 000 1.5h7.19L6.22 16.72a.75.75 0 101.06 1.06L17.5 7.56v7.19c0 .414.336.75.75.75z"></path></svg>');
content: ' ';

display: inline-block;
vertical-align: middle;
position: relative;

height: 1em;
width: 1em;
background-color: var(--md-typeset-a-color);
}

a.external:hover::after,
a.autorefs-external:hover::after {
background-color: var(--md-accent-fg-color);
}
20 changes: 19 additions & 1 deletion docs/insiders/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,33 @@ You can cancel your sponsorship anytime.[^5]
print_join_sponsors_button()
```

<hr>
<div class="premium-sponsors">

<div class="bronze">
<b>Bronze sponsors</b>
<p>

<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" title="Material for MkDocs">
<img alt="Material for MkDocs" src="https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/.github/assets/logo.svg" style="height: 240px;">
</a>
<a href="https://docs.pydantic.dev/latest/" target="_blank" title="Pydantic">
<img alt="Pydantic" src="https://github.com/pawamoy/website/assets/3999221/368ff871-8fae-40c4-9b66-781b66e12cbb" style="height: 100px;">
</a>

</p>
</div>
</div>

<hr>
<br>

```python exec="1" session="insiders"
print_sponsors()
```

<br><br>
<br>
<br>

<small>
If you sponsor publicly, you're automatically added here with a link to
Expand Down
2 changes: 2 additions & 0 deletions docs/license.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# License

```
--8<-- "LICENSE"
```
24 changes: 23 additions & 1 deletion duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import sys
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from duty import duty
from duty.callables import black, blacken_docs, coverage, lazy, mkdocs, mypy, pytest, ruff, safety
Expand Down Expand Up @@ -35,7 +35,29 @@ def pyprefix(title: str) -> str: # noqa: D103
return title


def merge(d1: Any, d2: Any) -> Any: # noqa: D103
basic_types = (int, float, str, bool, complex)
if isinstance(d1, dict) and isinstance(d2, dict):
for key, value in d2.items():
if key in d1:
if isinstance(d1[key], basic_types):
d1[key] = value
else:
d1[key] = merge(d1[key], value)
else:
d1[key] = value
return d1
if isinstance(d1, list) and isinstance(d2, list):
return d1 + d2
return d2


def mkdocs_config() -> str: # noqa: D103
from mkdocs import utils

# patch YAML loader to merge arrays
utils.merge = merge

if "+insiders" in pkgversion("mkdocs-material"):
return "mkdocs.insiders.yml"
return "mkdocs.yml"
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.insiders.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INHERIT: mkdocs.yml

plugins:
typeset: {}
- typeset
16 changes: 8 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ markdown_extensions:
permalink: "¤"

plugins:
search: {}
markdown-exec: {}
gen-files:
- search
- markdown-exec
- gen-files:
scripts:
- scripts/gen_ref_nav.py
literate-nav:
- literate-nav:
nav_file: SUMMARY.txt
coverage: {}
mkdocstrings:
- coverage
- mkdocstrings:
handlers:
python:
import:
Expand All @@ -127,10 +127,10 @@ plugins:
merge_init_into_class: true
docstring_options:
ignore_init_summary: true
git-committers:
- git-committers:
enabled: !ENV [DEPLOY, false]
repository: pawamoy/markdown-exec
minify:
- minify:
minify_html: !ENV [DEPLOY, false]

extra:
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ markdown-exec = "markdown_exec.mkdocs_plugin:MarkdownExecPlugin"

[tool.pdm]
version = {source = "scm"}
plugins = [
"pdm-multirun",
]

[tool.pdm.build]
package-dir = "src"
editable-backend = "editables"

[tool.pdm.dev-dependencies]
duty = ["duty>=0.10"]
ci-quality = ["markdown-exec[duty,docs,quality,typing,security]"]
ci-tests = ["markdown-exec[duty,tests]"]
docs = [
"black>=23.1; python_version >= '3.8' and python_version < '3.11'",
"markdown-callouts>=0.2; python_version >= '3.8' and python_version < '3.11'",
Expand Down Expand Up @@ -100,4 +105,6 @@ typing = [
"types-pyyaml>=6.0",
"types-toml>=0.10",
]
security = ["safety>=2"]
security = [
"safety>=2",
]
2 changes: 2 additions & 0 deletions scripts/gen_credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def _render_credits() -> str:
}
template_text = dedent(
"""
# Credits
These projects were used to build *{{ project_name }}*. **Thank you!**
[`python`](https://www.python.org/) |
Expand Down
6 changes: 4 additions & 2 deletions scripts/gen_ref_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mkdocs_gen_files

nav = mkdocs_gen_files.Nav()
mod_symbol = '<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code>'

for path in sorted(Path("src").rglob("*.py")):
module_path = path.relative_to("src").with_suffix("")
Expand All @@ -20,13 +21,14 @@
elif parts[-1].startswith("_"):
continue

nav[parts] = doc_path.as_posix()
nav_parts = [f"{mod_symbol} {part}" for part in parts]
nav[tuple(nav_parts)] = doc_path.as_posix()

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(parts)
fd.write(f"::: {ident}")

mkdocs_gen_files.set_edit_path(full_doc_path, path)
mkdocs_gen_files.set_edit_path(full_doc_path, ".." / path)

with mkdocs_gen_files.open("reference/SUMMARY.txt", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
Loading

0 comments on commit 92e0238

Please sign in to comment.