From a567b990e63c67be77832d652f674e06eae448ce Mon Sep 17 00:00:00 2001 From: burnettk Date: Tue, 30 May 2023 07:15:49 -0400 Subject: [PATCH] enable pep8-naming and use ruff for autofixer --- bin/run_pyl | 26 +++++-------------- spiffworkflow-backend/pyproject.toml | 2 +- .../services/logging_service.py | 6 +++-- .../process_model_test_runner_service.py | 8 +++--- .../unit/test_process_model_test_runner.py | 4 +-- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/bin/run_pyl b/bin/run_pyl index 9e1ce7c9a..d3a45ec8a 100755 --- a/bin/run_pyl +++ b/bin/run_pyl @@ -30,29 +30,17 @@ function get_python_dirs() { (git ls-tree -r HEAD --name-only | grep -E '\.py$' | awk -F '/' '{print $1}' | sort | uniq | grep -v '\.' | grep -Ev '^(bin|migrations)$') || echo '' } -function run_autoflake() { - # checking command -v autoflake8 is not good enough, since the asdf shim may be installed, which will make command -v succeed, - # but autoflake8 may not have been pip installed inside the correct version of python. - if ! autoflake8 --help >/dev/null ; then - pip install autoflake8 - asdf reshim python - fi - - if ! autoflake --help >/dev/null ; then - pip install autoflake - asdf reshim python - fi - - if ! autopep8 --help >/dev/null ; then - pip install autopep8 +function run_autofixers() { + # checking command -v ruff is not good enough, since the asdf shim may be installed, which will make command -v succeed, + # but ruff may not have been pip installed inside the correct version of python. + if ! ruff --help >/dev/null 2>&1; then + pip install ruff asdf reshim python fi python_dirs=$(get_python_dirs) python_files=$(find $python_dirs -type f -name "*.py" ! -name '.null-ls*' ! -name '_null-ls*') - autoflake8 --in-place --remove-unused-variables --remove-duplicate-keys --expand-star-imports --exit-zero-even-if-changed $python_files - autoflake --in-place --remove-all-unused-imports $python_files - autopep8 --in-place $python_files + ruff --fix $python_files } function run_pre_commmit() { @@ -71,7 +59,7 @@ done for python_project in "${python_projects[@]}" ; do if [[ "$subcommand" != "pre" ]] || [[ -n "$(git status --porcelain "$python_project")" ]]; then pushd "$python_project" - run_autoflake || run_autoflake + run_autofixers || run_autofixers popd fi done diff --git a/spiffworkflow-backend/pyproject.toml b/spiffworkflow-backend/pyproject.toml index aa48b06d1..f116d4a35 100644 --- a/spiffworkflow-backend/pyproject.toml +++ b/spiffworkflow-backend/pyproject.toml @@ -171,7 +171,7 @@ select = [ "E", # pycodestyle error # "ERA", # eradicate "F", # pyflakes - # "N", # pep8-naming + "N", # pep8-naming # "PL", # pylint # "S", # flake8-bandit "UP", # pyupgrade diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/logging_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/logging_service.py index e7707724d..3c8845c3a 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/logging_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/logging_service.py @@ -46,12 +46,14 @@ class JsonFormatter(logging.Formatter): self.default_msec_format = msec_format self.datefmt = None - def usesTime(self) -> bool: + def usesTime(self) -> bool: # noqa: N802, this is overriding a method from python's stdlib """Overwritten to look for the attribute in the format dict values instead of the fmt string.""" return "asctime" in self.fmt_dict.values() # we are overriding a method that returns a string and returning a dict, hence the Any - def formatMessage(self, record: logging.LogRecord) -> Any: + def formatMessage( # noqa: N802, this is overriding a method from python's stdlib + self, record: logging.LogRecord + ) -> Any: """Overwritten to return a dictionary of the relevant LogRecord attributes instead of a string. KeyError is raised if an unknown attribute is provided in the fmt_dict. diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py index 4f46f8c15..0bc8bbd6d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py @@ -26,11 +26,11 @@ class NoTestCasesFoundError(Exception): pass -class MissingInputTaskData(Exception): +class MissingInputTaskDataError(Exception): pass -class UnsupporterRunnerDelegateGiven(Exception): +class UnsupporterRunnerDelegateGivenError(Exception): pass @@ -236,7 +236,7 @@ class ProcessModelTestRunner: self.test_case_identifier = test_case_identifier if not issubclass(process_model_test_runner_delegate_class, ProcessModelTestRunnerDelegate): - raise UnsupporterRunnerDelegateGiven( + raise UnsupporterRunnerDelegateGivenError( "Process model test runner delegate must inherit from ProcessModelTestRunnerDelegate. Given" f" class '{process_model_test_runner_delegate_class}' does not" ) @@ -342,7 +342,7 @@ class ProcessModelTestRunner: task_data_length = len(test_case_task_properties["data"]) test_case_index = self.task_data_index[test_case_task_key] if task_data_length <= test_case_index: - raise MissingInputTaskData( + raise MissingInputTaskDataError( f"Missing input task data for task: {test_case_task_key}. " f"Only {task_data_length} given in the json but task was called {test_case_index + 1} times" ) diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py index f934c8a17..068a772a8 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py @@ -5,7 +5,7 @@ from flask import Flask from flask import current_app from spiffworkflow_backend.services.process_model_test_runner_service import NoTestCasesFoundError from spiffworkflow_backend.services.process_model_test_runner_service import ProcessModelTestRunner -from spiffworkflow_backend.services.process_model_test_runner_service import UnsupporterRunnerDelegateGiven +from spiffworkflow_backend.services.process_model_test_runner_service import UnsupporterRunnerDelegateGivenError from tests.spiffworkflow_backend.helpers.base_test import BaseTest @@ -34,7 +34,7 @@ class TestProcessModelTestRunner(BaseTest): app: Flask, with_db_and_bpmn_file_cleanup: None, ) -> None: - with pytest.raises(UnsupporterRunnerDelegateGiven): + with pytest.raises(UnsupporterRunnerDelegateGivenError): ProcessModelTestRunner( os.path.join(self.root_path(), "DNE"), process_model_test_runner_delegate_class=NoTestCasesFoundError )