build: replace Flake8, FlakeHeaven and isort with ruff (#2548) · RDFLib/rdflib@dfe0c21 (original) (raw)
File tree
99 files changed
lines changed
- plugins/parser/example/rdflib/plugin/parser
99 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -42,15 +42,13 @@ jobs: | ||
42 | 42 | TOXENV_SUFFIX: "-min" |
43 | 43 | - python-version: "3.9" |
44 | 44 | os: ubuntu-latest |
45 | -TOX_EXTRA_COMMAND: "- isort --check-only --diff ." | |
46 | 45 | TOXENV_SUFFIX: "-docs" |
47 | 46 | - python-version: "3.10" |
48 | 47 | os: ubuntu-latest |
49 | 48 | TOX_EXTRA_COMMAND: "- black --check --diff ./rdflib" |
50 | 49 | TOXENV_SUFFIX: "-lxml" |
51 | 50 | - python-version: "3.11" |
52 | 51 | os: ubuntu-latest |
53 | -TOX_EXTRA_COMMAND: "flake8 --exit-zero rdflib" | |
54 | 52 | TOXENV_SUFFIX: "-docs" |
55 | 53 | PREPARATION: "sudo apt-get install -y firejail" |
56 | 54 | extensive-tests: true |
@@ -121,7 +119,7 @@ jobs: | ||
121 | 119 | fail-fast: false |
122 | 120 | matrix: |
123 | 121 | include: |
124 | - - task: "gha:flake8" | |
122 | + - task: "gha:lint" | |
125 | 123 | python-version: 3.8 |
126 | 124 | steps: |
127 | 125 | - uses: actions/checkout@v3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,15 +6,11 @@ ci: | ||
6 | 6 | |
7 | 7 | # https://pre-commit.com/#adding-pre-commit-plugins-to-your-project |
8 | 8 | repos: |
9 | - - repo: https://github.com/pycqa/isort | |
10 | -rev: 5.11.5 | |
9 | + - repo: https://github.com/astral-sh/ruff-pre-commit | |
10 | +rev: v0.0.286 | |
11 | 11 | hooks: |
12 | - - id: isort | |
13 | -# This is here to defer file selection to isort which will do it based on | |
14 | -# black config. | |
15 | -pass_filenames: false | |
16 | -require_serial: true | |
17 | -args: ["."] | |
12 | + - id: ruff | |
13 | +args: ["--fix"] | |
18 | 14 | - repo: https://github.com/psf/black |
19 | 15 | # WARNING: version should be the same as in `pyproject.toml` |
20 | 16 | # Using git ref spec because of https://github.com/psf/black/issues/2493 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -111,17 +111,10 @@ tasks: | ||
111 | 111 | desc: Run tests |
112 | 112 | cmds: |
113 | 113 | - '{{.TEST_HARNESS}}{{.RUN_PREFIX}} pytest {{if (mustFromJson .WITH_COVERAGE)}}--cov --cov-report={{end}} {{.CLI_ARGS}}' |
114 | -flake8: | |
115 | -desc: Run flake8 | |
114 | +ruff: | |
115 | +desc: Run ruff | |
116 | 116 | cmds: |
117 | - - | | |
118 | - if {{.VENV_PYTHON}} -c 'import importlib.util; exit(0 if importlib.util.find_spec("flakeheaven") is not None else 1)' | |
119 | - then | |
120 | - 1>&2 echo "running flakeheaven" | |
121 | - {{.VENV_PYTHON}} -m flakeheaven lint {{.CLI_ARGS}} | |
122 | - else | |
123 | - 1>&2 echo "skipping flakeheaven as it is not installed, likely because python version is older than 3.8" | |
124 | - fi | |
117 | + - '{{.RUN_PREFIX}} ruff check {{if (mustFromJson (.FIX | default "false"))}}--fix {{end}}{{.CLI_ARGS | |
125 | 118 | black: |
126 | 119 | desc: Run black |
127 | 120 | cmds: |
@@ -145,17 +138,16 @@ tasks: | ||
145 | 138 | lint:fix: |
146 | 139 | desc: Fix auto-fixable linting errors |
147 | 140 | cmds: |
148 | - - task: isort | |
141 | + - task: ruff | |
142 | +vars: { FIX: true } | |
149 | 143 | - task: black |
150 | 144 | |
151 | 145 | lint: |
152 | 146 | desc: Perform linting |
153 | 147 | cmds: |
154 | - - task: isort | |
155 | -vars: { CHECK: true } | |
156 | 148 | - task: black |
157 | 149 | vars: { CHECK: true } |
158 | - - task: flake8 | |
150 | + - task: ruff | |
159 | 151 | |
160 | 152 | validate:static: |
161 | 153 | desc: Perform static validation |
@@ -265,13 +257,13 @@ tasks: | ||
265 | 257 | COVERAGE_FILE: ".coverage" |
266 | 258 | - cmd: coveralls |
267 | 259 | |
268 | -gha:flake8: | |
269 | -desc: GitHub Actions flake8 workflow | |
260 | +gha:lint: | |
261 | +desc: GitHub Actions lint workflow | |
270 | 262 | cmds: |
271 | 263 | - task: poetry:configure |
272 | 264 | vars: |
273 | -CLI_ARGS: --no-root --only=flake8 | |
274 | - - task: flake8 | |
265 | +CLI_ARGS: --no-root --only=lint | |
266 | + - task: ruff | |
275 | 267 | |
276 | 268 | cmd:rdfpipe: |
277 | 269 | desc: Run rdfpipe |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -40,7 +40,8 @@ Some ways in which you can contribute to RDFLib are: | ||
40 | 40 | [\](https://gitter.im/RDFLib/rdflib?utm\_source=badge&utm\_medium=badge&utm\_campaign=pr-badge) [\](https://matrix.to/#/#RDFLib\_rdflib:gitter.im) |
41 | 41 | - Participate in GitHub discussions: |
42 | 42 | [\](https://github.com/RDFLib/rdflib/discussions) |
43 | -- Fix flake8 failures. | |
43 | +- Fix linting failures (see ruff settings in `pyproject.toml` and `# | |
44 | + noqa:` directives in the codebase). | |
44 | 45 | |
45 | 46 | ## Pull Requests |
46 | 47 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -46,7 +46,7 @@ def example_1(): | ||
46 | 46 | print("(will always be 0 when using temp file for DB)") |
47 | 47 | |
48 | 48 | # Now we'll add some triples to the graph & commit the changes |
49 | -EG = Namespace("http://example.net/test/") | |
49 | +EG = Namespace("http://example.net/test/") # noqa: N806 | |
50 | 50 | graph.bind("eg", EG) |
51 | 51 | |
52 | 52 | graph.add((EG["pic:1"], EG.name, Literal("Jane & Bob"))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -20,7 +20,7 @@ | ||
20 | 20 | # Create a complex number RDFlib Literal |
21 | 21 | EG = Namespace("http://example.com/") |
22 | 22 | c = complex(2, 3) |
23 | -l = Literal(c) | |
23 | +l = Literal(c) # noqa: E741 | |
24 | 24 | |
25 | 25 | # Add it to a graph |
26 | 26 | g = Graph() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -31,7 +31,7 @@ | ||
31 | 31 | ) # any number of rdfs.subClassOf |
32 | 32 | |
33 | 33 | |
34 | -def customEval(ctx, part): | |
34 | +def customEval(ctx, part): # noqa: N802 | |
35 | 35 | """ |
36 | 36 | Rewrite triple patterns to get super-classes |
37 | 37 | """ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -249,22 +249,22 @@ def infixowl_example(): | ||
249 | 249 | disjointWith=[CPR["physical-therapy"], CPR["psychological-therapy"]], |
250 | 250 | ) |
251 | 251 | therapy += medicalTherapy |
252 | -medicalTherapy += Class(CPR["substance-administration"]) | |
252 | +medicalTherapy += Class(CPR["substance-administration"]) # noqa: N806 | |
253 | 253 | |
254 | 254 | diagnosticAct = Class(CPR["diagnostic-act"], subClassOf=[clinicalAct]) # noqa: N806 |
255 | 255 | diagnosticAct.disjointWith = [CPR["therapeutic-act"]] |
256 | 256 | |
257 | 257 | screeningAct = Class(CPR["screening-act"]) # noqa: N806 |
258 | -screeningAct += Class(CPR["laboratory-test"]) | |
258 | +screeningAct += Class(CPR["laboratory-test"]) # noqa: N806 | |
259 | 259 | |
260 | -diagnosticAct += screeningAct | |
260 | +diagnosticAct += screeningAct # noqa: N806 | |
261 | 261 | |
262 | -screeningAct += Class( | |
262 | +screeningAct += Class( # noqa: N806 | |
263 | 263 | CPR["medical-history-screening-act"], |
264 | 264 | disjointWith=[CPR["clinical-examination"], CPR["laboratory-test"]], |
265 | 265 | ) |
266 | 266 | |
267 | -screeningAct += Class( | |
267 | +screeningAct += Class( # noqa: N806 | |
268 | 268 | CPR["clinical-examination"], |
269 | 269 | disjointWith=[CPR["laboratory-test"], CPR["medical-history-screening-act"]], |
270 | 270 | ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -34,7 +34,7 @@ | ||
34 | 34 | g = Graph() |
35 | 35 | g.parse(f"{EXAMPLES_DIR / 'smushingdemo.n3'}", format="n3") |
36 | 36 | |
37 | -newURI = {} # old subject : stable uri | |
37 | +newURI = {} # old subject : stable uri # noqa: N816 | |
38 | 38 | for s, p, o in g.triples((None, FOAF["mbox_sha1sum"], None)): |
39 | 39 | # For this graph, all objects are Identifiers, which is a subclass of |
40 | 40 | # string. `n3` does allow for objects which are not Identifiers, like |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -14,7 +14,7 @@ | ||
14 | 14 | # Think of it as a blank piece of graph paper! |
15 | 15 | |
16 | 16 | primer = ConjunctiveGraph() |
17 | -myNS = Namespace("https://example.com/") | |
17 | +myNS = Namespace("https://example.com/") # noqa: N816 | |
18 | 18 | |
19 | 19 | primer.add((myNS.pat, myNS.knows, myNS.jo)) |
20 | 20 | # or: |
@@ -96,7 +96,7 @@ | ||
96 | 96 | |
97 | 97 | :Woman = foo:FemaleAdult . |
98 | 98 | :Title a rdf:Property; = dc:title . |
99 | - """ # --- End of primer code | |
99 | + """ # --- End of primer code # noqa: N816 | |
100 | 100 | |
101 | 101 | # To make this go easier to spit back out... |
102 | 102 | # technically, we already created a namespace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -49,10 +49,10 @@ | ||
49 | 49 | person = URIRef("ex:person") |
50 | 50 | dad = URIRef("ex:d") |
51 | 51 | mom = URIRef("ex:m") |
52 | -momOfDad = URIRef("ex:gm0") | |
53 | -momOfMom = URIRef("ex:gm1") | |
54 | -dadOfDad = URIRef("ex:gf0") | |
55 | -dadOfMom = URIRef("ex:gf1") | |
52 | +momOfDad = URIRef("ex:gm0") # noqa: N816 | |
53 | +momOfMom = URIRef("ex:gm1") # noqa: N816 | |
54 | +dadOfDad = URIRef("ex:gf0") # noqa: N816 | |
55 | +dadOfMom = URIRef("ex:gf1") # noqa: N816 | |
56 | 56 | |
57 | 57 | parent = URIRef("ex:parent") |
58 | 58 |