From 1ccb038c010bf91cca4c47463da06d117121f1f5 Mon Sep 17 00:00:00 2001 From: rnkuhns Date: Sun, 9 Jun 2024 12:32:24 -0400 Subject: [PATCH 1/4] Update pre-commit routine --- .pre-commit-config.yaml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 967f461..949ce8a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: + - id: no-commit-to-branch - id: check-added-large-files args: ["--maxkb=1000"] - id: check-ast @@ -46,7 +47,7 @@ repos: rev: 1.16.0 hooks: - id: blacken-docs - additional_dependencies: [black==22.3.0] + additional_dependencies: [black==24.4.2] - repo: https://github.com/pycqa/flake8 rev: 7.0.0 @@ -59,6 +60,8 @@ repos: flake8-builtins, flake8-quotes>=3.3.2, flake8-comprehensions, + flake8-bandit, + flake8-pydocstyle, pandas-vet, flake8-print, pep8-naming, @@ -84,12 +87,13 @@ repos: - id: pydocstyle additional_dependencies: [".[toml]"] - - repo: https://github.com/PyCQA/bandit - rev: 1.7.8 - hooks: - - id: bandit - args: ["-c", "pyproject.toml"] - additional_dependencies: ["bandit[toml]"] + # Now using ruff and plug-in for flake8 + # - repo: https://github.com/PyCQA/bandit + # rev: 1.7.8 + # hooks: + # - id: bandit + # args: ["-c", "pyproject.toml"] + # additional_dependencies: ["bandit[toml]"] - repo: https://github.com/codespell-project/codespell rev: v2.3.0 @@ -115,7 +119,18 @@ repos: rev: v1.5.0 hooks: - id: yesqa - additional_dependencies: ["flake8-builtins"] + additional_dependencies: [ + flake8-bugbear, + flake8-builtins, + flake8-quotes>=3.3.2, + flake8-comprehensions, + flake8-bandit, + flake8-pydocstyle, + pandas-vet, + flake8-print, + pep8-naming, + doc8, + ] - repo: https://github.com/asottile/pyupgrade rev: v3.15.2 From 0862e1f83831a1af853914b162dc958efa234fe1 Mon Sep 17 00:00:00 2001 From: rnkuhns Date: Sun, 9 Jun 2024 12:32:50 -0400 Subject: [PATCH 2/4] Update flake8 config --- setup.cfg | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/setup.cfg b/setup.cfg index b025b0b..315ee0c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,16 @@ inline-quotes = double extend-ignore = E203 extend-select = B904, B907 exclude = .git, __pycache__, docs/source/conf.py, build, dist +require-plugins = + flake8-bugbear, + flake8-builtins, + flake8-quotes, + flake8-bandit, + flake8-pydocstyle, + flake8-comprehensions, + pandas-vet, + flake8-print, + pep8-naming [mypy] ignore_missing_imports = True From 708cc8ecf60b9993951040410103d200d1202970 Mon Sep 17 00:00:00 2001 From: rnkuhns Date: Sun, 9 Jun 2024 12:34:32 -0400 Subject: [PATCH 3/4] Update ruff and other configurations --- pyproject.toml | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5062f42..583c44f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,8 @@ linters = [ "flake8-builtins", "flake8-quotes", "flake8-comprehensions", + "flake8-bandit", + "flake8-pydocstyle", "pandas-vet", "flake8-print", "pep8-naming", @@ -115,7 +117,7 @@ addopts = [ profile = "black" src_paths = ["predictably/*"] multi_line_output = 3 -known_first_party = ["predictably"] +known_first_party = ["predictably", "predictably-core"] [tool.black] line-length = 88 @@ -123,6 +125,51 @@ line-length = 88 [tool.pydocstyle] convention = "numpy" +[tool.ruff] +line-length = 88 +indent-width = 4 + +[tool.ruff.lint] +select = [ + "E", + "F", + "I", + "B", + "N", + "A", + "D", + "Q", + "UP", + "SIM", + "W", + "S", + "C4", + "T20", + "PTH", + "RUF", +] +ignore = ["D413", "W191"] +unfixable = ["B"] +preview = true + +[tool.ruff.lint.per-file-ignores] +"**/tests/*.py" = ["S101"] + +[tool.ruff.format] +# Setup to format like black +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" + +docstring-code-line-length = "dynamic" + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.flake8-quotes] +docstring-quotes = "double" + [tool.coverage.report] show_missing = true ignore_errors = true @@ -144,7 +191,7 @@ ignore = ["D004"] ignore_path = ["docs/_build", "docs/source/api_reference/auto_generated"] [tool.bandit] -exclude_dirs = ["*/tests/*", "*/testing/*"] +exclude_dirs = ["**/tests/*", "**/testing/*"] [tool.numpydoc_validation] checks = ["all", "GL01", "SA01", "EX01"] From 8bb7e8c72fa9a1a68f80f34f9333e5c05766de34 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 9 Jun 2024 16:36:37 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/conf.py | 4 +- predictably/__init__.py | 6 +-- predictably/_config.py | 6 +-- predictably/_config_param_setting.py | 6 +-- predictably/_core/_pprint/_pprint.py | 2 +- predictably/_core/tests/test_base.py | 56 +++++++++++++------------- predictably/_core/tests/test_config.py | 1 - predictably/tests/conftest.py | 2 +- predictably/tests/test_config.py | 1 - predictably/utils/_iter.py | 4 +- 10 files changed, 43 insertions(+), 45 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6192387..ba3617d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -32,7 +32,7 @@ # Cython files. Hence, we do not add the source code path to the system path. env_rtd = os.environ.get("READTHEDOCS") # Check if on Read the docs -if not env_rtd == "True": +if env_rtd != "True": print("Not on ReadTheDocs") sys.path.insert(0, os.path.abspath("../..")) else: @@ -186,7 +186,7 @@ def find_source(): # numpydoc ignore=RT01 }, { "name": "Slack", - "url": f"https://join.slack.com/t/{org}/shared_invite/zt-21ezi33ip-WGJCUBCWc5yVrr6FOsARaw", # noqa: E501 + "url": f"https://join.slack.com/t/{org}/shared_invite/zt-21ezi33ip-WGJCUBCWc5yVrr6FOsARaw", "icon": "fab fa-slack", }, { diff --git a/predictably/__init__.py b/predictably/__init__.py index 4dfd1e1..f28ed15 100644 --- a/predictably/__init__.py +++ b/predictably/__init__.py @@ -18,9 +18,9 @@ __author__: List[str] = ["RNKuhns"] __all__: List[str] = [ - "get_default_config", + "config_context", "get_config", - "set_config", + "get_default_config", "reset_config", - "config_context", + "set_config", ] diff --git a/predictably/_config.py b/predictably/_config.py index b157e99..7b9789a 100644 --- a/predictably/_config.py +++ b/predictably/_config.py @@ -17,11 +17,11 @@ __author__: List[str] = ["RNKuhns"] __all__: List[str] = [ - "get_default_config", + "config_context", "get_config", - "set_config", + "get_default_config", "reset_config", - "config_context", + "set_config", ] diff --git a/predictably/_config_param_setting.py b/predictably/_config_param_setting.py index 362ca35..6cc5ad8 100644 --- a/predictably/_config_param_setting.py +++ b/predictably/_config_param_setting.py @@ -95,9 +95,9 @@ def is_valid_param_value(self, value: Any) -> bool: Whether a parameter value is valid. """ valid_param: bool - if not isinstance(value, self.expected_type): - valid_param = False - elif self.allowed_values is not None and value not in self.get_allowed_values(): + if not isinstance(value, self.expected_type) or ( + self.allowed_values is not None and value not in self.get_allowed_values() + ): valid_param = False else: valid_param = True diff --git a/predictably/_core/_pprint/_pprint.py b/predictably/_core/_pprint/_pprint.py index 46d84ac..9587aad 100644 --- a/predictably/_core/_pprint/_pprint.py +++ b/predictably/_core/_pprint/_pprint.py @@ -131,7 +131,7 @@ def __init__( # (they are treated as dicts) self.n_max_elements_to_show = n_max_elements_to_show - def format(self, obj, context, maxlevels, level): # noqa: A003 + def format(self, obj, context, maxlevels, level): return _safe_repr( obj, context, maxlevels, level, changed_only=self.changed_only ) diff --git a/predictably/_core/tests/test_base.py b/predictably/_core/tests/test_base.py index 10385f4..d22b166 100644 --- a/predictably/_core/tests/test_base.py +++ b/predictably/_core/tests/test_base.py @@ -23,31 +23,6 @@ __author__ = ["RNKuhns"] __all__ = [ - "test_get_class_tags", - "test_get_class_tag", - "test_get_tags", - "test_get_tag", - "test_get_tag_raises", - "test_set_tags", - "test_set_tags_works_with_missing_tags_dynamic_attribute", - "test_clone_tags", - "test_is_composite", - "test_components", - "test_components_raises_error_base_class_is_not_class", - "test_components_raises_error_base_class_is_not_baseobject_subclass", - "test_reset", - "test_reset_composite", - "test_get_init_signature", - "test_get_init_signature_raises_error_for_invalid_signature", - "test_get_param_names", - "test_get_params", - "test_get_params_invariance", - "test_get_params_after_set_params", - "test_set_params", - "test_set_params_raises_error_non_existent_param", - "test_set_params_raises_error_non_interface_composite", - "test_raises_on_get_params_for_param_arg_not_assigned_to_attribute", - "test_set_params_with_no_param_to_set_returns_object", # "test_clone", # "test_clone_2", # "test_clone_raises_error_for_nonconforming_objects", @@ -59,15 +34,40 @@ # "test_clone_class_rather_than_instance_raises_error", # "test_clone_sklearn_composite", "test_baseobject_repr", - "test_baseobject_str", "test_baseobject_repr_mimebundle_", - "test_repr_html_wraps", + "test_baseobject_str", + "test_clone_tags", + "test_components", + "test_components_raises_error_base_class_is_not_baseobject_subclass", + "test_components_raises_error_base_class_is_not_class", # "test_get_test_params", # "test_get_test_params_raises_error_when_params_required", # "test_create_test_instance", # "test_create_test_instances_and_names", # "test_has_implementation_of", "test_eq_dunder", + "test_get_class_tag", + "test_get_class_tags", + "test_get_init_signature", + "test_get_init_signature_raises_error_for_invalid_signature", + "test_get_param_names", + "test_get_params", + "test_get_params_after_set_params", + "test_get_params_invariance", + "test_get_tag", + "test_get_tag_raises", + "test_get_tags", + "test_is_composite", + "test_raises_on_get_params_for_param_arg_not_assigned_to_attribute", + "test_repr_html_wraps", + "test_reset", + "test_reset_composite", + "test_set_params", + "test_set_params_raises_error_non_existent_param", + "test_set_params_raises_error_non_interface_composite", + "test_set_params_with_no_param_to_set_returns_object", + "test_set_tags", + "test_set_tags_works_with_missing_tags_dynamic_attribute", ] import inspect @@ -984,7 +984,7 @@ def test_baseobject_repr( long_base_obj_repr = fixture_class_parent(a=["long_params"] * 1000) assert len(repr(long_base_obj_repr)) == 535 - named_objs = [(f"Step {i+1}", Child()) for i in range(25)] + named_objs = [(f"Step {i + 1}", Child()) for i in range(25)] base_comp = CompositionDummy(foo=Parent(c=Child(c=named_objs))) assert len(repr(base_comp)) == 1362 diff --git a/predictably/_core/tests/test_config.py b/predictably/_core/tests/test_config.py index 8f63e5a..b8c2176 100644 --- a/predictably/_core/tests/test_config.py +++ b/predictably/_core/tests/test_config.py @@ -347,7 +347,6 @@ def test_config_threadsafe(): between threads. Same test as `test_config_threadsafe_joblib` but with `ThreadPoolExecutor`. """ - print_changed_only_vals = [False, True, False, True] sleep_durations = [0.1, 0.2, 0.1, 0.2] diff --git a/predictably/tests/conftest.py b/predictably/tests/conftest.py index 647dfb0..ac3a5dc 100644 --- a/predictably/tests/conftest.py +++ b/predictably/tests/conftest.py @@ -7,7 +7,7 @@ from predictably._core._base import BaseEstimator, BaseObject -__all__: List[str] = ["Parent", "Child"] +__all__: List[str] = ["Child", "Parent"] __author__: List[str] = ["RNKuhns"] PREDICTABLY_BASE_CLASSES = (BaseObject, BaseEstimator) diff --git a/predictably/tests/test_config.py b/predictably/tests/test_config.py index 8f63e5a..b8c2176 100644 --- a/predictably/tests/test_config.py +++ b/predictably/tests/test_config.py @@ -347,7 +347,6 @@ def test_config_threadsafe(): between threads. Same test as `test_config_threadsafe_joblib` but with `ThreadPoolExecutor`. """ - print_changed_only_vals = [False, True, False, True] sleep_durations = [0.1, 0.2, 0.1, 0.2] diff --git a/predictably/utils/_iter.py b/predictably/utils/_iter.py index f95d8ee..ee6857b 100644 --- a/predictably/utils/_iter.py +++ b/predictably/utils/_iter.py @@ -10,10 +10,10 @@ __author__: List[str] = ["RNKuhns"] __all__: List[str] = [ - "_scalar_to_seq", + "_format_seq_to_str", "_remove_single", "_remove_type_text", - "_format_seq_to_str", + "_scalar_to_seq", ]