Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
offbyone authored Sep 27, 2024
2 parents 242a989 + 2e66e12 commit 2b233b9
Show file tree
Hide file tree
Showing 13 changed files with 1,856 additions and 84 deletions.
69 changes: 37 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
USING_COVERAGE: "3.8,3.9,3.10,3.11,3.12"

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version:
Expand All @@ -32,74 +33,74 @@ jobs:
- "pypy3.9"
exclude:
- os: macos-latest
python-version: pypy3
python-version: pypy3.9

steps:
- uses: "actions/checkout@v3"
- uses: actions/checkout@v4
with:
# We want our tags here
fetch-depth: 0
- uses: "actions/setup-python@v4"
- name: Install the latest version of uv
id: setup-uv
uses: astral-sh/setup-uv@v3
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python -VV
python -msite
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade coverage[toml] virtualenv tox tox-gh-actions
enable-cache: true

- name: "Run tox targets for ${{ matrix.python-version }}"
run: "python -m tox"
env:
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }}
run: uvx --with tox-uv --with tox-gh tox

- name: Upload coverage data
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: ".coverage.*"
name: coverage-data-${{ matrix.python-version }}-${{ matrix.os }}
path: ".coverage*"
if-no-files-found: ignore
include-hidden-files: true

coverage:
needs:
- tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Install the latest version of uv
id: setup-uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"

- name: Install coverage
run: python -m pip install --upgrade coverage[toml]
enable-cache: true

- name: Download coverage data
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: coverage-data
pattern: coverage-data-*
merge-multiple: true

- name: Combine coverage
run: python -m coverage combine
run: |
uvx --with coverage[toml] coverage combine
# ignore-errors is so that we don't gag on missing code in .tox environments
- name: Generate the HTML report
run: python -m coverage html --skip-covered --skip-empty --ignore-errors
run: uvx --with coverage[toml] coverage html --skip-covered --skip-empty --ignore-errors

- name: Upload the HTML report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov

# ignore-errors is so that we don't gag on missing code in .tox environments
- name: Enforce the coverage
run: python -m coverage report --ignore-errors --fail-under 95
run: uvx --with coverage[toml] coverage report --ignore-errors --fail-under 95

package:
name: "Build & verify package"
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v3"
- uses: actions/checkout@v4
with:
# We want our tags here
fetch-depth: 0
Expand All @@ -114,11 +115,15 @@ jobs:
runs-on: "${{ matrix.os }}"

steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
- uses: actions/checkout@v4
- name: Install the latest version of uv
id: setup-uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
enable-cache: true
- name: "Install in dev mode"
run: "python -m pip install -e .[dev]"
run: |
uv venv
uv pip install -e .[dev]
- name: "Import package"
run: "python -c 'import hamcrest; print(hamcrest.__version__)'"
run: "uv run python -c 'import hamcrest; print(hamcrest.__version__)'"
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# Fetch all tags; this is needed for hatch-vcs
fetch-depth: 0
Expand All @@ -43,7 +43,7 @@ jobs:

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
Expand All @@ -64,7 +64,7 @@ jobs:
(github.event_name == 'workflow_dispatch' && startsWith(github.event.ref, 'refs/tags'))
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: Packages
path: dist
Expand All @@ -73,5 +73,3 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip_existing: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
22 changes: 8 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ repos:
- id: blacken-docs
# args: ["-l100"]

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.8
hooks:
- id: flake8
exclude: >-
(?x)^(
examples/.*\.py$
| doc/.*\.py$
)
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
# args: ["-l100"]
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
3 changes: 2 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys
import os
import alabaster

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
16 changes: 15 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dev = [
"flake8",
"black",
"tox",
"tox-asdf",
"tox-uv",
"doc2dash",
]

Expand Down Expand Up @@ -137,6 +137,20 @@ exclude_lines = [
"-> ['\"]?NoReturn['\"]?:",
]

[tool.ruff]
exclude = [
# re-ordering in this can lead to circular imports. No good!
"src/hamcrest/__init__.py",
]
line-length = 100

[tool.ruff.lint]
ignore = [
# We use star imports everywhere in this damn codebase
"F405",
"F403"
]

[tool.black]
line_length = 100

Expand Down
2 changes: 2 additions & 0 deletions src/hamcrest/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ruff: noqa: F405, F403

from hamcrest.core.assert_that import assert_that
from hamcrest.core.core import *

Expand Down
4 changes: 2 additions & 2 deletions src/hamcrest/core/core/isinstanceof.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Type
from typing import Type, Any

from hamcrest.core.base_matcher import BaseMatcher
from hamcrest.core.description import Description
Expand All @@ -23,7 +23,7 @@ def describe_to(self, description: Description) -> None:
description.append_text("an instance of ").append_text(self.expected_type.__name__)


def instance_of(atype: Type) -> Matcher[object]:
def instance_of(atype: Type[Any]) -> Matcher[object]:
"""Matches if object is an instance of, or inherits from, a given type.
:param atype: The type to compare against as the expected type.
Expand Down
6 changes: 4 additions & 2 deletions src/hamcrest/core/core/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def describe_match(self, item, match_description: Description) -> None:
)


def raises(exception: Type[Exception], pattern=None, matching=None) -> Matcher[Callable[..., Any]]:
def raises(
exception: Type[Exception], pattern: Optional[str] = None, matching: Optional[Matcher] = None
) -> Matcher[Callable[..., Any]]:
"""Matches if the called function raised the expected exception.
:param exception: The class of the expected exception
Expand Down Expand Up @@ -121,7 +123,7 @@ def __init__(self, func: Callable[..., Any]):
def __call__(self):
self.func(*self.args, **self.kwargs)

def with_args(self, *args, **kwargs):
def with_args(self, *args: Any, **kwargs: Any):
self.args = args
self.kwargs = kwargs
return self
Expand Down
1 change: 1 addition & 0 deletions src/hamcrest/library/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Library of Matcher implementations."""

# ruff: noqa: F405, F403
from hamcrest.core import *
from hamcrest.library.collection import *
from hamcrest.library.integration import *
Expand Down
2 changes: 1 addition & 1 deletion tests/hamcrest_unit_test/assert_that_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def testAssertionErrorShouldIncludeOptionalReason(self):

def testAssertionUnicodeEncodesProperly(self):
expected = "EXPECTED"
actual = u("\xdcnic\N{Latin Small Letter O with diaeresis}de")
actual = u("\xdcnic\N{LATIN SMALL LETTER O WITH DIAERESIS}de")

with self.assertRaises(AssertionError):
assert_that(actual, equal_to(expected), "REASON")
Expand Down
4 changes: 2 additions & 2 deletions tests/hamcrest_unit_test/base_description_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_append_text_delegates(desc):
("unicode-py3", "'unicode-py3'"),
(b"bytes-py3", "<b'bytes-py3'>"),
pytest.param(
"\U0001F4A9",
"'{0}'".format("\U0001F4A9"),
"\U0001f4a9",
"'{0}'".format("\U0001f4a9"),
marks=pytest.mark.skipif(
platform.python_implementation() == "PyPy",
reason="Inexplicable failure on PyPy. Not super important, I hope!",
Expand Down
32 changes: 8 additions & 24 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ looponfailroots =


# Keep docs in sync with docs env and .readthedocs.yml.
[gh-actions]
[gh]
python =
3.8: py38, py38-numpy
3.9: py39, py39-numpy
3.10: py310, py310-numpy
3.11: py311, py311-numpy
3.12: py312, py312-numpy, lint, changelog, typing, manifest, docs
pypy-2: pypy2
pypy-3: pypy3
3.8 = py38, py38-numpy
3.9 = py39, py39-numpy
3.10 = py310, py310-numpy
3.11 = py311, py311-numpy
3.12 = py312, py312-numpy, lint, changelog, typing, docs
pypy3.9 = pypy3


[tox]
envlist = typing,lint,py38{,-numpy},py39{,-numpy},py310{,-numpy},py311{,-numpy},py312{,-numpy},pypy{,-numpy},pypy3{,-numpy},manifest,docs,pypi-description,changelog,coverage-report
envlist = typing,lint,py38{,-numpy},py39{,-numpy},py310{,-numpy},py311{,-numpy},py312{,-numpy},pypy{,-numpy},pypy3{,-numpy},docs,pypi-description,changelog,coverage-report
isolated_build = True


Expand Down Expand Up @@ -65,7 +64,6 @@ commands = python -m pytest {posargs}
# Python 3.6+ has a number of compile-time warnings on invalid string escapes.
# PYTHONWARNINGS=d and --no-compile below make them visible during the Tox run.
basepython = python3.8
install_command = pip install --no-compile {opts} {packages}
setenv =
PYTHONWARNINGS=d
extras = {env:TOX_AP_TEST_EXTRAS:tests}
Expand All @@ -76,7 +74,6 @@ commands = coverage run -m pytest {posargs}
# Python 3.6+ has a number of compile-time warnings on invalid string escapes.
# PYTHONWARNINGS=d and --no-compile below make them visible during the Tox run.
basepython = python3.9
install_command = pip install --no-compile {opts} {packages}
setenv =
PYTHONWARNINGS=d
extras = {env:TOX_AP_TEST_EXTRAS:tests}
Expand All @@ -87,7 +84,6 @@ commands = coverage run -m pytest {posargs}
# Python 3.6+ has a number of compile-time warnings on invalid string escapes.
# PYTHONWARNINGS=d and --no-compile below make them visible during the Tox run.
basepython = python3.10
install_command = pip install --no-compile {opts} {packages}
setenv =
PYTHONWARNINGS=d
extras = {env:TOX_AP_TEST_EXTRAS:tests}
Expand All @@ -98,7 +94,6 @@ commands = coverage run -m pytest {posargs}
# Python 3.6+ has a number of compile-time warnings on invalid string escapes.
# PYTHONWARNINGS=d and --no-compile below make them visible during the Tox run.
basepython = python3.11
install_command = pip install --no-compile {opts} {packages}
setenv =
PYTHONWARNINGS=d
extras = {env:TOX_AP_TEST_EXTRAS:tests}
Expand All @@ -109,7 +104,6 @@ commands = coverage run -m pytest {posargs}
# Python 3.6+ has a number of compile-time warnings on invalid string escapes.
# PYTHONWARNINGS=d and --no-compile below make them visible during the Tox run.
basepython = python3.12
install_command = pip install --no-compile {opts} {packages}
setenv =
PYTHONWARNINGS=d
extras = {env:TOX_AP_TEST_EXTRAS:tests}
Expand Down Expand Up @@ -143,15 +137,6 @@ commands =
sphinx-build -n -T -b html -d {envtmpdir}/doctrees doc doc/_build/html


[testenv:manifest]
basepython = python3.12
deps =
check-manifest
setuptools-scm
skip_install = true
commands = check-manifest --ignore src/hamcrest/_version.py


[testenv:pypi-description]
basepython = python3.12
skip_install = true
Expand All @@ -167,7 +152,6 @@ commands =
basepython = python3.12
deps =
towncrier
importlib_resources<6 # TODO: remove once twisted/towncrier#528 is released
skip_install = true
commands = towncrier --draft

Expand Down
Loading

0 comments on commit 2b233b9

Please sign in to comment.