From 3af967fc4fdc50d2d8c5cf8d9539c54ac644c000 Mon Sep 17 00:00:00 2001 From: bensteUEM Date: Mon, 7 Oct 2024 20:16:54 +0200 Subject: [PATCH] further ruff linting cleanup #102 --- churchtools_api/churchtools_api.py | 11 ++++----- churchtools_api/files.py | 3 ++- churchtools_api/groups.py | 1 + churchtools_api/persons.py | 1 + churchtools_api/songs.py | 4 ++-- main.ipynb | 3 ++- pyproject.toml | 31 ++++++++++++++----------- tests/test_churchtools_api_resources.py | 2 +- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/churchtools_api/churchtools_api.py b/churchtools_api/churchtools_api.py index 185d10c..087d8e2 100644 --- a/churchtools_api/churchtools_api.py +++ b/churchtools_api/churchtools_api.py @@ -218,12 +218,11 @@ def get_services(self, **kwargs): response_content = json.loads(response.content) response_data = response_content["data"].copy() - if "returnAsDict" in kwargs and "serviceId" not in kwargs: - if kwargs["returnAsDict"]: - result = {} - for item in response_data: - result[item["id"]] = item - response_data = result + if kwargs.get("returnAsDict", False) and "serviceId" not in kwargs: + result = {} + for item in response_data: + result[item["id"]] = item + response_data = result logger.debug( f"Services load successful with {len(response_data)} entries", diff --git a/churchtools_api/files.py b/churchtools_api/files.py index b4521c7..7053033 100644 --- a/churchtools_api/files.py +++ b/churchtools_api/files.py @@ -24,6 +24,7 @@ def file_upload( domain_type: str, domain_identifier: int, custom_file_name: Optional[str] = None, + *, overwrite: bool = False, ) -> bool: """Helper function to upload an attachment to any module of ChurchTools. @@ -87,7 +88,7 @@ def file_upload( response_content = json.loads(response.content) logger.debug(f"Upload successful {response_content}") return True - except BaseException: + except (json.JSONDecodeError, TypeError, UnicodeDecodeError): logger.warning(response.content.decode()) return False else: diff --git a/churchtools_api/groups.py b/churchtools_api/groups.py index 6003a11..72eff54 100644 --- a/churchtools_api/groups.py +++ b/churchtools_api/groups.py @@ -333,6 +333,7 @@ def get_group_members(self, group_id: int, **kwargs) -> list[dict]: def get_groups_members( self, group_ids: Optional[list[int]] = None, + *, with_deleted: bool = False, **kwargs, ) -> list[dict]: diff --git a/churchtools_api/persons.py b/churchtools_api/persons.py index 3365c11..dce008a 100644 --- a/churchtools_api/persons.py +++ b/churchtools_api/persons.py @@ -79,6 +79,7 @@ def get_persons(self, **kwargs) -> list[dict]: def get_persons_masterdata( self, + *, resultClass: Optional[str] = None, returnAsDict: bool = False, **kwargs, diff --git a/churchtools_api/songs.py b/churchtools_api/songs.py index e6cfa06..5aedbf8 100644 --- a/churchtools_api/songs.py +++ b/churchtools_api/songs.py @@ -105,7 +105,7 @@ def get_song_category_map(self) -> dict: return song_category_dict - def create_song( + def create_song( # noqa: PLR0913 self, title: str, songcategory_id: int, @@ -157,7 +157,7 @@ def create_song( logger.info(f"Creating song failed with {response.status_code}") return None - def edit_song( + def edit_song( # noqa: PLR0913 self, song_id: int, songcategory_id=None, diff --git a/main.ipynb b/main.ipynb index 1e3945d..1bb341d 100644 --- a/main.ipynb +++ b/main.ipynb @@ -22,6 +22,7 @@ "from pathlib import Path\n", "\n", "from churchtools_api.churchtools_api import ChurchToolsApi\n", + "from secure.config import ct_domain, ct_token\n", "\n", "logger = logging.getLogger(__name__)\n", "\n", @@ -34,7 +35,7 @@ " logging.config.dictConfig(config=logging_config)\n", "\n", "# Create Session\n", - "from secure.config import ct_domain, ct_token\n", + "\n", "\n", "api = ChurchToolsApi(ct_domain)\n", "api.login_ct_rest_api(ct_token=ct_token)" diff --git a/pyproject.toml b/pyproject.toml index 890fdcd..18c019a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,23 +68,28 @@ ignore = [ "S101", # TODO: Github #104 - pytest asserts "ANN001","ANN002","ANN003","ANN201", "FIX002", #Open ToDos - "C901", #complexity - "ARG002", - "FA100", - "FBT001","FBT002", - "TD002","TD003","TD004", - "D100","D101","D102","D104","D107","D205","D415", - "E402","E501", - "DTZ001","DTZ005","DTZ007","DTZ002", - "N801","N802","N803","N806", - "PLR2004","PLR0913","PLR0912", - "PTH110","PTH107","PTH123","PTH118","PTH112","PTH103", - "SIM102","SIM113","SIM115", + "TD002","TD003","TD004", #TODOs + "C901","PLR0912", #complexity + "ARG002",#TODO: Github #110 + "FA100", #Python version specific #102 + "D100","D101","D102","D104","D107","D205","D415", #Docstrings + "E501", #line too long + "DTZ001","DTZ005","DTZ007","DTZ002", #datetime timezone + + "PLR2004", #magic values + "PTH110","PTH107","PTH123","PTH118","PTH112","PTH103", #Path changes + "SIM115", #context manager for files + + "SIM102","SIM113", "G001","G003", "G004", "A001","A002", "TRY300", - "BLE001", + "COM812", "ISC001", #disabled for formatter compatibility + + "N802", #function lowercase -> breaking change + "N803", #argument lowercase -> breaking change + "N806", #variable name lowercase -> breaking change ] fixable = [ "ALL", diff --git a/tests/test_churchtools_api_resources.py b/tests/test_churchtools_api_resources.py index ba0b879..a2bdbaf 100644 --- a/tests/test_churchtools_api_resources.py +++ b/tests/test_churchtools_api_resources.py @@ -17,7 +17,7 @@ logging.config.dictConfig(config=logging_config) -class Test_churchtools_api_resources(TestsChurchToolsApiAbstract): +class TestChurchtoolsApiResources(TestsChurchToolsApiAbstract): def test_get_resource_masterdata_resourceTypes(self) -> None: """Check resourceTypes can be retrieved.