Skip to content

Commit 747d554

Browse files
committed
chore: Switch to PDM
1 parent 31e8756 commit 747d554

14 files changed

Lines changed: 212 additions & 245 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: e9e472d
2+
_commit: 0.2.2
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: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ env:
1717
LC_ALL: en_US.utf-8
1818
PYTHONIOENCODING: UTF-8
1919

20-
# To fix an error when running Poetry on Windows
21-
# (https://github.com/python-poetry/poetry/issues/2629),
22-
# we set Poetry's cache directory to .poetry_cache in the current directory.
23-
# It makes it easier to later remove the virtualenv when it's broken.
24-
# Absolute path is necessary to avoid this issue:
25-
# https://github.com/python-poetry/poetry/issues/3049
26-
POETRY_CACHE_DIR: ${{ github.workspace }}/.poetry_cache
27-
2820
jobs:
2921

3022
quality:
@@ -35,36 +27,44 @@ jobs:
3527
- name: Checkout
3628
uses: actions/checkout@v2
3729

38-
- name: Set up Python
39-
uses: actions/setup-python@v2
30+
- name: Set up PDM
31+
uses: pdm-project/setup-pdm@v1.1
4032
with:
4133
python-version: 3.8
4234

43-
- name: Set up Poetry
44-
run: pip install poetry
35+
- name: Set cache variables
36+
id: set_variables
37+
run: |
38+
echo "::set-output name=PIP_CACHE::$(pip cache dir)"
39+
echo "::set-output name=PDM_CACHE::$(pdm config cache_dir)"
4540
46-
- name: Set up the cache
47-
uses: actions/cache@v1
41+
- name: Set up cache
42+
uses: actions/cache@v2
4843
with:
49-
path: .poetry_cache
50-
key: quality-poetry-cache
44+
path: |
45+
${{ steps.set_variables.outputs.PIP_CACHE }}
46+
${{ steps.set_variables.outputs.PDM_CACHE }}
47+
key: checks-cache
48+
49+
- name: Resolving dependencies
50+
run: pdm lock
5151

52-
- name: Set up the project
53-
run: poetry install -vv -E numpy-style
52+
- name: Install dependencies
53+
run: |
54+
pdm install -s duty -s docs -s quality -s typing
55+
pip install safety
5456
5557
- name: Check if the documentation builds correctly
56-
run: poetry run duty check-docs
58+
run: pdm run duty check-docs
5759

5860
- name: Check the code quality
59-
run: poetry run duty check-code-quality
61+
run: pdm run duty check-code-quality
6062

6163
- name: Check if the code is correctly typed
62-
run: poetry run duty check-types
64+
run: pdm run duty check-types
6365

6466
- name: Check for vulnerabilities in dependencies
65-
run: |
66-
pip install safety
67-
poetry run duty check-dependencies
67+
run: pdm run duty check-dependencies
6868

6969
tests:
7070

@@ -77,24 +77,31 @@ jobs:
7777

7878
steps:
7979
- name: Checkout
80-
uses: actions/checkout@v2
80+
uses: actions/checkout@v2
8181

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

87-
- name: Set up Poetry
88-
run: pip install poetry
87+
- name: Set cache variables
88+
id: set_variables
89+
run: |
90+
echo "::set-output name=PIP_CACHE::$(pip cache dir)"
91+
echo "::set-output name=PDM_CACHE::$(pdm config cache_dir)"
8992
90-
- name: Set up the cache
91-
uses: actions/cache@v1
93+
- name: Set up cache
94+
uses: actions/cache@v2
9295
with:
93-
path: .poetry_cache
94-
key: tests-poetry-cache-${{ matrix.os }}-py${{ matrix.python-version }}
96+
path: |
97+
${{ steps.set_variables.outputs.PIP_CACHE }}
98+
${{ steps.set_variables.outputs.PDM_CACHE }}
99+
key: tests-cache-${{ runner.os }}-${{ matrix.python-version }}
95100

96-
- name: Set up the project
97-
run: poetry install -vv -E numpy-style || { rm -rf .poetry_cache/virtualenvs/*; poetry install -vv -E numpy-style; }
101+
- name: Install dependencies
102+
run: |
103+
pdm use -f ${{ matrix.python-version }}
104+
pdm install -s duty -s tests
98105
99106
- name: Run the test suite
100-
run: poetry run duty test
107+
run: pdm run duty test

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ __pycache__/
44
dist/
55
*.egg-info/
66
build/
7+
htmlcov/
78
.coverage*
89
pip-wheel-metadata/
910
.pytest_cache/
10-
input.json
11-
poetry.lock
1211
.mypy_cache/
13-
.tox/
1412
site/
13+
pdm.lock
14+
.pdm.toml
15+
__pypackages__/
1516
.venv/

CONTRIBUTING.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ make setup
1717
!!! note
1818
If it fails for some reason,
1919
you'll need to install
20-
[Poetry](https://github.com/python-poetry/poetry)
20+
[PDM](https://github.com/pdm-project/pdm)
2121
manually.
2222

2323
You can install it with:
2424

2525
```bash
2626
python3 -m pip install --user pipx
27-
pipx install poetry
27+
pipx install pdm
2828
```
2929

3030
Now you can try running `make setup` again,
31-
or simply `poetry install -E numpy-style`.
31+
or simply `pdm install`.
3232

3333
You now have the dependencies installed.
3434

35-
You can run the application with `poetry run pytkdocs [ARGS...]`.
35+
You can run the application with `pdm run pytkdocs [ARGS...]`.
3636

3737
Run `make help` to see all the available actions!
3838

@@ -45,11 +45,9 @@ on multiple Python versions, you can do one of the following:
4545

4646
1. `export PYTHON_VERSIONS= `: this will run the task
4747
with only the current Python version
48-
2. run the task directly with `poetry run duty TASK`,
49-
or `duty TASK` if the environment was already activated
50-
through `poetry shell`
48+
2. run the task directly with `pdm run duty TASK`
5149

52-
The Makefile detects if the Poetry environment is activated,
50+
The Makefile detects if a virtual environment is activated,
5351
so `make` will work the same with the virtualenv activated or not.
5452

5553
## Development

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.DEFAULT_GOAL := help
22
SHELL := bash
33

4-
DUTY = $(shell [ -n "${VIRTUAL_ENV}" ] || echo poetry run) duty
4+
DUTY = $(shell [ -n "${VIRTUAL_ENV}" ] || echo pdm run) duty
55

66
args = $(foreach a,$($(subst -,_,$1)_args),$(if $(value $a),$a="$($a)"))
77
check_code_quality_args = files

config/coverage.ini

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
[coverage:paths]
2-
source =
3-
src/pytkdocs
4-
*/site-packages/pytkdocs
5-
61
[coverage:run]
72
branch = true
8-
source =
9-
src/pytkdocs
10-
tests
113
parallel = true
4+
source =
5+
src/
6+
tests/
7+
8+
[coverage:paths]
9+
equivalent =
10+
src/
11+
__pypackages__/
1212

1313
[coverage:report]
1414
precision = 2
1515
omit =
16-
src/pytkdocs/__init__.py
17-
src/pytkdocs/__main__.py
18-
tests/*
19-
20-
[coverage:html]
21-
directory = build/coverage
16+
src/*/__init__.py
17+
src/*/__main__.py
18+
tests/__init__.py
2219

2320
[coverage:json]
24-
output = build/coverage.json
21+
output = htmlcov/coverage.json

docs/credits.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
{{ credits() }}
1+
# Credits
2+
3+
These projects were used to build *[[ project_name ]]*. **Thank you!**
4+
5+
[`python`](https://www.python.org/) |
6+
[`pdm`](https://pdm.fming.dev/) |
7+
[`copier-pdm`](https://github.com/pawamoy/copier-pdm)
8+
9+
### Direct dependencies
10+
11+
{{ cite_packages(package_info, direct_dependencies) }}
12+
13+
### Indirect dependencies
14+
15+
{{ cite_packages(package_info, indirect_dependencies) }}
16+
17+
**[More credits from the author](http://pawamoy.github.io/credits/)**

docs/macros.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
"""Macros and filters made available in Markdown pages."""
22

3-
import functools
3+
import re
44
from itertools import chain
55
from pathlib import Path
66

7-
import httpx
87
import toml
9-
from jinja2 import StrictUndefined
10-
from jinja2.sandbox import SandboxedEnvironment
118
from pip._internal.commands.show import search_packages_info # noqa: WPS436 (no other way?)
129

1310

@@ -19,19 +16,23 @@ def get_credits_data() -> dict:
1916
Data required to render the credits template.
2017
"""
2118
project_dir = Path(__file__).parent.parent
22-
metadata = toml.load(project_dir / "pyproject.toml")["tool"]["poetry"]
23-
lock_data = toml.load(project_dir / "poetry.lock")
19+
metadata = toml.load(project_dir / "pyproject.toml")["project"]
20+
metadata_pdm = toml.load(project_dir / "pyproject.toml")["tool"]["pdm"]
21+
lock_data = toml.load(project_dir / "pdm.lock")
2422
project_name = metadata["name"]
2523

26-
poetry_dependencies = chain(metadata["dependencies"].keys(), metadata["dev-dependencies"].keys())
27-
direct_dependencies = {dep.lower() for dep in poetry_dependencies}
28-
direct_dependencies.remove("python")
24+
all_dependencies = chain(
25+
metadata.get("dependencies", []),
26+
chain(*metadata.get("optional-dependencies", {}).values()),
27+
chain(*metadata_pdm.get("dev-dependencies", {}).values()),
28+
)
29+
direct_dependencies = {re.sub(r"[^\w-].*$", "", dep) for dep in all_dependencies}
30+
direct_dependencies = {dep.lower() for dep in direct_dependencies}
2931
indirect_dependencies = {pkg["name"].lower() for pkg in lock_data["package"]}
3032
indirect_dependencies -= direct_dependencies
31-
dependencies = direct_dependencies | indirect_dependencies
3233

3334
packages = {}
34-
for pkg in search_packages_info(dependencies):
35+
for pkg in search_packages_info(direct_dependencies | indirect_dependencies): # type: ignore
3536
pkg = {_: pkg[_] for _ in ("name", "home-page")}
3637
packages[pkg["name"].lower()] = pkg
3738

@@ -49,22 +50,6 @@ def get_credits_data() -> dict:
4950
}
5051

5152

52-
@functools.lru_cache(maxsize=None)
53-
def get_credits():
54-
"""
55-
Return credits as Markdown.
56-
57-
Returns:
58-
The credits page Markdown.
59-
"""
60-
jinja_env = SandboxedEnvironment(undefined=StrictUndefined)
61-
commit = "166758a98d5e544aaa94fda698128e00733497f4"
62-
template_url = f"https://raw.githubusercontent.com/pawamoy/jinja-templates/{commit}/credits.md"
63-
template_data = get_credits_data()
64-
template_text = httpx.get(template_url).text
65-
return jinja_env.from_string(template_text).render(**template_data)
66-
67-
6853
def define_env(env):
6954
"""
7055
Add macros and filters into the Jinja2 environment.
@@ -75,7 +60,13 @@ def define_env(env):
7560
Arguments:
7661
env: An object used to add macros and filters to the environment.
7762
"""
63+
env.variables.update(get_credits_data())
64+
65+
@env.macro # noqa: WPS430
66+
def cite_package(info, name): # noqa: WPS430
67+
package = info.get(name, {})
68+
return f"[`{package.get('name', name)}`]({package.get('home-page', '')})"
7869

79-
@env.macro # noqa: WPS430 (nested function)
80-
def credits(): # noqa: WPS430
81-
return get_credits()
70+
@env.macro # noqa: WPS430
71+
def cite_packages(info, names): # noqa: WPS430
72+
return " | ".join(cite_package(info, name) for name in names)

0 commit comments

Comments
 (0)