Skip to content

Commit aa494da

Browse files
authored
Add ruff (#64)
1 parent a02af91 commit aa494da

File tree

10 files changed

+123
-159
lines changed

10 files changed

+123
-159
lines changed

.github/workflows/check.yml

Lines changed: 25 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: check
22
on:
33
push:
4+
tags-ignore: ["**"]
45
pull_request:
56
schedule:
67
- cron: "0 8 * * *"
@@ -11,108 +12,66 @@ concurrency:
1112

1213
jobs:
1314
test:
14-
name: test ${{ matrix.py }} - ${{ matrix.os }}
15-
runs-on: ${{ matrix.os }}
15+
name: test on CPython ${{ matrix.py }}
16+
runs-on: ubuntu-latest
1617
strategy:
1718
fail-fast: false
1819
matrix:
1920
py:
21+
- "3.12.0-beta.2"
2022
- "3.11"
2123
- "3.10"
22-
- "pypy-3.7-v7.3.7" # ahead to start it earlier because takes longer
23-
- "3.9"
24-
- "3.8"
25-
- "3.7"
26-
os:
27-
- ubuntu-22.04
28-
- windows-2022
29-
- macos-12
30-
24+
- 3.9
25+
- 3.8
26+
- 3.7
3127
steps:
32-
- name: Setup python for tox
28+
- name: setup python for tox
3329
uses: actions/setup-python@v4
3430
with:
3531
python-version: "3.11"
36-
- name: Install tox
32+
- name: install tox
3733
run: python -m pip install tox
3834
- uses: actions/checkout@v3
39-
with:
40-
fetch-depth: 0
41-
- name: Setup python for test ${{ matrix.py }}
35+
- name: setup python for test ${{ matrix.py }}
4236
uses: actions/setup-python@v4
4337
with:
4438
python-version: ${{ matrix.py }}
4539
- name: Pick environment to run
4640
run: |
47-
import codecs
48-
import os
49-
import platform
50-
import sys
51-
cpy = platform.python_implementation() == "CPython"
52-
base =("{}{}{}" if cpy else "{}{}").format("py" if cpy else "pypy", *sys.version_info[0:2])
53-
env = "TOXENV={}\n".format(base)
54-
print("Picked:\n{}for{}".format(env, sys.version))
41+
import codecs; import os; import sys
42+
env = f"TOXENV=py3{sys.version_info[1]}\n"
43+
print("Picked:\n{env}for{sys.version}")
5544
with codecs.open(os.environ["GITHUB_ENV"], "a", "utf-8") as file_handler:
5645
file_handler.write(env)
5746
shell: python
58-
- name: Setup test suite
47+
- name: setup test suite
5948
run: tox -vv --notest
60-
- name: Run test suite
49+
- name: run test suite
6150
run: tox --skip-pkg-install
6251
env:
6352
PYTEST_ADDOPTS: "-vv --durations=20"
6453
CI_RUN: "yes"
6554
DIFF_AGAINST: HEAD
6655

6756
check:
68-
name: tox env ${{ matrix.tox_env }} - ${{ matrix.os }}
69-
runs-on: ${{ matrix.os }}
57+
name: tox env ${{ matrix.tox_env }}
58+
runs-on: ubuntu-latest
7059
strategy:
7160
fail-fast: false
7261
matrix:
73-
os:
74-
- ubuntu-22.04
75-
- windows-2022
7662
tox_env:
77-
- dev
7863
- type
79-
- readme
80-
exclude:
81-
- { os: windows-latest, tox_env: readme }
64+
- dev
65+
- pkg_check
8266
steps:
8367
- uses: actions/checkout@v3
84-
with:
85-
fetch-depth: 0
86-
- name: Setup Python "3.11"
68+
- name: setup Python 3.11
8769
uses: actions/setup-python@v4
8870
with:
8971
python-version: "3.11"
90-
- name: Install tox
72+
- name: install tox
9173
run: python -m pip install tox
92-
- name: Setup test suite
93-
run: tox -vv --notest -e ${{ matrix.tox_env }}
94-
- name: Run test suite
95-
run: tox --skip-pkg-install -e ${{ matrix.tox_env }}
96-
97-
publish:
98-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
99-
needs: [check, test]
100-
runs-on: ubuntu-22.04
101-
steps:
102-
- name: Setup python to build package
103-
uses: actions/setup-python@v4
104-
with:
105-
python-version: "3.11"
106-
- name: Install build
107-
run: python -m pip install build
108-
- uses: actions/checkout@v3
109-
with:
110-
fetch-depth: 0
111-
- name: Build sdist and wheel
112-
run: python -m build -s -w . -o dist
113-
- name: Publish to PyPi
114-
uses: pypa/[email protected]
115-
with:
116-
skip_existing: true
117-
user: __token__
118-
password: ${{ secrets.pypi_password }}
74+
- name: run check for ${{ matrix.tox_env }}
75+
run: python -m tox -e ${{ matrix.tox_env }}
76+
env:
77+
UPGRADE_ADVISORY: "yes"

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release to PyPI
2+
on:
3+
push:
4+
tags: ["*"]
5+
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
environment:
10+
name: release
11+
url: https://pypi.org/p/sphinx-argparse-cli
12+
permissions:
13+
id-token: write
14+
steps:
15+
- name: Setup python to build package
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.11"
19+
- name: Install build
20+
run: python -m pip install build
21+
- uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
- name: Build package
25+
run: pyproject-build -s -w . -o dist
26+
- name: Publish to PyPI
27+
uses: pypa/[email protected]

.pre-commit-config.yaml

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,32 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.4.0
44
hooks:
5-
- id: check-ast
6-
- id: check-builtin-literals
7-
- id: check-docstring-first
8-
- id: check-merge-conflict
9-
- id: check-yaml
10-
- id: check-toml
11-
- id: debug-statements
125
- id: end-of-file-fixer
136
- id: trailing-whitespace
14-
- repo: https://github.com/asottile/pyupgrade
15-
rev: v3.3.2
16-
hooks:
17-
- id: pyupgrade
18-
args: ["--py37-plus"]
19-
- repo: https://github.com/PyCQA/isort
20-
rev: 5.12.0
21-
hooks:
22-
- id: isort
237
- repo: https://github.com/psf/black
248
rev: 23.3.0
259
hooks:
2610
- id: black
27-
args: [--safe]
28-
- repo: https://github.com/asottile/blacken-docs
29-
rev: 1.13.0
30-
hooks:
31-
- id: blacken-docs
32-
additional_dependencies: [black==23.3]
33-
- repo: https://github.com/tox-dev/pyproject-fmt
34-
rev: "0.11.1"
35-
hooks:
36-
- id: pyproject-fmt
37-
additional_dependencies: [tox>=4.5.1]
3811
- repo: https://github.com/tox-dev/tox-ini-fmt
3912
rev: "1.3.0"
4013
hooks:
4114
- id: tox-ini-fmt
4215
args: ["-p", "fix"]
43-
- repo: https://github.com/PyCQA/flake8
44-
rev: 6.0.0
16+
- repo: https://github.com/tox-dev/pyproject-fmt
17+
rev: "0.12.0"
4518
hooks:
46-
- id: flake8
47-
additional_dependencies:
48-
- flake8-bugbear==23.3.23
49-
- flake8-comprehensions==3.12
50-
- flake8-pytest-style==1.7.2
51-
- flake8-spellcheck==0.28
52-
- flake8-unused-arguments==0.0.13
53-
- flake8-noqa==1.3.1
54-
- pep8-naming==0.13.3
55-
- flake8-pyproject==1.2.3
19+
- id: pyproject-fmt
20+
additional_dependencies: ["tox>=4.6.1"]
5621
- repo: https://github.com/pre-commit/mirrors-prettier
57-
rev: "v2.7.1"
22+
rev: "v3.0.0-alpha.9-for-vscode"
5823
hooks:
5924
- id: prettier
60-
additional_dependencies:
61-
62-
- "@prettier/[email protected]"
6325
args: ["--print-width=120", "--prose-wrap=always"]
26+
- repo: https://github.com/astral-sh/ruff-pre-commit
27+
rev: "v0.0.272"
28+
hooks:
29+
- id: ruff
30+
args: [--fix, --exit-non-zero-on-fix]
6431
- repo: meta
6532
hooks:
6633
- id: check-hooks-apply

pyproject.toml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
build-backend = "hatchling.build"
33
requires = [
44
"hatch-vcs>=0.3",
5-
"hatchling>=1.14",
5+
"hatchling>=1.18",
66
]
77

88
[project]
@@ -36,11 +36,12 @@ dynamic = [
3636
"version",
3737
]
3838
dependencies = [
39-
"pytest>=7.3.1",
39+
"pytest>=7.3.2",
4040
]
4141
optional-dependencies.test = [
42-
"coverage>=7.2.3",
43-
"pytest-mock>=3.10",
42+
"covdefaults>=2.3",
43+
"coverage>=7.2.7",
44+
"pytest-mock>=3.11.1",
4445
]
4546
urls.Homepage = "https://github.com/pytest-dev/pytest-print"
4647
urls.Source = "https://github.com/pytest-dev/pytest-print"
@@ -55,17 +56,27 @@ version.source = "vcs"
5556
[tool.black]
5657
line-length = 120
5758

58-
[tool.isort]
59-
profile = "black"
60-
known_first_party = ["pytest_print"]
61-
62-
[tool.flake8]
63-
ignore = ["E203"]
64-
max-complexity = 22
65-
max-line-length = 120
66-
unused-arguments-ignore-abstract-functions = true
67-
noqa-require-code = true
68-
dictionaries = ["en_US", "python", "technical", "django"]
59+
[tool.ruff]
60+
select = ["ALL"]
61+
line-length = 120
62+
target-version = "py37"
63+
isort = {known-first-party = ["pytest_print"], required-imports = ["from __future__ import annotations"]}
64+
ignore = [
65+
"ANN101", # no typoe annotation for self
66+
"ANN401", # allow Any as type annotation
67+
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
68+
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
69+
"S104", # Possible binding to all interface
70+
]
71+
[tool.ruff.per-file-ignores]
72+
"tests/**/*.py" = [
73+
"S101", # asserts allowed in tests...
74+
"FBT", # don"t care about booleans as positional arguments in tests
75+
"INP001", # no implicit namespace
76+
"D", # don"t care about documentation in tests
77+
"S603", # `subprocess` call: check for execution of untrusted input
78+
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
79+
]
6980

7081
[tool.coverage]
7182
run.source = ["pytest_print", "tests"]
@@ -85,6 +96,7 @@ paths.source = [
8596
"*/src",
8697
"*\\src",
8798
]
99+
run.plugins = ["covdefaults"]
88100

89101
[tool.mypy]
90102
python_version = "3.11"

src/pytest_print/__init__.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
from datetime import datetime
2-
from typing import Callable, Optional
1+
"""Pytest print functionality."""
2+
from __future__ import annotations
3+
4+
from timeit import default_timer
5+
from typing import TYPE_CHECKING, Callable
36

47
import pytest
5-
from _pytest.config.argparsing import Parser
6-
from _pytest.fixtures import SubRequest
7-
from _pytest.terminal import TerminalReporter
88

99
from ._version import __version__
1010

11+
if TYPE_CHECKING:
12+
from _pytest.config.argparsing import Parser
13+
from _pytest.fixtures import SubRequest
14+
from _pytest.terminal import TerminalReporter
15+
1116

1217
def pytest_addoption(parser: Parser) -> None:
1318
group = parser.getgroup("general")
@@ -29,7 +34,7 @@ def pytest_addoption(parser: Parser) -> None:
2934

3035
@pytest.fixture(name="printer")
3136
def printer(request: SubRequest) -> Callable[[str], None]:
32-
"""pytest plugin to print test progress steps in verbose mode"""
37+
"""Pytest plugin to print test progress steps in verbose mode."""
3338
return create_printer(request)
3439

3540

@@ -48,21 +53,21 @@ def create_printer(request: SubRequest) -> Callable[[str], None]:
4853
return no_op
4954

5055

51-
def no_op(msg: str) -> None: # noqa: U100
52-
"""Do nothing"""
56+
def no_op(msg: str) -> None: # noqa: ARG001
57+
"""Do nothing."""
5358

5459

5560
class State:
56-
def __init__(self, print_relative: bool, reporter: TerminalReporter) -> None:
61+
def __init__(self, print_relative: bool, reporter: TerminalReporter) -> None: # noqa: FBT001
5762
self._reporter = reporter
58-
self._start = datetime.now() if print_relative else None
63+
self._start = default_timer() if print_relative else None
5964
self._print_relative = print_relative
6065

6166
@property
62-
def elapsed(self) -> Optional[float]:
67+
def elapsed(self) -> float | None:
6368
if self._start is None:
6469
return None # pragma: no cover
65-
return (datetime.now() - self._start).total_seconds()
70+
return default_timer() - self._start
6671

6772
def printer(self, msg: str) -> None:
6873
msg = "\t{}{}".format(f"{self.elapsed}\t" if self._print_relative else "", msg)

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from __future__ import annotations
2+
13
pytest_plugins = ["pytester"]

tests/example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from time import sleep
24
from typing import Callable, Iterator
35

0 commit comments

Comments
 (0)