Skip to content

Instantly share code, notes, and snippets.

@aucampia
Last active August 27, 2023 19:36
Show Gist options
  • Save aucampia/abe1c139c52fb9c2f164f5332155634d to your computer and use it in GitHub Desktop.
Save aucampia/abe1c139c52fb9c2f164f5332155634d to your computer and use it in GitHub Desktop.

Generated with:

task run -- python -m pip install --upgrade strip-hints black python-minifier
PYLOGGING_LEVEL=INFO task run -- git difftool -y -x $(readlink -f devtools/diffrtpy.py) upstream/main | tee /var/tmp/compact.diff

Changes to .flakeheaven.baseline and poetry.lock was removed by hand.

$ git log -1
commit 830a359b1caadeb9c7322bc9a9e048d6ca88443a (HEAD -> aucampia/20230827T1011-flake8, origin/aucampia/20230827T1011-flake8)
Author: Iwan Aucamp <aucampia@gmail.com>
Date:   Sun Aug 27 12:35:34 2023 +0000

    build: replace Flake8, FlakeHeaven and isort with ruff
    
    FlakeHeaven only supports Flake8 versions below 5.x, and flake8 itself
    is still fairly limited in its configurability.
    
    Ruff implements most of the features of isort, Flake8 and FlakeHeaven.
    It does not provide a baseline feature like FlakeHeaven, but it does
    have a feature for adding `# noqa:` directives to the code base, which
    was used after file specific ignores were configured for some errors.
    
    Ruff also has a fix feature which can be used to fix some errors, so
    this change also adds Ruff to the pre-commit config so that it can be
    triggered with `pre-commit.ci autofix`.
$ git log -1 upstream/main 
commit e75768745aee9ea256739b0f397e6978f192b123 (upstream/main)
Author: Iwan Aucamp <aucampia@gmail.com>
Date:   Sat Aug 26 10:20:01 2023 +0200

    test: add python variants to variant based tests (#2544)
    
    This change adds python based variants to the variant tests. The python
    based variants provide a `populate_graph` function that populates a
    passed graph with quads or triples. This provides for the ability to do
    more nuanced and narrow tests using variants.
    
    Other changes:
    
    - Add some more variants for `diverse_quads` that explicitly sets the
      datatype of strings.
    - Removed the hand coded `simple_triple` graph from `test/data.py` as
      this is now subsumed by `test/data/variants/simple_triple.py`.
--- a/.github/workflows/validate.yaml
+++ b/.github/workflows/validate.yaml
@@ -40,19 +40,17 @@
extensive-tests: true
suffix: "-min"
TOXENV_SUFFIX: "-min"
- python-version: "3.9"
os: ubuntu-latest
- TOX_EXTRA_COMMAND: "- isort --check-only --diff ."
TOXENV_SUFFIX: "-docs"
- python-version: "3.10"
os: ubuntu-latest
TOX_EXTRA_COMMAND: "- black --check --diff ./rdflib"
TOXENV_SUFFIX: "-lxml"
- python-version: "3.11"
os: ubuntu-latest
- TOX_EXTRA_COMMAND: "flake8 --exit-zero rdflib"
TOXENV_SUFFIX: "-docs"
PREPARATION: "sudo apt-get install -y firejail"
extensive-tests: true
TOX_TEST_HARNESS: "firejail --net=none --"
TOX_PYTEST_EXTRA_ARGS: "-m 'not webtest'"
@@ -119,11 +117,11 @@
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- - task: "gha:flake8"
+ - task: "gha:lint"
python-version: 3.8
steps:
- uses: actions/checkout@v3
- name: Cache XDG_CACHE_HOME
uses: actions/cache@v3
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -4,19 +4,15 @@
autoupdate_schedule: weekly
autofix_prs: false
# https://pre-commit.com/#adding-pre-commit-plugins-to-your-project
repos:
- - repo: https://github.com/pycqa/isort
- rev: 5.11.5
+ - repo: https://github.com/astral-sh/ruff-pre-commit
+ rev: v0.0.286
hooks:
- - id: isort
- # This is here to defer file selection to isort which will do it based on
- # black config.
- pass_filenames: false
- require_serial: true
- args: ["."]
+ - id: ruff
+ args: ["--fix"]
- repo: https://github.com/psf/black
# WARNING: version should be the same as in `pyproject.toml`
# Using git ref spec because of https://github.com/psf/black/issues/2493
rev: 'refs/tags/23.7.0:refs/tags/23.7.0'
hooks:
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -109,21 +109,14 @@
TOXENV: '{{if .TOX_PYTHON_VERSION}}py{{mustRegexReplaceAll "^([0-9]+)[.]([0-9]+).*" .TOX_PYTHON_VERSION "${1}${2}"}}{{if (mustFromJson .EXTENSIVE)}}-extensive{{end}}{{.TOXENV_SUFFIX | default ""}}{{end}}'
test:
desc: Run tests
cmds:
- '{{.TEST_HARNESS}}{{.RUN_PREFIX}} pytest {{if (mustFromJson .WITH_COVERAGE)}}--cov --cov-report={{end}} {{.CLI_ARGS}}'
- flake8:
- desc: Run flake8
- cmds:
- - |
- if {{.VENV_PYTHON}} -c 'import importlib.util; exit(0 if importlib.util.find_spec("flakeheaven") is not None else 1)'
- then
- 1>&2 echo "running flakeheaven"
- {{.VENV_PYTHON}} -m flakeheaven lint {{.CLI_ARGS}}
- else
- 1>&2 echo "skipping flakeheaven as it is not installed, likely because python version is older than 3.8"
- fi
+ ruff:
+ desc: Run ruff
+ cmds:
+ - '{{.RUN_PREFIX}} ruff check {{if (mustFromJson (.FIX | default "false"))}}--fix {{end}}{{.CLI_ARGS | default "."}}'
black:
desc: Run black
cmds:
- '{{.VENV_PYTHON}} -m black {{if (mustFromJson (.CHECK | default "false"))}}--check --diff {{end}}{{.CLI_ARGS | default "."}}'
isort:
@@ -143,21 +136,20 @@
cmds:
- "{{.RUN_PREFIX}} dmypy run {{.CLI_ARGS}}"
lint:fix:
desc: Fix auto-fixable linting errors
cmds:
- - task: isort
+ - task: ruff
+ vars: { FIX: true }
- task: black
lint:
desc: Perform linting
cmds:
- - task: isort
- vars: { CHECK: true }
- task: black
vars: { CHECK: true }
- - task: flake8
+ - task: ruff
validate:static:
desc: Perform static validation
cmds:
- task: lint
@@ -263,17 +255,17 @@
- task: tox
vars:
COVERAGE_FILE: ".coverage"
- cmd: coveralls
- gha:flake8:
- desc: GitHub Actions flake8 workflow
+ gha:lint:
+ desc: GitHub Actions lint workflow
cmds:
- task: poetry:configure
vars:
- CLI_ARGS: --no-root --only=flake8
- - task: flake8
+ CLI_ARGS: --no-root --only=lint
+ - task: ruff
cmd:rdfpipe:
desc: Run rdfpipe
cmds:
- cmd: "{{.VENV_PYTHON}} -m rdflib.tools.rdfpipe {{.CLI_ARGS}}"
--- a/docs/CONTRIBUTING.md
+++ b/docs/CONTRIBUTING.md
@@ -38,11 +38,12 @@
[![Wikidata: Q7276224](https://img.shields.io/badge/Wikidata-Q7276224-informational)](https://www.wikidata.org/wiki/Q7276224)
- Participate on Gitter/Matrix chat:
[![Gitter](https://badges.gitter.im/RDFLib/rdflib.svg)](https://gitter.im/RDFLib/rdflib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Matrix](https://img.shields.io/matrix/rdflib:matrix.org?label=matrix.org%20chat)](https://matrix.to/#/#RDFLib_rdflib:gitter.im)
- Participate in GitHub discussions:
[![GitHub Discussions](https://img.shields.io/github/discussions/RDFLib/rdflib)](https://github.com/RDFLib/rdflib/discussions)
-- Fix flake8 failures.
+- Fix linting failures (see ruff settings in `pyproject.toml` and `#
+ noqa:` directives in the codebase).
## Pull Requests
Contributions that involve changes to the RDFLib repository have to be made with
pull requests and should follow the [RDFLib developers guide](./developers.rst).
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -46,11 +46,10 @@
html5lib = {version = "^1.0", optional = true}
lxml = {version = "^4.3.0", optional = true}
[tool.poetry.group.dev.dependencies]
black = "23.7.0"
-isort = "^5.10.0"
mypy = "^1.1.0"
lxml-stubs = "^0.4.0"
[tool.poetry.group.tests.dependencies]
pytest = "^7.1.3"
@@ -64,14 +63,12 @@
myst-parser = "^2.0.0"
sphinxcontrib-apidoc = "^0.3.0"
sphinx-autodoc-typehints = "^1.17.1"
typing-extensions = "^4.5.0"
-[tool.poetry.group.flake8.dependencies]
-flake8 = {version = ">=4.0.1"} # flakeheaven is incompatible with flake8 >=5.0 (https://github.com/flakeheaven/flakeheaven/issues/132)
-flakeheaven = {version = "^3.2.1"}
-pep8-naming = {version = "^0.13.2"}
+[tool.poetry.group.lint.dependencies]
+ruff = "^0.0.286"
[tool.poetry.extras]
berkeleydb = ["berkeleydb"]
networkx = ["networkx"]
html = ["html5lib"]
@@ -79,46 +76,92 @@
[build-system]
requires = ["poetry-core>=1.4.0"]
build-backend = "poetry.core.masonry.api"
-[tool.flakeheaven]
-format = "grouped"
-baseline = ".flakeheaven.baseline"
-
-[tool.flakeheaven.plugins]
-pycodestyle = [
- "+*",
- # mirrored from setup.cfg
- "-E501",
- "-E203",
- "-W503",
- "-E231",
-]
-pyflakes = [
- "+*",
-]
-pep8-naming = ["+*"]
-
-[tool.flakeheaven.exceptions."rdflib/plugins/sparql/*"]
-pep8-naming = ["-N802", "-N803", "-N806", "-N812", "-N816", "-N801"]
-[tool.flakeheaven.exceptions."rdflib/namespace/_*"]
-pep8-naming = ["-N815"]
-[tool.flakeheaven.exceptions."rdflib/plugins/parsers/notation3.py"]
-pep8-naming = ["-N802", "-N803", "-N806", "-N816"]
-[tool.flakeheaven.exceptions."rdflib/plugins/serializers/turtle.py"]
-pep8-naming = ["-N802", "-N806", "-N815"]
-[tool.flakeheaven.exceptions."rdflib/__init__.py"]
-pycodestyle = ["-E402"]
-[tool.flakeheaven.exceptions."test/utils/namespace/_*"]
-pep8-naming = ["-N815"]
-[tool.flakeheaven.exceptions."rdflib/plugins/parsers/rdfxml.py"]
-pep8-naming = ["-N802"]
-[tool.flakeheaven.exceptions."rdflib/plugins/parsers/trix.py"]
-pep8-naming = ["-N802"]
-[tool.flakeheaven.exceptions."docs/*.rst"]
-pyflakes = ["-F821"]
+[tool.ruff]
+# https://beta.ruff.rs/docs/configuration/
+target-version = "py38"
+select = [
+ "E", # pycodestyle errors
+ "W", # pycodestyle warnings
+ "F", # Pyflakes
+ "I", # isort
+ "N", # pep8-naming
+]
+
+ignore = [
+ "E501", # line too long:
+ # Disabled based on black recommendations
+ # https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated
+ "E203", # whitespace before ':'
+ "E231", # missing whitespace after ','
+ "E402", # Module level import not at top of file
+]
+
+# Same as Black.
+line-length = 88
+
+[tool.ruff.per-file-ignores]
+"rdflib/plugins/sparql/*" = [
+ "N801", # Class name should be UpperCamelCase
+ "N802", # Function name should be lowercase
+ "N803", # Argument name should be lowercase
+ "N806", # Variable in function should be lowercase
+ "N812", # Lowercase imported as non lowercase
+ "N816", # Variable in class scope should be mixedCase
+]
+"rdflib/namespace/_*" = [
+ "N815", # Variable in class scope should not be mixedCase
+ "N999", # Invalid module name
+]
+"rdflib/plugins/parsers/{trix,rdfxml,notation3}.py" = [
+ "N802", # Function name should be lowercase
+ "N803", # Argument name should be lowercase
+ "N806", # Variable in function should be lowercase
+ "N816", # Variable in class scope should be mixedCase
+]
+"rdflib/extras/infixowl.py" = [
+ "N803", # Function name should be lowercase
+]
+"rdflib/plugins/serializers/{turtle,longturtle,trig}.py" = [
+ "N802", # Function name should be lowercase
+ "N806", # Variable in function should be lowercase
+ "N815", # Variable in class scope should not be mixedCase
+]
+"rdflib/plugins/stores/sparqlstore.py" = [
+ "N803", # Argument name should be lowercase
+]
+"test/utils/namespace/_*" = [
+ "N815", # Variable in class scope should not be mixedCase
+ "N999", # Invalid module name
+]
+"test/test_sparql/test_{initbindings,datetime_processing,expressions}.py" = [
+ "N802", # Function name should be lowercase
+ "N806", # Variable in function should be lowercase
+]
+"test/test_store/test_store_sparql*.py" = [
+ "N802", # Function name should be lowercase
+]
+"test/test_serializers/test_{prettyxml,serializer_turtle,serializer_xml}.py" = [
+ "N802", # Function name should be lowercase
+ "N803", # Function name should be lowercase
+ "N806", # Variable in function should be lowercase
+ "N815", # Variable in class scope should not be mixedCase
+]
+"test/test_literal/test_uriref_literal_comparison.py" = [
+ "N802", # Function name should be lowercase
+]
+"test/test_nt_misc.py" = [
+ "N802", # Function name should be lowercase
+ "N806", # Variable in function should be lowercase
+]
+"test/test_graph/test_{container,graph_context,aggregate_graphs}.py" = [
+ "N802", # Function name should be lowercase
+ "N806", # Variable in function should be lowercase
+ "N816", # Variable in class scope should be mixedCase
+]
[tool.black]
required-version = "23.7.0"
line-length = "88"
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,28 +1,2 @@
[options.package_data]
rdflib = py.typed
-
-# https://flake8.pycqa.org/en/latest/user/configuration.html
-[flake8]
-exclude =
- .git,
- __pycache__,
- .venv,
- .var,
- .tox,
- var,
- .mypy_cache,
- test/data/suites/, # does not contain python
- test/jsonld/1.1/, # does not contain python
- test/jsonld/test-suite/, # does not contain python
- test/data/variants/, # does not contain python
- test/data/translate_algebra/, # does not contain python
- docs/rdf_terms.rst, # This file is causing an error on GitHub actions
-extend-ignore =
- # Disabled so that black can control line length.
- E501, # line too long
- # Disabled based on black recommendations
- # https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated
- E203, # Whitespace before ':'
- W503, # Line break occurred before a binary operator
- # Disabled because this bumps heads with black
- E231, # missing whitespace after ','
--- a/tox.ini
+++ b/tox.ini
@@ -1,10 +1,10 @@
# https://tox.wiki/en/latest/user_guide.html
# https://tox.wiki/en/latest/config.html
[tox]
envlist =
- flake8,py3{7,8,9,10,11},covreport,docs,precommit
+ lint,py3{7,8,9,10,11},covreport,docs,precommit
isolated_build = True
toxworkdir={env:TOX_WORK_DIR:{tox_root}/.tox}
[testenv]
passenv =
@@ -18,11 +18,11 @@
extensive: POETRY_ARGS_extensive = --extras=berkeleydb --extras=networkx --extras=html
lxml: POETRY_ARGS_lxml = --extras=lxml
commands_pre =
py3{7,8,9,10,11}: python -c 'import os; print("\n".join(f"{key}={value}" for key, value in os.environ.items()))'
py3{7,8,9,10,11}: poetry lock --check
- py3{7,8,9,10,11}: poetry install --no-root --only=main --only=dev --only=flake8 --only=tests {env:POETRY_ARGS_docs:} {env:POETRY_ARGS_extensive:} {env:POETRY_ARGS_lxml:} {env:POETRY_ARGS:} --sync
+ py3{7,8,9,10,11}: poetry install --no-root --only=main --only=dev --only=lint --only=tests {env:POETRY_ARGS_docs:} {env:POETRY_ARGS_extensive:} {env:POETRY_ARGS_lxml:} {env:POETRY_ARGS:} --sync
commands =
{env:TOX_EXTRA_COMMAND:}
{env:TOX_MYPY_COMMAND:poetry run python -m mypy --show-error-context --show-error-codes --junit-xml=test_reports/{env:TOX_JUNIT_XML_PREFIX:}mypy-junit.xml}
{posargs:poetry run {env:TOX_TEST_HARNESS:} pytest -ra --tb=native {env:TOX_PYTEST_ARGS:--junit-xml=test_reports/{env:TOX_JUNIT_XML_PREFIX:}pytest-junit.xml --cov --cov-report=} {env:TOX_PYTEST_EXTRA_ARGS:}}
docs: poetry run sphinx-build -T -W -b html -d {envdir}/doctree docs docs/_build/html
@@ -37,16 +37,16 @@
poetry install --no-root --only=tests
commands =
poetry run python -m coverage combine
poetry run python -m coverage report
-[testenv:flake8]
+[testenv:lint]
skip_install = true
commands_pre =
- poetry install --no-root --only=flake8
+ poetry install --no-root --only=lint
commands =
- poetry run python -m flakeheaven lint
+ poetry run ruff .
[testenv:docs]
passenv =
TERM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment