diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index c7bda6f4..2b8b9fce 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -28,8 +28,11 @@ jobs: - name: Install Python dependencies run: poetry install - - name: Linting with Pylint - run: poetry run pylint dsp_permissions_scripts tests + - name: Formatting with ruff + run: poetry run ruff format . + + - name: Linting with ruff + run: poetry run ruff check . - name: Linting with mypy run: poetry run mypy . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..6e9a8e4f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,44 @@ +# Configuration of https://pre-commit.com/ + +repos: + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.7 + hooks: + - id: ruff + # args: [ + # --ignore=A002, + # --ignore=D101, + # --ignore=D102, + # --ignore=PLR0913, + # --ignore=PLR2004, + # --ignore=PLW0603, + # ] + - id: ruff-format + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: check-merge-conflict + - id: no-commit-to-branch + args: [--branch, main] + - id: fix-byte-order-marker + - id: detect-private-key + - id: check-symlinks + - id: destroyed-symlinks + - id: mixed-line-ending + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-check-blanket-noqa + - id: python-check-blanket-type-ignore + - id: python-check-mock-methods + - id: python-no-eval + - id: python-no-log-warn + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + - id: text-unicode-replacement-char diff --git a/dsp_permissions_scripts/ap/ap_serialize.py b/dsp_permissions_scripts/ap/ap_serialize.py index df863f28..ec132c58 100644 --- a/dsp_permissions_scripts/ap/ap_serialize.py +++ b/dsp_permissions_scripts/ap/ap_serialize.py @@ -27,7 +27,7 @@ def serialize_aps_of_project( aps_as_dict = {explanation_string: aps_as_dicts} with open(filepath, mode="w", encoding="utf-8") as f: f.write(json.dumps(aps_as_dict, ensure_ascii=False, indent=2)) - logger.info(f"{len(project_aps)} APs have been written to file {str(filepath)}") + logger.info(f"{len(project_aps)} APs have been written to file {filepath}") def deserialize_aps_of_project( @@ -38,5 +38,5 @@ def deserialize_aps_of_project( filepath = _get_file_path(shortcode, mode) with open(filepath, mode="r", encoding="utf-8") as f: aps_as_dict = json.load(f) - aps_as_dicts = list(aps_as_dict.values())[0] + aps_as_dicts = next(iter(aps_as_dict.values())) return [Ap.model_validate(d) for d in aps_as_dicts] diff --git a/dsp_permissions_scripts/doap/doap_serialize.py b/dsp_permissions_scripts/doap/doap_serialize.py index ff09cdbd..0ca3f75e 100644 --- a/dsp_permissions_scripts/doap/doap_serialize.py +++ b/dsp_permissions_scripts/doap/doap_serialize.py @@ -31,7 +31,7 @@ def serialize_doaps_of_project( doaps_as_dict = {explanation_string: doaps_as_dicts} with open(filepath, mode="w", encoding="utf-8") as f: f.write(json.dumps(doaps_as_dict, ensure_ascii=False, indent=2)) - logger.info(f"{len(project_doaps)} DOAPs have been written to file {str(filepath)}") + logger.info(f"{len(project_doaps)} DOAPs have been written to file {filepath}") def deserialize_doaps_of_project( @@ -42,5 +42,5 @@ def deserialize_doaps_of_project( filepath = _get_file_path(shortcode, mode) with open(filepath, mode="r", encoding="utf-8") as f: doaps_as_dict = json.load(f) - doaps_as_dicts = list(doaps_as_dict.values())[0] + doaps_as_dicts = next(iter(doaps_as_dict.values())) return [Doap.model_validate(d) for d in doaps_as_dicts] diff --git a/dsp_permissions_scripts/oap/oap_serialize.py b/dsp_permissions_scripts/oap/oap_serialize.py index 46c5d7e0..9073342c 100644 --- a/dsp_permissions_scripts/oap/oap_serialize.py +++ b/dsp_permissions_scripts/oap/oap_serialize.py @@ -35,7 +35,7 @@ def serialize_oaps( for value_oap in oap.value_oaps: _serialize_oap(value_oap, folder) counter += 1 - logger.info(f"Successfully wrote {len(oaps)} OAPs into {counter} files in folder {str(folder)}") + logger.info(f"Successfully wrote {len(oaps)} OAPs into {counter} files in folder {folder}") def _serialize_oap(oap: ResourceOap | ValueOap, folder: Path) -> None: diff --git a/dsp_permissions_scripts/oap/oap_set.py b/dsp_permissions_scripts/oap/oap_set.py index a600e543..22492756 100644 --- a/dsp_permissions_scripts/oap/oap_set.py +++ b/dsp_permissions_scripts/oap/oap_set.py @@ -47,7 +47,7 @@ def _update_permissions_for_value( raise err from None -def _update_permissions_for_resource( +def _update_permissions_for_resource( # noqa: PLR0913 resource_iri: str, lmd: str | None, resource_type: str, diff --git a/dsp_permissions_scripts/utils/__init__.py b/dsp_permissions_scripts/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dsp_permissions_scripts/utils/dsp_client.py b/dsp_permissions_scripts/utils/dsp_client.py index 8e69881b..418af0c5 100644 --- a/dsp_permissions_scripts/utils/dsp_client.py +++ b/dsp_permissions_scripts/utils/dsp_client.py @@ -20,6 +20,8 @@ from dsp_permissions_scripts.utils.get_logger import get_logger from dsp_permissions_scripts.utils.helpers import PACKAGE_NAME +# ruff: noqa: PLR2004 (magic value used in comparison) + logger = get_logger(__name__) HTTP_OK = 200 diff --git a/dsp_permissions_scripts/utils/get_logger.py b/dsp_permissions_scripts/utils/get_logger.py index 72ac7606..eb70af32 100644 --- a/dsp_permissions_scripts/utils/get_logger.py +++ b/dsp_permissions_scripts/utils/get_logger.py @@ -47,5 +47,5 @@ def log_start_of_script(host: str, shortcode: str) -> None: logger.info("") print(f"\n{msg}") - logfile = [handler.baseFilename for handler in logger.handlers if isinstance(handler, logging.FileHandler)][0] + logfile = next(handler.baseFilename for handler in logger.handlers if isinstance(handler, logging.FileHandler)) print(f"There will be no print output, only logging to file {logfile}") diff --git a/dsp_permissions_scripts/utils/scope_serialization.py b/dsp_permissions_scripts/utils/scope_serialization.py index 73ecf96c..49feb052 100644 --- a/dsp_permissions_scripts/utils/scope_serialization.py +++ b/dsp_permissions_scripts/utils/scope_serialization.py @@ -10,7 +10,7 @@ def create_string_from_scope(perm_scope: PermissionScope) -> str: for perm_letter in perm_scope.model_fields: if groups := perm_scope.get(perm_letter): as_dict[perm_letter] = sort_groups(groups) - strs = [f"{k} {','.join([x.val for x in l])}" for k, l in as_dict.items()] + strs = [f"{k} {','.join([x.val for x in v])}" for k, v in as_dict.items()] return "|".join(strs) diff --git a/poetry.lock b/poetry.lock index 0a1e8c9d..e3701f28 100644 --- a/poetry.lock +++ b/poetry.lock @@ -11,61 +11,6 @@ files = [ {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, ] -[[package]] -name = "astroid" -version = "3.1.0" -description = "An abstract syntax tree for Python with inference support." -optional = false -python-versions = ">=3.8.0" -files = [ - {file = "astroid-3.1.0-py3-none-any.whl", hash = "sha256:951798f922990137ac090c53af473db7ab4e70c770e6d7fae0cec59f74411819"}, - {file = "astroid-3.1.0.tar.gz", hash = "sha256:ac248253bfa4bd924a0de213707e7ebeeb3138abeb48d798784ead1e56d419d4"}, -] - -[[package]] -name = "black" -version = "24.3.0" -description = "The uncompromising code formatter." -optional = false -python-versions = ">=3.8" -files = [ - {file = "black-24.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395"}, - {file = "black-24.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995"}, - {file = "black-24.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7"}, - {file = "black-24.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0"}, - {file = "black-24.3.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9"}, - {file = "black-24.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597"}, - {file = "black-24.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d"}, - {file = "black-24.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5"}, - {file = "black-24.3.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f"}, - {file = "black-24.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11"}, - {file = "black-24.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4"}, - {file = "black-24.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5"}, - {file = "black-24.3.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837"}, - {file = "black-24.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd"}, - {file = "black-24.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213"}, - {file = "black-24.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959"}, - {file = "black-24.3.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb"}, - {file = "black-24.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7"}, - {file = "black-24.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7"}, - {file = "black-24.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f"}, - {file = "black-24.3.0-py3-none-any.whl", hash = "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93"}, - {file = "black-24.3.0.tar.gz", hash = "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f"}, -] - -[package.dependencies] -click = ">=8.0.0" -mypy-extensions = ">=0.4.3" -packaging = ">=22.0" -pathspec = ">=0.9.0" -platformdirs = ">=2" - -[package.extras] -colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - [[package]] name = "certifi" version = "2024.2.2" @@ -77,6 +22,17 @@ files = [ {file = "certifi-2024.2.2.tar.gz", hash = "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f"}, ] +[[package]] +name = "cfgv" +version = "3.4.0" +description = "Validate configuration and produce human readable error messages." +optional = false +python-versions = ">=3.8" +files = [ + {file = "cfgv-3.4.0-py2.py3-none-any.whl", hash = "sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9"}, + {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, +] + [[package]] name = "charset-normalizer" version = "3.3.2" @@ -177,44 +133,45 @@ files = [ ] [[package]] -name = "click" -version = "8.1.7" -description = "Composable command line interface toolkit" +name = "distlib" +version = "0.3.8" +description = "Distribution utilities" optional = false -python-versions = ">=3.7" +python-versions = "*" files = [ - {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, - {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, + {file = "distlib-0.3.8-py2.py3-none-any.whl", hash = "sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784"}, + {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, ] -[package.dependencies] -colorama = {version = "*", markers = "platform_system == \"Windows\""} - [[package]] -name = "colorama" -version = "0.4.6" -description = "Cross-platform colored terminal text." +name = "filelock" +version = "3.13.4" +description = "A platform independent file lock." optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +python-versions = ">=3.8" files = [ - {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, - {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, + {file = "filelock-3.13.4-py3-none-any.whl", hash = "sha256:404e5e9253aa60ad457cae1be07c0f0ca90a63931200a47d9b6a6af84fd7b45f"}, + {file = "filelock-3.13.4.tar.gz", hash = "sha256:d13f466618bfde72bd2c18255e269f72542c6e70e7bac83a0232d6b1cc5c8cf4"}, ] +[package.extras] +docs = ["furo (>=2023.9.10)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "diff-cover (>=8.0.1)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)", "pytest-timeout (>=2.2)"] +typing = ["typing-extensions (>=4.8)"] + [[package]] -name = "dill" -version = "0.3.8" -description = "serialize all of Python" +name = "identify" +version = "2.5.35" +description = "File identification library for Python" optional = false python-versions = ">=3.8" files = [ - {file = "dill-0.3.8-py3-none-any.whl", hash = "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7"}, - {file = "dill-0.3.8.tar.gz", hash = "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca"}, + {file = "identify-2.5.35-py2.py3-none-any.whl", hash = "sha256:c4de0081837b211594f8e877a6b4fad7ca32bbfc1a9307fdd61c28bfe923f13e"}, + {file = "identify-2.5.35.tar.gz", hash = "sha256:10a7ca245cfcd756a554a7288159f72ff105ad233c7c4b9c6f0f4d108f5f6791"}, ] [package.extras] -graph = ["objgraph (>=1.7.2)"] -profile = ["gprof2dot (>=2022.7.29)"] +license = ["ukkonen"] [[package]] name = "idna" @@ -227,31 +184,6 @@ files = [ {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] -[[package]] -name = "isort" -version = "5.13.2" -description = "A Python utility / library to sort Python imports." -optional = false -python-versions = ">=3.8.0" -files = [ - {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, - {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, -] - -[package.extras] -colors = ["colorama (>=0.4.6)"] - -[[package]] -name = "mccabe" -version = "0.7.0" -description = "McCabe checker, plugin for flake8" -optional = false -python-versions = ">=3.6" -files = [ - {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, - {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, -] - [[package]] name = "mypy" version = "1.9.0" @@ -310,26 +242,18 @@ files = [ ] [[package]] -name = "packaging" -version = "24.0" -description = "Core utilities for Python packages" +name = "nodeenv" +version = "1.8.0" +description = "Node.js virtual environment builder" optional = false -python-versions = ">=3.7" +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" files = [ - {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"}, - {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, + {file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"}, + {file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"}, ] -[[package]] -name = "pathspec" -version = "0.12.1" -description = "Utility library for gitignore style pattern matching of file paths." -optional = false -python-versions = ">=3.8" -files = [ - {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"}, - {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"}, -] +[package.dependencies] +setuptools = "*" [[package]] name = "platformdirs" @@ -346,6 +270,24 @@ files = [ docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] +[[package]] +name = "pre-commit" +version = "3.7.0" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +optional = false +python-versions = ">=3.9" +files = [ + {file = "pre_commit-3.7.0-py2.py3-none-any.whl", hash = "sha256:5eae9e10c2b5ac51577c3452ec0a490455c45a0533f7960f993a0d01e59decab"}, + {file = "pre_commit-3.7.0.tar.gz", hash = "sha256:e209d61b8acdcf742404408531f0c37d49d2c734fd7cff2d6076083d191cb060"}, +] + +[package.dependencies] +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = ">=5.1" +virtualenv = ">=20.10.0" + [[package]] name = "pydantic" version = "2.6.4" @@ -456,30 +398,6 @@ files = [ [package.dependencies] typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" -[[package]] -name = "pylint" -version = "3.1.0" -description = "python code static checker" -optional = false -python-versions = ">=3.8.0" -files = [ - {file = "pylint-3.1.0-py3-none-any.whl", hash = "sha256:507a5b60953874766d8a366e8e8c7af63e058b26345cfcb5f91f89d987fd6b74"}, - {file = "pylint-3.1.0.tar.gz", hash = "sha256:6a69beb4a6f63debebaab0a3477ecd0f559aa726af4954fc948c51f7a2549e23"}, -] - -[package.dependencies] -astroid = ">=3.1.0,<=3.2.0-dev0" -colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} -dill = {version = ">=0.3.7", markers = "python_version >= \"3.12\""} -isort = ">=4.2.5,<5.13.0 || >5.13.0,<6" -mccabe = ">=0.6,<0.8" -platformdirs = ">=2.2.0" -tomlkit = ">=0.10.1" - -[package.extras] -spelling = ["pyenchant (>=3.2,<4.0)"] -testutils = ["gitpython (>3)"] - [[package]] name = "python-dotenv" version = "1.0.1" @@ -494,6 +412,55 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "pyyaml" +version = "6.0.1" +description = "YAML parser and emitter for Python" +optional = false +python-versions = ">=3.6" +files = [ + {file = "PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a"}, + {file = "PyYAML-6.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, + {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, + {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, + {file = "PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, + {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd"}, + {file = "PyYAML-6.0.1-cp36-cp36m-win32.whl", hash = "sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585"}, + {file = "PyYAML-6.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa"}, + {file = "PyYAML-6.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c"}, + {file = "PyYAML-6.0.1-cp37-cp37m-win32.whl", hash = "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba"}, + {file = "PyYAML-6.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867"}, + {file = "PyYAML-6.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, + {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, + {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, + {file = "PyYAML-6.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, + {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, + {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, +] + [[package]] name = "requests" version = "2.31.0" @@ -516,16 +483,47 @@ socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] -name = "tomlkit" -version = "0.12.4" -description = "Style preserving TOML library" +name = "ruff" +version = "0.3.7" +description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "tomlkit-0.12.4-py3-none-any.whl", hash = "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b"}, - {file = "tomlkit-0.12.4.tar.gz", hash = "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, + {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, + {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, + {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, + {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, ] +[[package]] +name = "setuptools" +version = "69.5.1" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "setuptools-69.5.1-py3-none-any.whl", hash = "sha256:c636ac361bc47580504644275c9ad802c50415c7522212252c033bd15f301f32"}, + {file = "setuptools-69.5.1.tar.gz", hash = "sha256:6c1fccdac05a97e598fb0ae3bbed5904ccb317337a51139dcd51453611bbb987"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mypy (==1.9)", "packaging (>=23.2)", "pip (>=19.1)", "pytest (>=6,!=8.1.1)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + [[package]] name = "types-requests" version = "2.31.0.20240406" @@ -568,7 +566,27 @@ h2 = ["h2 (>=4,<5)"] socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["zstandard (>=0.18.0)"] +[[package]] +name = "virtualenv" +version = "20.25.1" +description = "Virtual Python Environment builder" +optional = false +python-versions = ">=3.7" +files = [ + {file = "virtualenv-20.25.1-py3-none-any.whl", hash = "sha256:961c026ac520bac5f69acb8ea063e8a4f071bcc9457b9c1f28f6b085c511583a"}, + {file = "virtualenv-20.25.1.tar.gz", hash = "sha256:e08e13ecdca7a0bd53798f356d5831434afa5b07b93f0abdf0797b7a06ffe197"}, +] + +[package.dependencies] +distlib = ">=0.3.7,<1" +filelock = ">=3.12.2,<4" +platformdirs = ">=3.9.1,<5" + +[package.extras] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] + [metadata] lock-version = "2.0" python-versions = "^3.12.0" -content-hash = "e3bdc99905489e98e350e69efded6aa86c039ce48d29f9d8025cf631e8387926" +content-hash = "1a10cbba17cab64c9b73631fecdf215770aa7b1ec3df3cee1fdd162b50c352a5" diff --git a/pyproject.toml b/pyproject.toml index afedbff3..50674faf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,38 +16,49 @@ pydantic = "^2.6.4" mypy = "^1.9.0" types-requests = "^2.31.0.20240406" python-dotenv = "^1.0.1" -black = "^24.3.0" -pylint = "^3.1.0" -isort = "^5.13.2" +ruff = "^0.3.7" +pre-commit = "^3.7.0" [build-system] build-backend = "poetry.core.masonry.api" requires = ["poetry-core"] -[tool.pylint.MASTER] -extension-pkg-whitelist="pydantic" - -[tool.pylint.format] -max-line-length = 120 +[tool.ruff] +line-length = 120 +target-version = "py312" -[tool.pylint."messages control"] -disable = [ - "missing-module-docstring", - "missing-class-docstring", - "missing-function-docstring", - "invalid-name", - "trailing-whitespace", - "too-few-public-methods", - "logging-fstring-interpolation", +[tool.ruff.lint] +select = [ + "RUF", # ruff-specific rules + "PL", # pylint + "I", # isort + "E", # pycodestyle errors + "F", # pyflakes + "A", # flake8-builtins + "BLE", # flake8-blind-except + "ARG", # flake8-unused-arguments + "S", # flake8-bandit plugin which checks for security issues + "YTT", # flake8-2020 plugin, which checks for misuse of `sys.version` or `sys.version_info` + "ASYNC", # flake8-async plugin, which checks for bad async / asyncio practices + "ISC", # flake8-implicit-str-concat plugin, which checks for problematic string concatenation + "INP", # flake8-no-pep420 plugin, which checks for missing __init__.py files + "PIE", # flake8-pie plugin, which does miscellaneous checks + "PT", # flake8-pytest-style plugin + "TID", # flake8-tidy-imports plugin + "ICN", # flake8-import-conventions plugin, which checks for import conventions + "ARG", # flake8-unused-arguments + "PGH", # pygrep-hooks: A collection of fast, cheap, regex based pre-commit hooks + "UP031", # pyupgrade: printf-string-formatting + "B023", # flake8-bugbear: function-uses-loop-variable + "FIX", # flake8-fixme: checks for FIXME, TODO, XXX, etc. ] -[tool.black] -line-length = 120 +[tool.ruff.lint.pydocstyle] +convention = "google" -[tool.isort] -profile = "black" -force_single_line = true -line_length = 120 +[tool.ruff.lint.isort] +force-single-line = true +known-first-party = ["dsp_tools"] [tool.mypy] ignore_missing_imports = false diff --git a/tests/test_ap.py b/tests/test_ap.py index 6d69e120..b853eeb8 100644 --- a/tests/test_ap.py +++ b/tests/test_ap.py @@ -4,6 +4,8 @@ from dsp_permissions_scripts.ap.ap_model import ApValue from dsp_permissions_scripts.models import group +# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) +# ruff: noqa: PT027 (pytest-unittest-raises-assertion) (remove this line when pytest is used instead of unittest) class TestAp(unittest.TestCase): ap = Ap( diff --git a/tests/test_ap_serialization.py b/tests/test_ap_serialization.py index 8942c75b..3773d241 100644 --- a/tests/test_ap_serialization.py +++ b/tests/test_ap_serialization.py @@ -10,6 +10,7 @@ from dsp_permissions_scripts.models import group from dsp_permissions_scripts.models.host import Hosts +# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) class TestApSerialization(unittest.TestCase): shortcode = "1234" @@ -48,7 +49,7 @@ def test_serialize_aps_of_project(self) -> None: ) with open(self.output_file, mode="r", encoding="utf-8") as f: aps_file = json.load(f) - explanation_text = list(aps_file.keys())[0] + explanation_text = next(iter(aps_file.keys())) self.assertRegex(explanation_text, r"Project 1234 on host .+ has \d+ APs") aps_as_dicts = aps_file[explanation_text] self.assertEqual(self.ap1, Ap.model_validate(aps_as_dicts[0])) diff --git a/tests/test_doap_serialization.py b/tests/test_doap_serialization.py index 955ef9bb..ee21ff97 100644 --- a/tests/test_doap_serialization.py +++ b/tests/test_doap_serialization.py @@ -11,6 +11,7 @@ from dsp_permissions_scripts.models.scope import PermissionScope from tests.test_scope_serialization import compare_scopes +# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) class TestDoapSerialization(unittest.TestCase): shortcode = "1234" diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 661ced86..c0fe3773 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -3,6 +3,7 @@ from dsp_permissions_scripts.models import group from dsp_permissions_scripts.utils.helpers import sort_groups +# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) class TestHelpers(unittest.TestCase): def test_sort_groups(self) -> None: diff --git a/tests/test_oap_serialization.py b/tests/test_oap_serialization.py index f05a688f..5e0d19f7 100644 --- a/tests/test_oap_serialization.py +++ b/tests/test_oap_serialization.py @@ -10,6 +10,7 @@ from dsp_permissions_scripts.oap.oap_serialize import serialize_oaps from tests.test_scope_serialization import compare_scopes +# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) class TestOapSerialization(unittest.TestCase): shortcode = "1234" diff --git a/tests/test_scope.py b/tests/test_scope.py index 9a17c2b5..46b7f34f 100644 --- a/tests/test_scope.py +++ b/tests/test_scope.py @@ -4,6 +4,7 @@ from dsp_permissions_scripts.models.scope import PermissionScope from tests.test_scope_serialization import compare_scopes +# ruff: noqa: PT027 (pytest-unittest-raises-assertion) (remove this line when pytest is used instead of unittest) class TestScope(unittest.TestCase): def test_scope_validation_on_creation(self) -> None: diff --git a/tests/test_scope_serialization.py b/tests/test_scope_serialization.py index c9c66501..1465156d 100644 --- a/tests/test_scope_serialization.py +++ b/tests/test_scope_serialization.py @@ -8,6 +8,8 @@ from dsp_permissions_scripts.utils.scope_serialization import create_scope_from_string from dsp_permissions_scripts.utils.scope_serialization import create_string_from_scope +# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) + def compare_scopes( scope1: PermissionScope, @@ -22,13 +24,13 @@ def compare_scopes( class TestScopeSerialization(unittest.TestCase): - perm_strings = [ + perm_strings = ( "CR knora-admin:SystemAdmin|V knora-admin:CustomGroup", "D knora-admin:ProjectAdmin|RV knora-admin:ProjectMember", "M knora-admin:ProjectAdmin|V knora-admin:Creator,knora-admin:KnownUser|RV knora-admin:UnknownUser", "CR knora-admin:SystemAdmin,knora-admin:ProjectAdmin|D knora-admin:Creator|RV knora-admin:UnknownUser", - ] - admin_route_objects = [ + ) + admin_route_objects = ( [ {"name": "CR", "additionalInformation": "knora-admin:SystemAdmin", "permissionCode": None}, {"name": "V", "additionalInformation": "knora-admin:CustomGroup", "permissionCode": None}, @@ -49,8 +51,8 @@ class TestScopeSerialization(unittest.TestCase): {"name": "D", "additionalInformation": "knora-admin:Creator", "permissionCode": None}, {"name": "RV", "additionalInformation": "knora-admin:UnknownUser", "permissionCode": None}, ], - ] - scopes = [ + ) + scopes = ( PermissionScope.create( CR=[group.SYSTEM_ADMIN], V=[group.Group(val="http://www.knora.org/ontology/knora-admin#CustomGroup")], @@ -69,7 +71,7 @@ class TestScopeSerialization(unittest.TestCase): D={group.CREATOR}, RV={group.UNKNOWN_USER}, ), - ] + ) def test_create_scope_from_string(self) -> None: for perm_string, scope in zip(self.perm_strings, self.scopes):