Skip to content

Commit e9c8f59

Browse files
authored
Merge pull request #126 from mkdocstrings/template-upgrade
Template upgrade
2 parents 080079f + de94eef commit e9c8f59

19 files changed

Lines changed: 220 additions & 110 deletions

File tree

.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.4.3
2+
_commit: 0.7.1
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: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
uses: actions/checkout@v2
2929

3030
- name: Set up PDM
31-
uses: pdm-project/setup-pdm@v2
31+
uses: pdm-project/setup-pdm@v2.5
3232
with:
33-
python-version: 3.8
33+
python-version: "3.8"
3434

3535
- name: Set cache variables
3636
id: set_variables
@@ -50,15 +50,13 @@ jobs:
5050
run: pdm lock
5151

5252
- name: Install dependencies
53-
run: |
54-
pdm install -G duty -G docs -G quality -G typing -G numpy-style
55-
pip install safety
53+
run: pdm install -G duty -G docs -G quality -G typing -G security -G numpy-style
5654

5755
- name: Check if the documentation builds correctly
5856
run: pdm run duty check-docs
5957

6058
- name: Check the code quality
61-
run: pdm run duty check-code-quality
59+
run: pdm run duty check-quality
6260

6361
- name: Check if the code is correctly typed
6462
run: pdm run duty check-types
@@ -70,8 +68,17 @@ jobs:
7068

7169
strategy:
7270
matrix:
73-
os: [ubuntu-latest, macos-latest, windows-latest]
74-
python-version: [3.6, 3.7, 3.8, 3.9]
71+
os:
72+
- ubuntu-latest
73+
- macos-latest
74+
- windows-latest
75+
python-version:
76+
- "3.6"
77+
- "3.7"
78+
- "3.8"
79+
- "3.9"
80+
- "3.10"
81+
- "3.11-dev"
7582

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

@@ -80,7 +87,7 @@ jobs:
8087
uses: actions/checkout@v2
8188

8289
- name: Set up PDM
83-
uses: pdm-project/setup-pdm@v2
90+
uses: pdm-project/setup-pdm@v2.5
8491
with:
8592
python-version: ${{ matrix.python-version }}
8693

.gitpod.dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM gitpod/workspace-full
2+
USER gitpod
3+
ENV PIP_USER=no
4+
ENV PYTHON_VERSIONS=
5+
RUN pip3 install pipx; \
6+
pipx install pdm; \
7+
pipx ensurepath

.gitpod.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
vscode:
2+
extensions:
3+
- ms-python.python
4+
5+
image:
6+
file: .gitpod.dockerfile
7+
8+
ports:
9+
- port: 8000
10+
onOpen: notify
11+
12+
tasks:
13+
- init: make setup

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ SHELL := bash
44
DUTY = $(shell [ -n "${VIRTUAL_ENV}" ] || echo pdm run) duty
55

66
args = $(foreach a,$($(subst -,_,$1)_args),$(if $(value $a),$a="$($a)"))
7-
check_code_quality_args = files
7+
check_quality_args = files
88
docs_serve_args = host port
99
release_args = version
1010
test_args = match
1111

1212
BASIC_DUTIES = \
1313
changelog \
14+
check-dependencies \
1415
clean \
1516
coverage \
1617
docs \
@@ -21,9 +22,7 @@ BASIC_DUTIES = \
2122
release
2223

2324
QUALITY_DUTIES = \
24-
check \
25-
check-code-quality \
26-
check-dependencies \
25+
check-quality \
2726
check-docs \
2827
check-types \
2928
test
@@ -32,10 +31,19 @@ QUALITY_DUTIES = \
3231
help:
3332
@$(DUTY) --list
3433

34+
.PHONY: lock
35+
lock:
36+
@pdm lock
37+
3538
.PHONY: setup
3639
setup:
3740
@bash scripts/setup.sh
3841

42+
.PHONY: check
43+
check:
44+
@bash scripts/multirun.sh duty check-quality check-types check-docs
45+
@$(DUTY) check-dependencies
46+
3947
.PHONY: $(BASIC_DUTIES)
4048
$(BASIC_DUTIES):
4149
@$(DUTY) $@ $(call args,$@)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://pawamoy.github.io/pytkdocs/)
55
[![pypi version](https://img.shields.io/pypi/v/pytkdocs.svg)](https://pypi.org/project/pytkdocs/)
66
[![conda version](https://img.shields.io/conda/vn/conda-forge/pytkdocs)](https://anaconda.org/conda-forge/pytkdocs)
7+
[![gitpod](https://img.shields.io/badge/gitpod-workspace-blue.svg?style=flat)](https://gitpod.io/#https://github.com/pawamoy/pytkdocs)
78
[![gitter](https://badges.gitter.im/join%20chat.svg)](https://gitter.im/pytkdocs/community)
89

910
Load Python objects documentation.

config/flake8.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ignore =
1010
D105
1111
# multi-line docstring summary should start at the first line
1212
D212
13+
# does not support Parameters sections
14+
D417
1315
# whitespace before ':' (incompatible with Black)
1416
E203
1517
# redundant with E0602 (undefined variable)

config/mypy.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
[mypy]
22
ignore_missing_imports = true
33
exclude = tests/fixtures/
4-
5-
[mypy-toml.*]
6-
ignore_missing_imports = true
7-
8-
[mypy-dataclasses.*]
9-
ignore_missing_imports = true

duties.py

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Development tasks."""
22

3+
import importlib
34
import os
45
import re
56
import sys
7+
import tempfile
8+
from contextlib import suppress
69
from functools import wraps
10+
from io import StringIO
711
from pathlib import Path
8-
from shutil import which
912
from typing import List, Optional, Pattern
1013
from urllib.request import urlopen
1114

@@ -105,7 +108,7 @@ def changelog(ctx):
105108
)
106109

107110

108-
@duty(pre=["check_code_quality", "check_types", "check_docs", "check_dependencies"])
111+
@duty(pre=["check_quality", "check_types", "check_docs", "check_dependencies"])
109112
def check(ctx):
110113
"""
111114
Check it all!
@@ -116,7 +119,7 @@ def check(ctx):
116119

117120

118121
@duty
119-
def check_code_quality(ctx, files=PY_SRC):
122+
def check_quality(ctx, files=PY_SRC):
120123
"""
121124
Check the code quality.
122125
@@ -141,22 +144,36 @@ def check_dependencies(ctx):
141144
Arguments:
142145
ctx: The context instance (passed automatically).
143146
"""
144-
nofail = False
145-
safety = which("safety")
146-
if not safety:
147-
pipx = which("pipx")
148-
if pipx:
149-
safety = f"{pipx} run safety"
150-
else:
151-
safety = "safety"
152-
nofail = True
153-
ctx.run(
154-
f"pdm export -f requirements --without-hashes | {safety} check --stdin --full-report",
155-
title="Checking dependencies",
156-
pty=PTY,
157-
nofail=nofail,
147+
# undo possible patching
148+
# see https://github.com/pyupio/safety/issues/348
149+
for module in sys.modules: # noqa: WPS528
150+
if module.startswith("safety.") or module == "safety":
151+
del sys.modules[module] # noqa: WPS420
152+
153+
importlib.invalidate_caches()
154+
155+
# reload original, unpatched safety
156+
from safety.formatter import report
157+
from safety.safety import check as safety_check
158+
from safety.util import read_requirements
159+
160+
# retrieve the list of dependencies
161+
requirements = ctx.run(
162+
["pdm", "export", "-f", "requirements", "--without-hashes"],
163+
title="Exporting dependencies as requirements",
164+
allow_overrides=False,
158165
)
159166

167+
# check using safety as a library
168+
def safety(): # noqa: WPS430
169+
packages = list(read_requirements(StringIO(requirements)))
170+
vulns = safety_check(packages=packages, ignore_ids="", key="", db_mirror="", cached=False, proxy={})
171+
output_report = report(vulns=vulns, full=True, checked_packages=len(packages))
172+
if vulns:
173+
print(output_report)
174+
175+
ctx.run(safety, title="Checking dependencies")
176+
160177

161178
def no_docs_py36(nofail=True):
162179
"""
@@ -197,15 +214,57 @@ def check_docs(ctx, strict: bool = False):
197214
ctx.run(f"mkdocs build{' -s' if strict else ''}", title="Building documentation", pty=PTY)
198215

199216

200-
@duty
201-
def check_types(ctx):
217+
@duty # noqa: WPS231
218+
def check_types(ctx): # noqa: WPS231
202219
"""
203220
Check that the code is correctly typed.
204221
205222
Arguments:
206223
ctx: The context instance (passed automatically).
207224
"""
208-
ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY)
225+
# NOTE: the following code works around this issue:
226+
# https://github.com/python/mypy/issues/10633
227+
228+
# compute packages directory path
229+
py = f"{sys.version_info.major}.{sys.version_info.minor}"
230+
pkgs_dir = Path("__pypackages__", py, "lib").resolve()
231+
232+
# build the list of available packages
233+
packages = {}
234+
for package in pkgs_dir.glob("*"):
235+
if package.suffix not in {".dist-info", ".pth"} and package.name != "__pycache__":
236+
packages[package.name] = package
237+
238+
# handle .pth files
239+
for pth in pkgs_dir.glob("*.pth"):
240+
with suppress(OSError):
241+
for package in Path(pth.read_text().splitlines()[0]).glob("*"): # noqa: WPS440
242+
if package.suffix != ".dist-info":
243+
packages[package.name] = package
244+
245+
# create a temporary directory to assign to MYPYPATH
246+
with tempfile.TemporaryDirectory() as tmpdir:
247+
248+
# symlink the stubs
249+
ignore = set()
250+
for stubs in (path for name, path in packages.items() if name.endswith("-stubs")): # noqa: WPS335
251+
Path(tmpdir, stubs.name).symlink_to(stubs, target_is_directory=True)
252+
# try to symlink the corresponding package
253+
# see https://www.python.org/dev/peps/pep-0561/#stub-only-packages
254+
pkg_name = stubs.name.replace("-stubs", "")
255+
if pkg_name in packages:
256+
ignore.add(pkg_name)
257+
Path(tmpdir, pkg_name).symlink_to(packages[pkg_name], target_is_directory=True)
258+
259+
# create temporary mypy config to ignore stubbed packages
260+
newconfig = Path("config", "mypy.ini").read_text()
261+
newconfig += "\n" + "\n\n".join(f"[mypy-{pkg}.*]\nignore_errors=true" for pkg in ignore)
262+
tmpconfig = Path(tmpdir, "mypy.ini")
263+
tmpconfig.write_text(newconfig)
264+
265+
# set MYPYPATH and run mypy
266+
os.environ["MYPYPATH"] = tmpdir
267+
ctx.run(f"mypy --config-file {tmpconfig} {PY_SRC}", title="Type-checking", pty=PTY)
209268

210269

211270
@duty(silent=True)
@@ -301,7 +360,7 @@ def release(ctx, version):
301360
ctx.run("git push --tags", title="Pushing tags", pty=False)
302361
ctx.run("pdm build", title="Building dist/wheel", pty=PTY)
303362
ctx.run("twine upload --skip-existing dist/*", title="Publishing version", pty=PTY)
304-
docs_deploy.run() # type: ignore
363+
docs_deploy.run()
305364

306365

307366
@duty(silent=True)

0 commit comments

Comments
 (0)