From 919bd3abe46aca3362315840c1028e313904e9db Mon Sep 17 00:00:00 2001 From: eggplants Date: Wed, 16 Mar 2022 05:28:11 +0900 Subject: [PATCH 1/6] fix: black hook in pre-commit and config --- .pre-commit-config.yaml | 15 ++------------- docs/developers.rst | 3 +-- pyproject.toml | 2 -- rdflib/plugins/stores/berkeleydb.py | 15 ++++++--------- requirements.dev.txt | 3 +-- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8416add51..a21e71808 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,21 +14,10 @@ repos: pass_filenames: false require_serial: true args: ["."] - - repo: local + - repo: https://github.com/psf/black + rev: 22.1.0 hooks: - # using a local hook for black because of an issue that arises when using - # pre-commit and setuptools-scm that results in version info being lost. - # For more info see https://github.com/psf/black/issues/2493 - # Based on https://github.com/psf/black/blob/main/.pre-commit-hooks.yaml - id: black - name: black - description: "Black: The uncompromising Python code formatter" - entry: black - language: python - # WARNING: version should be the same as in `pyproject.toml`. - additional_dependencies: [black==21.9b0] - # This is here to defer file selection to black which will do it based on - # black config. pass_filenames: false require_serial: true args: ["."] diff --git a/docs/developers.rst b/docs/developers.rst index dadb413cf..dcd960319 100644 --- a/docs/developers.rst +++ b/docs/developers.rst @@ -10,8 +10,7 @@ This document describes the process and conventions to follow when developing RDFLib code. * Please be as Pythonic as possible (:pep:`8`). -* Code should be formatted using `black `_ - and we use Black v21.9b0, with the black.toml config file provided. +* Code should be formatted using `black `_. * Code should also pass `flake8 `_ linting and `mypy `_ type checking. * You must supply tests for new code diff --git a/pyproject.toml b/pyproject.toml index 07f9c4678..5c6c2c605 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,4 @@ [tool.black] -# WARNING: This should be the same as in `.pre-commit-config.yaml`. -required-version = "21.9b0" line-length = "88" skip-string-normalization = true target-version = ['py37'] diff --git a/rdflib/plugins/stores/berkeleydb.py b/rdflib/plugins/stores/berkeleydb.py index 77603aa83..511d33dfb 100644 --- a/rdflib/plugins/stores/berkeleydb.py +++ b/rdflib/plugins/stores/berkeleydb.py @@ -300,15 +300,12 @@ def add(self, triple, context, quoted=False, txn=None): def __remove(self, spo, c, quoted=False, txn=None): s, p, o = spo cspo, cpos, cosp = self.__indicies - contexts_value = ( - cspo.get( - "^".encode("latin-1").join( - ["".encode("latin-1"), s, p, o, "".encode("latin-1")] - ), - txn=txn, - ) - or "".encode("latin-1") - ) + contexts_value = cspo.get( + "^".encode("latin-1").join( + ["".encode("latin-1"), s, p, o, "".encode("latin-1")] + ), + txn=txn, + ) or "".encode("latin-1") contexts = set(contexts_value.split("^".encode("latin-1"))) contexts.discard(c) contexts_value = "^".encode("latin-1").join(contexts) diff --git a/requirements.dev.txt b/requirements.dev.txt index 4843b4dd3..3d63cfa77 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,8 +1,7 @@ -black==21.9b0 +black coverage doctest-ignore-unicode==0.1.2 flake8 -flake8-black html5lib isort mypy From 71a373b001df36dfb16199456ef308e441242ce5 Mon Sep 17 00:00:00 2001 From: eggplants Date: Wed, 16 Mar 2022 06:42:17 +0900 Subject: [PATCH 2/6] Update requirements.dev.txt Co-authored-by: Iwan Aucamp --- requirements.dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.dev.txt b/requirements.dev.txt index 3d63cfa77..a4626d1f1 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -2,6 +2,7 @@ black coverage doctest-ignore-unicode==0.1.2 flake8 +flake8-black html5lib isort mypy From 90bf6b1a40fc5e33de05d7e747e838ff6a638719 Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Wed, 16 Mar 2022 11:38:30 +1000 Subject: [PATCH 3/6] stable black range --- requirements.dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.dev.txt b/requirements.dev.txt index a4626d1f1..3458f08aa 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,4 +1,4 @@ -black +black>=22.0,<23 coverage doctest-ignore-unicode==0.1.2 flake8 From a2a1c115b5ad2514f57717f68de7114739fcca7b Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Wed, 16 Mar 2022 12:40:13 +1000 Subject: [PATCH 4/6] re-add req. version --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 5c6c2c605..76b1177ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,5 @@ [tool.black] +required-version = "22" line-length = "88" skip-string-normalization = true target-version = ['py37'] From 41c51415d0ef11acb184d4442dc82a88fee73b57 Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Wed, 16 Mar 2022 22:35:13 +0100 Subject: [PATCH 5/6] Use a fixed version of black instead of a range. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seems at least for me black wants an exact version ```console $ .venv/bin/black --version black, 22.1.0 (compiled: yes) $ .venv/bin/black rdflib Oh no! 💥 💔 💥 The required version `22` does not match the running version `22.1.0`! $ .venv/bin/black --required-version 22 rdflib Oh no! 💥 💔 💥 The required version `22` does not match the running version `22.1.0`! $ .venv/bin/black --required-version 22.1.0 rdflib All done! ✨ 🍰 ✨ 116 files left unchanged. ``` Also revert back to the local hook for pre-commit as this is needed when using a fixed version. --- .pre-commit-config.yaml | 15 +++++++++++++-- docs/developers.rst | 2 +- pyproject.toml | 2 +- requirements.dev.txt | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a21e71808..c63c37280 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,10 +14,21 @@ repos: pass_filenames: false require_serial: true args: ["."] - - repo: https://github.com/psf/black - rev: 22.1.0 + - repo: local hooks: + # using a local hook for black because of an issue that arises when using + # pre-commit and setuptools-scm that results in version info being lost. + # For more info see https://github.com/psf/black/issues/2493 + # Based on https://github.com/psf/black/blob/main/.pre-commit-hooks.yaml - id: black + name: black + description: "Black: The uncompromising Python code formatter" + entry: black + language: python + # WARNING: version should be the same as in `pyproject.toml` and `requirements.dev.txt`. + additional_dependencies: ["black>=22.0,<23"] + # This is here to defer file selection to black which will do it based on + # black config. pass_filenames: false require_serial: true args: ["."] diff --git a/docs/developers.rst b/docs/developers.rst index dcd960319..adee0de44 100644 --- a/docs/developers.rst +++ b/docs/developers.rst @@ -10,7 +10,7 @@ This document describes the process and conventions to follow when developing RDFLib code. * Please be as Pythonic as possible (:pep:`8`). -* Code should be formatted using `black `_. +* Code should be formatted using `black `_ and we use Black v21.9b0, with the black config in ``pyproject.toml``. * Code should also pass `flake8 `_ linting and `mypy `_ type checking. * You must supply tests for new code diff --git a/pyproject.toml b/pyproject.toml index 76b1177ac..0b272327f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.black] -required-version = "22" +required-version = "22.1.0" line-length = "88" skip-string-normalization = true target-version = ['py37'] diff --git a/requirements.dev.txt b/requirements.dev.txt index 3458f08aa..afd61309e 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,4 +1,4 @@ -black>=22.0,<23 +black==22.1.0 coverage doctest-ignore-unicode==0.1.2 flake8 From 9abbbcb35fc99558616091490c7c9c15d5b7a3ee Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 17 Mar 2022 10:31:33 +0900 Subject: [PATCH 6/6] Fix black version in developers.rst --- docs/developers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/developers.rst b/docs/developers.rst index adee0de44..f89481808 100644 --- a/docs/developers.rst +++ b/docs/developers.rst @@ -10,7 +10,7 @@ This document describes the process and conventions to follow when developing RDFLib code. * Please be as Pythonic as possible (:pep:`8`). -* Code should be formatted using `black `_ and we use Black v21.9b0, with the black config in ``pyproject.toml``. +* Code should be formatted using `black `_ and we use Black v22.1.0, with the black config in ``pyproject.toml``. * Code should also pass `flake8 `_ linting and `mypy `_ type checking. * You must supply tests for new code