Skip to content

Replace flake8, bugbear, isort, and pyupgrade with ruff #568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ updates:
directory: "/"
schedule:
interval: "weekly"

8 changes: 8 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
schedule:
- cron: '0 4 * * 1'
jobs:
ruff: # https://beta.ruff.rs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install --user ruff
- run: ruff --format=github .

# this job ensures that tests can run from the packaged version, which means
# that nose2 is correctly packaging and distributing its tests
test-sdist:
Expand All @@ -27,6 +34,7 @@ jobs:
nose2 -v --pretty-assert

test:
needs: ruff
strategy:
fail-fast: false
matrix:
Expand Down
34 changes: 17 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ repos:
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.22.0
hooks:
- id: check-github-workflows
- id: check-dependabot
- id: check-readthedocs
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
language_version: python3
additional_dependencies: ['flake8-bugbear==22.7.1']
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
language_version: python3
types: [python]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
hooks:
- id: ruff
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.2
hooks:
- id: validate-pyproject
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 0.9.2
hooks:
- id: pyproject-fmt
11 changes: 5 additions & 6 deletions contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ You can also use ``make test`` and ``make lint`` for these.
Linting
+++++++

nose2 uses `black`_, `isort`_, and `flake8`_ to enforce linting and code
style rules, and `pre-commit`_ to run these tools.
nose2 uses `black`_ and `ruff`_ to enforce code formatting and linting and
`pre-commit`_ to run these tools.

For the best development experience, we recommend setting up integrations with
your editor and git.
Expand All @@ -59,9 +59,8 @@ have ``pre-commit`` installed and run:
If you need to bypass pre-commit hooks after setting this up, you can commit
with ``--no-verify``

.. _github: https://github.com/nose-devs/nose2
.. _tox: http://pypi.python.org/pypi/tox
.. _black: https://black.readthedocs.io/
.. _isort: https://pycqa.github.io/isort/
.. _flake8: https://flake8.pycqa.org/
.. _github: https://github.com/nose-devs/nose2
.. _pre-commit: https://pre-commit.com/
.. _ruff: https://beta.ruff.rs/docs/
.. _tox: http://pypi.python.org/pypi/tox
2 changes: 1 addition & 1 deletion docs/decorators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Setup & Teardown
================

.. autofunction :: nose2.tools.decorators.with_setup
.. autofunction :: nose2.tools.decorators.with_teardown
.. autofunction :: nose2.tools.decorators.with_teardown
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

.. include :: ../README.rst
.. include :: contents.rst.inc

1 change: 0 additions & 1 deletion docs/plugins/collect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Collecting tests without running them
=====================================

.. autoplugin :: nose2.plugins.collect.CollectOnly

2 changes: 0 additions & 2 deletions docs/plugins/doctests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ Loader: Doctests
================

.. autoplugin :: nose2.plugins.doctests.DocTestLoader


1 change: 0 additions & 1 deletion docs/plugins/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Loader: Test Functions
======================

.. autoplugin :: nose2.plugins.loader.functions.Functions

1 change: 0 additions & 1 deletion docs/plugins/junitxml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ The XML test report for nose2's sample scenario with tests in a package looks li
</failure>
</testcase>
</testsuite>

1 change: 0 additions & 1 deletion docs/plugins/outcomes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Mapping exceptions to test outcomes
===================================

.. autoplugin :: nose2.plugins.outcomes.Outcomes

1 change: 0 additions & 1 deletion docs/plugins/testid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Using Test IDs
==============

.. autoplugin :: nose2.plugins.testid.TestId

4 changes: 2 additions & 2 deletions nose2/plugins/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ def _iso_timestamp(self):
]

ILLEGAL_REGEX_STR = (
"[" + "".join([f"{chr(l)}-{chr(h)}" for (l, h) in ILLEGAL_RANGES]) + "]"
"[" + "".join([f"{chr(lo)}-{chr(hi)}" for (lo, hi) in ILLEGAL_RANGES]) + "]"
)
RESTRICTED_REGEX_STR = (
"[" + "".join([f"{chr(l)}-{chr(h)}" for (l, h) in RESTRICTED_RANGES]) + "]"
"[" + "".join([f"{chr(lo)}-{chr(hi)}" for (lo, hi) in RESTRICTED_RANGES]) + "]"
)

_ILLEGAL_REGEX = re.compile(ILLEGAL_REGEX_STR, re.U)
Expand Down
2 changes: 1 addition & 1 deletion nose2/plugins/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def add_layer_to_tree(cls, tree, layer):
raise exceptions.LoadTestsFailure(err.format(layer))
for parent in parents:
if parent not in tree and parent is not object:
raise MissingParentLayer()
raise MissingParentLayer
# if we reached that point, then all the parents are in the tree
# if there are multiple parents, we first try to get the closest
# to the current layer.
Expand Down
2 changes: 1 addition & 1 deletion nose2/plugins/mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def procserver(session_export, conn):
# XXX If there a need to protect the loop? try/except?
rlog.debug("Execute test %s (%s)", testid, test)
executor(test, event.result)
events = [e for e in ssn.hooks.flush()]
events = list(ssn.hooks.flush())
try:
conn.send((testid, events))
rlog.debug("Log for %s returned", testid)
Expand Down
3 changes: 3 additions & 0 deletions nose2/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def stopTest(self, test):
event = events.StopTestEvent(test, self, time.time())
self.session.hooks.stopTest(event)

def addDuration(self, test, elapsed): # For Python >= 3.12
pass

def addError(self, test, err):
"""Test case resulted in error.

Expand Down
2 changes: 1 addition & 1 deletion nose2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self):
self.testResult = None
self.testLoader = None
self.logLevel = logging.WARN
self.configCache = dict()
self.configCache = {}

def get(self, section):
"""Get a config section.
Expand Down
4 changes: 2 additions & 2 deletions nose2/sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def add_config(self, rst, config, plugin):
info = config.vars[var]
rst.append(".. rst:configvar :: %s" % var, AD)
rst.append(" ", AD)
rst.append(" :Default: %(default)s" % info, AD)
rst.append(" :Type: %(type)s" % info, AD)
rst.append(" :Default: {default}".format(**info), AD)
rst.append(" :Type: {type}".format(**info), AD)
rst.append("", AD)

self.headline(rst, "Sample configuration", "-")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_failing_assert(self):
x = True
y = False
# fmt: off
# flake8: noqa
# ruff: noqa
assert x; assert y
# fmt: on

Expand Down
2 changes: 1 addition & 1 deletion nose2/tests/unit/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_fail(self):
assert False

def test_err(self):
1 / 0
1 / 0 # noqa: B018 useless expression

def test_skip(self):
self.skipTest("skip")
Expand Down
4 changes: 2 additions & 2 deletions nose2/tests/unit/test_layers_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test(self):
self.plugin.startTestRun(event)

def names(self, suite):
return [n for n in self.iternames(suite)]
return list(self.iternames(suite))

def iternames(self, suite):
for t in suite:
Expand All @@ -434,7 +434,7 @@ def iternames(self, suite):
test_method = t._testMethodName
yield f"{test_method} ({test_module}.{test_class})"
else:
yield [n for n in self.iternames(t)]
yield list(self.iternames(t))

def _listset(self, lst):
n = set()
Expand Down
4 changes: 2 additions & 2 deletions nose2/tests/unit/test_testid_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def test___init__(self):
self.assertEqual(
val,
exp_val,
"Attribute %s should have value "
"'%s', but has value %s" % (name, exp_val, val),
"Attribute {} should have value "
"'{}', but has value {}".format(name, exp_val, val),
)

def test_start_test(self):
Expand Down
80 changes: 80 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[tool.ruff]
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"E", # pycodestyle
"EXE", # flake8-executable
"F", # Pyflakes
"I", # isort
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"PLE", # Pylint errors
"PLR091", # Pylint Refactor just for max-args, max-branches, etc.
"PYI", # flake8-pyi
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "A", # flake8-builtins
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "BLE", # flake8-blind-except
# "COM", # flake8-commas
# "D", # pydocstyle
# "DJ", # flake8-django
# "DTZ", # flake8-datetimez
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "FBT", # flake8-boolean-trap
# "G", # flake8-logging-format
# "INP", # flake8-no-pep420
# "ISC", # flake8-implicit-str-concat
# "N", # pep8-naming
# "NPY", # NumPy-specific rules
# "PD", # pandas-vet
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib
# "Q", # flake8-quotes
# "RET", # flake8-return
# "S", # flake8-bandit
# "SIM", # flake8-simplify
# "SLF", # flake8-self
# "T10", # flake8-debugger
# "T20", # flake8-print
# "TRY", # tryceratops
]
ignore = [
"B904",
"RUF005",
"RUF100"
]
target-version = "py37"

[tool.ruff.isort]
known-third-party = [
"coverage",
"mock",
"six",
]

[tool.ruff.mccabe]
max-complexity = 15

[tool.ruff.pylint]
max-args = 9
max-branches = 15
max-statements = 66

[tool.ruff.per-file-ignores]
"nose2/tests/*" = ["B011"]
# FIXME: resolving these could change behavior -- do it in a separate
# cleanup and note it in the changelog
"nose2/plugins/loader/*.py" = ["B004"]
"nose2/plugins/mp.py" = ["UP031"]
"nose2/tests/functional/support/such/test_regression_same_havings.py" = ["EXE001"]
15 changes: 0 additions & 15 deletions setup.cfg

This file was deleted.