Skip to content

Commit 1f4e9b3

Browse files
authored
refactor!: require mock name, remove deprecated methods, drop Python 3.6 (#151)
BREAKING CHANGE: if you do not specify a `cls` or `func` argument to `decoy.mock()`, you must specify a `name` parameter. You can use the following find-and-replace patterns to fix most tests that start failing due to this change: ``` # find ([a-z_]+?)(: .+?)? = decoy.mock\(\) # replace $1$2 = decoy.mock(name="$1") ``` ``` # find ([a-z_]+?)(: .+?)? = decoy.mock\(is_async=(.+?)\) # replace $1$2 = decoy.mock(name="$1", is_async=$3) ```
1 parent e9fe3f7 commit 1f4e9b3

30 files changed

+1205
-1187
lines changed

.flake8

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

.github/actions/setup/action.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Set up repository for CI"
2+
description: "Install development dependencies"
3+
4+
inputs:
5+
python-version:
6+
description: "Python version to install"
7+
default: "3.11"
8+
poetry-version:
9+
description: "Poetry version to install"
10+
default: "1.3.2"
11+
cache:
12+
description: "Cache directory"
13+
default: "${{ runner.temp }}/cache"
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: "Set up Python"
19+
id: setup-python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ inputs.python-version }}
23+
24+
- name: "Set up dependency cache"
25+
uses: actions/cache@v3
26+
with:
27+
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ inputs.poetry-version }}-${{ hashFiles('poetry.lock') }}
28+
path: ${{ inputs.cache }}
29+
30+
- name: "Set up PATH on POSIX"
31+
if: ${{ runner.os != 'windows'}}
32+
shell: bash
33+
run: echo "${{ inputs.cache }}/tools/bin" >> $GITHUB_PATH
34+
35+
- name: "Set up PATH on Windows"
36+
if: ${{ runner.os == 'windows'}}
37+
shell: bash
38+
run: echo "${{ inputs.cache }}/tools/Scripts" >> $GITHUB_PATH
39+
40+
- name: "Check poetry installation"
41+
id: check-poetry
42+
shell: bash
43+
continue-on-error: true
44+
run: poetry --version
45+
46+
- name: "Install poetry"
47+
shell: bash
48+
if: ${{ steps.check-poetry.outcome == 'failure'}}
49+
run: |
50+
"${{ steps.setup-python.outputs.python-path }}" -m venv "${{ inputs.cache }}/tools"
51+
pip install poetry==${{ inputs.poetry-version }}
52+
53+
- name: "Install development dependencies"
54+
shell: bash
55+
run: |
56+
poetry config cache-dir "${{ inputs.cache }}/poetry"
57+
poetry install --sync

.github/workflows/ci.yml

Lines changed: 21 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,58 @@
1-
name: 'Continuous integration'
1+
name: "Continuous integration"
22

33
on: [push, pull_request]
44

5-
env:
6-
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip
7-
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/pypoetry
8-
DEFAULT_PYTHON: '3.8'
9-
105
jobs:
116
test:
12-
name: 'Test Python ${{ matrix.python-version }} on ${{ matrix.os }}'
7+
name: "Test Python ${{ matrix.python-version }} on ${{ matrix.os }}"
138
runs-on: ${{ matrix.os }}-latest
149
strategy:
1510
matrix:
1611
os: [Ubuntu, Windows, macOS]
17-
python-version: ['3.7', '3.8', '3.9', '3.10']
12+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1813
steps:
19-
- name: 'Check out repository'
14+
- name: "Check out repository"
2015
uses: actions/checkout@v3
2116

22-
- name: 'Set up Python'
23-
uses: actions/setup-python@v4
17+
- name: "Set up Python and development dependencies"
18+
uses: ./.github/actions/setup
2419
with:
2520
python-version: ${{ matrix.python-version }}
2621

27-
- name: 'Set up dependency cache'
28-
uses: actions/cache@v3
29-
# poetry venv restore is buggy on windows
30-
# https://github.com/python-poetry/poetry/issues/2629
31-
if: ${{ matrix.os != 'Windows' }}
32-
with:
33-
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('**/*.lock') }}
34-
path: |
35-
${{ env.PIP_CACHE_DIR }}
36-
${{ env.POETRY_CACHE_DIR }}
37-
38-
- name: 'Install poetry'
39-
run: pip install "poetry==1.1.11"
40-
41-
- name: 'Install dependencies'
42-
run: poetry install
43-
44-
- name: 'Run tests'
45-
run: poetry run coverage run --branch --source=decoy -m pytest --mypy-same-process
22+
- name: "Run tests"
23+
run: poetry run poe test-ci
4624

47-
- name: 'Generate coverage report'
48-
run: poetry run coverage xml
49-
50-
- name: 'Upload coverage report'
25+
- name: "Upload coverage report"
5126
uses: codecov/codecov-action@v3
5227

5328
check:
54-
name: 'Lint and type checks'
29+
name: "Lint and type checks"
5530
runs-on: ubuntu-latest
5631
steps:
57-
- name: 'Check out repository'
32+
- name: "Check out repository"
5833
uses: actions/checkout@v3
5934

60-
- name: 'Set up Python'
61-
uses: actions/setup-python@v4
62-
with:
63-
python-version: ${{ env.DEFAULT_PYTHON }}
64-
65-
- name: 'Set up dependency cache'
66-
uses: actions/cache@v3
67-
with:
68-
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
69-
path: |
70-
${{ env.PIP_CACHE_DIR }}
71-
${{ env.POETRY_CACHE_DIR }}
72-
73-
- name: 'Install poetry'
74-
run: pip install "poetry==1.1.11"
35+
- name: "Set up Python and development dependencies"
36+
uses: ./.github/actions/setup
7537

76-
- name: 'Install dependencies'
77-
run: poetry install
78-
79-
- name: 'Check formatting'
80-
run: poetry run black --check .
81-
82-
- name: 'Check linter'
83-
run: poetry run flake8
84-
85-
- name: 'Checks types'
86-
run: poetry run mypy
38+
- name: "Check types, lints, and formatting"
39+
run: poetry run poe check-ci
8740

8841
build:
8942
name: Build assets and deploy on tags
9043
runs-on: ubuntu-latest
9144
needs: [test, check]
9245
steps:
93-
- name: 'Check out repository'
46+
- name: "Check out repository"
9447
uses: actions/checkout@v3
9548

96-
- name: 'Set up Python'
97-
uses: actions/setup-python@v4
98-
with:
99-
python-version: ${{ env.DEFAULT_PYTHON }}
49+
- name: "Set up Python and development dependencies"
50+
uses: ./.github/actions/setup
10051

101-
- name: 'Set up dependency cache'
102-
uses: actions/cache@v3
103-
with:
104-
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
105-
path: |
106-
${{ env.PIP_CACHE_DIR }}
107-
${{ env.POETRY_CACHE_DIR }}
108-
109-
- name: 'Install poetry'
110-
run: pip install "poetry==1.1.11"
111-
112-
- name: 'Install dependencies'
113-
run: poetry install
114-
115-
- name: 'Build artifacts'
116-
run: |
117-
poetry build
118-
poetry run mkdocs build
52+
- name: "Build artifacts"
53+
run: poetry run poe build-ci
11954

120-
- name: 'Deploy to PyPI and GitHub Pages'
55+
- name: "Deploy to PyPI and GitHub Pages"
12156
if: startsWith(github.ref, 'refs/tags/v')
12257
env:
12358
USER_NAME: ${{ github.actor }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ site
33
*.egg-info
44
.python-version
55
__pycache__
6-
.cache
76
.coverage
87
coverage.xml
98
htmlcov
9+
.ruff_cache

CONTRIBUTING.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All contributions are greatly appreciated! Before contributing, please read the
66

77
This project uses [Poetry][] to manage dependencies and builds, and you will need to install it before working on Decoy.
88

9-
Once Poetry is installed, you should be good to set up a virtual environment and install development dependencies. Python >= 3.8 is required for development.
9+
Once Poetry is installed, you should be good to set up a virtual environment and install development dependencies. Python 3.11 is recommended for development.
1010

1111
```bash
1212
git clone https://github.com/mcous/decoy.git
@@ -16,18 +16,27 @@ poetry install
1616

1717
## Development Tasks
1818

19+
Decoy uses [poethepoet][] to manage development tasks. If you want to quickly check everything, run the following:
20+
21+
```shell
22+
poetry run poe all
23+
```
24+
25+
[poethepoet]: https://github.com/nat-n/poethepoet
26+
1927
### Tests
2028

21-
Decoy's tests are run using [pytest][].
29+
Decoy's tests are run using [pytest][]. To run tests in watch mode:
2230

2331
```bash
24-
poetry run pytest
32+
poetry run poe test
2533
```
2634

27-
You can also run tests in watch mode using [pytest-xdist][].
35+
To run tests once and report coverage
2836

2937
```bash
30-
poetry run pytest --looponfail
38+
poetry run poe test-once
39+
poetry run poe coverage
3140
```
3241

3342
In an exciting twist, since version 1.6.0, Decoy's tests rely on Decoy itself to test (and more importantly, design) the relationships between Decoy's internal APIs. This means:
@@ -39,27 +48,27 @@ If you find yourself in a situation where Decoy's test suite has blown up, **con
3948

4049
### Checks
4150

42-
Decoy's source code is typechecked with [mypy][] and linted with [flake8][].
51+
Decoy's source code is typechecked with [mypy][] and linted with [ruff][].
4352

4453
```bash
45-
poetry run mypy
46-
poetry run flake8
54+
poetry run poe check
55+
poetry run poe lint
4756
```
4857

4958
### Formatting
5059

5160
Decoy's source code is formatted using [black][].
5261

5362
```bash
54-
poetry run black .
63+
poetry run poe format
5564
```
5665

5766
### Documentation
5867

5968
Decoy's documentation is built with [mkdocs][], which you can use to preview the documentation site locally.
6069

6170
```bash
62-
poetry run mkdocs serve
71+
poetry run docs
6372
```
6473

6574
## Deploying
@@ -92,7 +101,7 @@ git push --follow-tags
92101
[pytest]: https://docs.pytest.org/
93102
[pytest-xdist]: https://github.com/pytest-dev/pytest-xdist
94103
[mypy]: https://mypy.readthedocs.io
95-
[flake8]: https://flake8.pycqa.org
104+
[ruff]: https://github.com/charliermarsh/ruff
96105
[black]: https://black.readthedocs.io
97106
[mkdocs]: https://www.mkdocs.org/
98107
[semantic versioning]: https://semver.org/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-2021, Mike Cousins
3+
Copyright (c) 2020-2023, Mike Cousins
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)