Skip to content

Commit

Permalink
Add Python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorodgerbrown authored Nov 6, 2022
1 parent 7793228 commit 02a6c4e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 34 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [fmt,lint,mypy]
toxenv: [fmt, lint, mypy, checks]
env:
TOXENV: ${{ matrix.toxenv }}

steps:
- name: Check out the repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install and run tox
run: |
Expand All @@ -37,18 +37,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8,"3.10"]
django: [32,41,main]
python: ["3.8", "3.11"]
django: ["32", "41", "main"]

env:
TOXENV: py${{ matrix.python }}-django${{ matrix.django }}

steps:
- name: Check out the repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

Expand Down
7 changes: 3 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ repos:

# python code formatting - will amend files
- repo: https://github.com/ambv/black
rev: 22.6.0
rev: 22.10.0
hooks:
- id: black

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
rev: v3.2.0
hooks:
- id: pyupgrade

Expand All @@ -30,10 +30,9 @@ repos:

# python static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v0.982
hooks:
- id: mypy
# additional_dependencies:
args:
- --disallow-untyped-defs
- --disallow-incomplete-defs
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT Licence (MIT)

Copyright (c) 2020 YunoJuno Ltd
Copyright (c) 2022 YunoJuno Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Django app for managing external side effects.
Python2/3
---------

**This project now supports Python 3.7+ and Django 2.2+ only on master.**
**This project now supports Python 3.8+ and Django 3.2+ only on master.**

Legacy versions are tagged.

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-side-effects"
version = "2.0.beta1"
version = "2.0"
description = "Django app for managing external side effects."
license = "MIT"
authors = ["YunoJuno <code@yunojuno.com>"]
Expand All @@ -18,6 +18,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
packages = [{ include = "side_effects" }]

Expand All @@ -28,7 +29,7 @@ django = "^3.2 || ^4.0"
[tool.poetry.dev-dependencies]
black = {version = "*", allow-prereleases = true}
coverage = "*"
flake8 = "^4.0.1"
flake8 = "*"
flake8-bandit = "*"
flake8-blind-except = "*"
flake8-docstrings = "*"
Expand Down
13 changes: 11 additions & 2 deletions side_effects/checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import inspect
from typing import Any, List
from typing import Any, Callable, List

from django.apps import AppConfig
from django.core.checks import messages, register
Expand All @@ -24,7 +24,16 @@ def _message(label: str) -> messages.CheckMessage:

def signature_count(label: str) -> int:
"""Return number of unique function signatures for an event."""
signatures = [inspect.signature(func) for func in registry._registry[label]]

def trim_signature(func: Callable) -> inspect.Signature:
# Return a Signature for the func that ignores return_value kwarg
sig = inspect.signature(func)
# remove return_value from the signature params as it's dynamic
# and may/ may not exist depending on the usage.
params = [sig.parameters[p] for p in sig.parameters if p != "return_value"]
return sig.replace(parameters=params, return_annotation=sig.return_annotation)

signatures = [trim_signature(func) for func in registry._registry[label]]
return len(set(signatures))


Expand Down
2 changes: 1 addition & 1 deletion side_effects/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Registry(defaultdict):
def __init__(self) -> None:
self._lock = threading.Lock()
self._suppress = False
super(Registry, self).__init__(list)
super().__init__(list)

def by_label(self, value: str) -> RegistryType:
"""Filter registry by label (exact match)."""
Expand Down
18 changes: 10 additions & 8 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@


@has_side_effects("foo")
def origin(message: str):
print(f"origin: {message}") # noqa: T201
def origin(message: str) -> str:
print(f"origin: {message}") # noqa: T001
return f"Message received: {message}"


@is_side_effect_of("foo")
def no_docstring(message: str):
print(f"side-effect.1: message={message}") # noqa: T201
def no_docstring(message: str) -> None:
print(f"side-effect.1: message={message}") # noqa: T001


@is_side_effect_of("foo")
def one_line_docstring(message: str):
def one_line_docstring(message: str) -> None:
"""This is a one-line docstring."""
print(f"side-effect.2: message={message}") # noqa: T201
print(f"side-effect.2: message={message}") # noqa: T001


@is_side_effect_of("foo")
def multi_line_docstring(message: str, return_value=None):
def multi_line_docstring(message: str, return_value: str) -> None:
"""
This is a multi-line docstring.
It has more information here.
"""
print(f"Side-effect.3: return_value={return_value}") # noqa: T201
print( # noqa: T001
f"Side-effect.3: message={message}, return_value={return_value}"
)
3 changes: 2 additions & 1 deletion tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def test_func():
registry.run_side_effects("foo")
mock_logger.warning.assert_called_once_with(
"Side-effects [%s] are being run within the scope of an atomic "
"transaction. This may have unintended consequences.", "foo"
"transaction. This may have unintended consequences.",
"foo",
)

def test__run_func__no_return_value(self):
Expand Down
14 changes: 9 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
[tox]
isolated_build = True
envlist = fmt, lint, mypy, py{3.8,3.9,3.10}-django{32,40,41,main}
envlist = fmt, lint, mypy, checks, py{3.8,3.9,3.10,3.11}-django{32,40,41,main}

[testenv]
deps =
coverage
pytest
pytest-cov
pytest-django
django22: Django>=2.2,<2.3
django30: Django>=3.0,<3.1
django31: Django>=3.1,<3.2
django32: Django>=3.2,<3.3
django40: Django>=4.0,<4.1
django41: Django>=4.1,<4.2
Expand All @@ -19,6 +16,13 @@ deps =
commands =
pytest --cov=side_effects tests

[testenv:checks]
description = Django system checks and missing migrations
deps = Django
commands =
python manage.py check --fail-level WARNING
python manage.py makemigrations --dry-run --check --verbosity 3

[testenv:fmt]
description = 'Source file formatting'
deps =
Expand All @@ -32,7 +36,7 @@ commands =
[testenv:lint]
description = 'Source file linting'
deps =
flake8==4.0.1
flake8
flake8-bandit
flake8-blind-except
flake8-docstrings
Expand Down

0 comments on commit 02a6c4e

Please sign in to comment.