enable pep8-naming and use ruff for autofixer
This commit is contained in:
parent
cb995b53a6
commit
a567b990e6
26
bin/run_pyl
26
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue