Skip to content

Commit

Permalink
Add ruff (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Jun 15, 2023
1 parent acaf1dd commit f56d393
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 65 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
fail-fast: false
matrix:
py:
- "3.12.0-beta.1"
- "3.12.0-beta.2"
- "3.11"
- "3.10"
- "3.9"
- "3.8"
- "3.7"
os:
- ubuntu-22.04
- ubuntu-latest

steps:
- name: Setup python for tox
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-latest
tox_env:
- dev
- type
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/pytest-env
Expand Down
57 changes: 17 additions & 40 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,33 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.272"
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [ --safe ]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [ black==23.3 ]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.0"
hooks:
- id: tox-ini-fmt
args: [ "-p", "fix" ]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.3.23
- flake8-comprehensions==3.12
- flake8-pytest-style==1.7.2
- flake8-spellcheck==0.28
- flake8-unused-arguments==0.0.13
- flake8-noqa==1.3.1
- pep8-naming==0.13.3
args: ["-p", "fix"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.9.2"
rev: "0.11.2"
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.6"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
args: ["--print-width=120", "--prose-wrap=always"]
- repo: meta
hooks:
- id: pyproject-fmt
- id: check-hooks-apply
- id: check-useless-excludes
33 changes: 30 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.3",
"hatchling>=1.14",
"hatchling>=1.17.1",
]

[project]
Expand All @@ -22,8 +22,13 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules",
]
Expand All @@ -34,7 +39,7 @@ dependencies = [
"pytest>=7.3.1",
]
optional-dependencies.test = [
"coverage>=7.2.3",
"coverage>=7.2.7",
"pytest-mock>=3.10",
]
urls.Homepage = "https://github.com/pytest-dev/pytest-env"
Expand Down Expand Up @@ -76,3 +81,25 @@ paths.source = [
python_version = "3.10"
show_error_codes = true
strict = true

[tool.ruff]
select = ["ALL"]
line-length = 120
target-version = "py37"
isort = {known-first-party = ["pytest_env"], required-imports = ["from __future__ import annotations"]}
ignore = [
"ANN101", # no typoe annotation for self
"ANN401", # allow Any as type annotation
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"S104", # Possible binding to all interface
]
[tool.ruff.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests...
"FBT", # don"t care about booleans as positional arguments in tests
"INP001", # no implicit namespace
"D", # don"t care about documentation in tests
"S603", # `subprocess` call: check for execution of untrusted input
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
]
1 change: 1 addition & 0 deletions src/pytest_env/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Pytest set environments."""
from __future__ import annotations

from .version import __version__
Expand Down
6 changes: 4 additions & 2 deletions src/pytest_env/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def pytest_addoption(parser: pytest.Parser) -> None:
parser.addini("env", type="linelist", help=help_msg, default=[])


@pytest.hookimpl(tryfirst=True) # type: ignore # untyped decorator
@pytest.hookimpl(tryfirst=True) # type: ignore[misc]
def pytest_load_initial_conftests(
args: list[str], early_config: pytest.Config, parser: pytest.Parser # noqa: U100
args: list[str], # noqa: ARG001
early_config: pytest.Config,
parser: pytest.Parser, # noqa: ARG001
) -> None:
"""Load environment variables from configuration files."""
for line in early_config.getini("env"):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@
],
)
def test_env(
testdir: pytest.Testdir, env: dict[str, str], ini: str, expected_env: dict[str, str], request: pytest.FixtureRequest
testdir: pytest.Testdir,
env: dict[str, str],
ini: str,
expected_env: dict[str, str],
request: pytest.FixtureRequest,
) -> None:
tmp_dir = Path(str(testdir.tmpdir))
test_name = re.sub(r"\W|^(?=\d)", "_", request.node.callspec.id).lower()
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ commands =
description = run static analysis and style check using flake8
skip_install = true
deps =
pre-commit>=3.2.2
pre-commit>=3.2.
pass_env =
HOMEPATH
PROGRAMDATA
Expand All @@ -44,7 +44,7 @@ commands =
[testenv:type]
description = run type check on code base
deps =
mypy==1.2
mypy==1.3
set_env =
{tty:MYPY_FORCE_COLOR = 1}
commands =
Expand Down
13 changes: 0 additions & 13 deletions whitelist.txt

This file was deleted.

0 comments on commit f56d393

Please sign in to comment.