Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Nov 13, 2022
1 parent bc3fb25 commit 4de7024
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 0.9.10
_commit: 0.10.6
_src_path: gh:pawamoy/copier-pdm
author_email: pawamoy@pm.me
author_fullname: Timothée Mazzucotelli
Expand Down
38 changes: 5 additions & 33 deletions .github/workflows/ci.yml
Expand Up @@ -25,27 +25,13 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up PDM
uses: pdm-project/setup-pdm@v2.6
uses: pdm-project/setup-pdm@v3
with:
python-version: "3.8"

- name: Set cache variables
id: set_variables
run: |
echo "::set-output name=PIP_CACHE::$(pip cache dir)"
echo "::set-output name=PDM_CACHE::$(pdm config cache_dir)"
- name: Set up cache
uses: actions/cache@v2
with:
path: |
${{ steps.set_variables.outputs.PIP_CACHE }}
${{ steps.set_variables.outputs.PDM_CACHE }}
key: checks-cache

- name: Resolving dependencies
run: pdm lock

Expand Down Expand Up @@ -77,33 +63,19 @@ jobs:
- "3.8"
- "3.9"
- "3.10"
- "3.11-dev"
- "3.11"

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

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up PDM
uses: pdm-project/setup-pdm@v2.6
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}

- name: Set cache variables
id: set_variables
run: |
echo "::set-output name=PIP_CACHE::$(pip cache dir)"
echo "::set-output name=PDM_CACHE::$(pdm config cache_dir)"
- name: Set up cache
uses: actions/cache@v2
with:
path: |
${{ steps.set_variables.outputs.PIP_CACHE }}
${{ steps.set_variables.outputs.PDM_CACHE }}
key: tests-cache-${{ runner.os }}-${{ matrix.python-version }}

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

Expand Down
62 changes: 14 additions & 48 deletions duties.py
Expand Up @@ -4,8 +4,6 @@
import os
import re
import sys
import tempfile
from contextlib import suppress
from io import StringIO
from pathlib import Path
from typing import List, Optional, Pattern
Expand Down Expand Up @@ -145,7 +143,8 @@ def check_dependencies(ctx):
importlib.invalidate_caches()

# reload original, unpatched safety
from safety.formatter import report
from safety.formatter import SafetyFormatter
from safety.safety import calculate_remediations
from safety.safety import check as safety_check
from safety.util import read_requirements

Expand All @@ -159,10 +158,19 @@ def check_dependencies(ctx):
# check using safety as a library
def safety(): # noqa: WPS430
packages = list(read_requirements(StringIO(requirements)))
vulns = safety_check(packages=packages, ignore_ids="", key="", db_mirror="", cached=False, proxy={})
output_report = report(vulns=vulns, full=True, checked_packages=len(packages))
vulns, db_full = safety_check(packages=packages, ignore_vulns="")
remediations = calculate_remediations(vulns, db_full)
output_report = SafetyFormatter("text").render_vulnerabilities(
announcements=[],
vulnerabilities=vulns,
remediations=remediations,
full=True,
packages=packages,
)
if vulns:
print(output_report)
return False
return True

ctx.run(safety, title="Checking dependencies")

Expand All @@ -188,49 +196,7 @@ def check_types(ctx): # noqa: WPS231
Arguments:
ctx: The context instance (passed automatically).
"""
# NOTE: the following code works around this issue:
# https://github.com/python/mypy/issues/10633

# compute packages directory path
py = f"{sys.version_info.major}.{sys.version_info.minor}"
pkgs_dir = Path("__pypackages__", py, "lib").resolve()

# build the list of available packages
packages = {}
for package in pkgs_dir.glob("*"):
if package.suffix not in {".dist-info", ".pth"} and package.name != "__pycache__":
packages[package.name] = package

# handle .pth files
for pth in pkgs_dir.glob("*.pth"):
with suppress(OSError):
for package in Path(pth.read_text().splitlines()[0]).glob("*"): # noqa: WPS440
if package.suffix != ".dist-info":
packages[package.name] = package

# create a temporary directory to assign to MYPYPATH
with tempfile.TemporaryDirectory() as tmpdir:

# symlink the stubs
ignore = set()
for stubs in (path for name, path in packages.items() if name.endswith("-stubs")): # noqa: WPS335
Path(tmpdir, stubs.name).symlink_to(stubs, target_is_directory=True)
# try to symlink the corresponding package
# see https://www.python.org/dev/peps/pep-0561/#stub-only-packages
pkg_name = stubs.name.replace("-stubs", "")
if pkg_name in packages:
ignore.add(pkg_name)
Path(tmpdir, pkg_name).symlink_to(packages[pkg_name], target_is_directory=True)

# create temporary mypy config to ignore stubbed packages
newconfig = Path("config", "mypy.ini").read_text()
newconfig += "\n" + "\n\n".join(f"[mypy-{pkg}.*]\nignore_errors=true" for pkg in ignore)
tmpconfig = Path(tmpdir, "mypy.ini")
tmpconfig.write_text(newconfig)

# set MYPYPATH and run mypy
os.environ["MYPYPATH"] = tmpdir
ctx.run(f"mypy --config-file {tmpconfig} {PY_SRC}", title="Type-checking", pty=PTY)
ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY)


@duty(silent=True)
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Expand Up @@ -6,7 +6,7 @@ build-backend = "pdm.pep517.api"
name = "mkdocstrings-python"
description = "A Python handler for mkdocstrings."
authors = [{name = "Timothée Mazzucotelli", email = "pawamoy@pm.me"}]
license-expression = "ISC"
license = "ISC"
readme = "README.md"
requires-python = ">=3.7"
keywords = []
Expand Down Expand Up @@ -73,6 +73,10 @@ maintain = [
"git-changelog>=0.4",
]
quality = [
# TODO: remove once importlib-metadata version conflict is resolved
"importlib-metadata<5; python_version < '3.8'",
"flake8>=4; python_version >= '3.8'",

"darglint>=1.8",
"flake8-bandit>=2.1",
"flake8-black>=0.2",
Expand All @@ -98,7 +102,7 @@ typing = [
"types-markdown>=3.3",
"types-toml>=0.10",
]
security = ["safety>=1.10"]
security = ["safety>=2"]

[tool.black]
line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_credits.py
Expand Up @@ -58,7 +58,7 @@ def get_deps(base_deps):
if dep_name not in deps:
deps[dep_name] = {"license": get_license(dep_name), **parsed, **lock_pkgs[dep_name]}
again = True

return deps

dev_dependencies = get_deps(chain(*pdm.get("dev-dependencies", {}).values()))
Expand Down

0 comments on commit 4de7024

Please sign in to comment.