From c93246ff3e9d3bfc4d07e77ce07446a93371137d Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 16:36:45 -0400 Subject: [PATCH 01/24] Initialize `ruff.toml` and replicate `isort` Signed-off-by: Yury Fedotov --- package/ruff.toml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 package/ruff.toml diff --git a/package/ruff.toml b/package/ruff.toml new file mode 100644 index 000000000..65e5dd1a8 --- /dev/null +++ b/package/ruff.toml @@ -0,0 +1,15 @@ +target-version = "py39" + +include = [ + "kedro_viz/*.py", + "tests/*.py", + "features/*.py", +] + +[lint] +select = [ + "I", # Isort +] + +[lint.isort] +known-first-party = ["kedro_viz"] From 831b64f105bb6eef338f1adfadcb572ff4c9ccee Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:10:53 -0400 Subject: [PATCH 02/24] Extend `ruff` config to replicate existing linter Signed-off-by: Yury Fedotov --- package/ruff.toml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/package/ruff.toml b/package/ruff.toml index 65e5dd1a8..2b9665493 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -9,7 +9,38 @@ include = [ [lint] select = [ "I", # Isort + "B", # Bugbear + "PL", # Pylint + "C90", # Mccabe complexity + "E", # Pycodestyle errors + "F", # Pyflakes + "W", # Pycodestyle warnings ] +ignore = [ + "E203", + "E231", + "E266", + "E501", + "F401", + "B030", # Except handler is something other than exception class + "C405", # Inconsistent definition of literal collections + "PLR2004", # Magic values in comparisons +] + +[lint.per-file-ignores] +"*/cli_steps.py" = ["B011"] # assert False instead of AssertionError +"*/base_deployer.py" = ["B024"] # ABCs without abstract methods +"kedro_viz/__init__.py" = ["B028"] # Risky usage of positional arguments +"tests/test_integrations/test_sqlite_store.py" = ["C401"] # Unnecessary generators +"kedro_viz/data_access/repositories/tags.py" = ["C413"] # Unnecessary list call around sorted() +"kedro_viz/data_access/repositories/catalog.py" = ["PLW2901"] # Overwrite for loop variable inside the loop +"features/steps/sh_run.py" = ["PLW1510"] # `subprocess.run` without explicit `check` argument [lint.isort] known-first-party = ["kedro_viz"] + +[lint.mccabe] +max-complexity = 18 + +[lint.pylint] +max-args = 12 From 38a1c0da98ac824cb75c52ae38679649755f0a59 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:11:24 -0400 Subject: [PATCH 03/24] Remove a few `pylint` directives that are no longer needed Signed-off-by: Yury Fedotov --- package/kedro_viz/data_access/managers.py | 3 +-- package/kedro_viz/data_access/repositories/catalog.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/package/kedro_viz/data_access/managers.py b/package/kedro_viz/data_access/managers.py index 40e00ebe5..160ed9905 100644 --- a/package/kedro_viz/data_access/managers.py +++ b/package/kedro_viz/data_access/managers.py @@ -466,8 +466,7 @@ def get_sorted_layers_for_registered_pipeline( self.get_node_dependencies_for_registered_pipeline(registered_pipeline_id), ) - # pylint: disable=too-many-locals,too-many-branches - def create_modular_pipelines_tree_for_registered_pipeline( + def create_modular_pipelines_tree_for_registered_pipeline( # noqa: PLR0912 self, registered_pipeline_id: str = DEFAULT_REGISTERED_PIPELINE_ID ) -> Dict[str, ModularPipelineNode]: """Create the modular pipelines tree for a specific registered pipeline. diff --git a/package/kedro_viz/data_access/repositories/catalog.py b/package/kedro_viz/data_access/repositories/catalog.py index 38d9a6772..4779e3d01 100644 --- a/package/kedro_viz/data_access/repositories/catalog.py +++ b/package/kedro_viz/data_access/repositories/catalog.py @@ -52,8 +52,7 @@ def _validate_layers_for_transcoding(self, dataset_name, layer): ) @property - def layers_mapping(self): - # pylint: disable=too-many-branches + def layers_mapping(self): # noqa: PLR0912 """Return layer mapping: dataset_name -> layer it belongs to in the catalog From kedro-datasets 1.3.0 onwards, the 'layers' attribute is defined inside the 'metadata' under 'kedro-viz' plugin. From 9de98014d9eaba4768efa7615effb3e0c97b6dfa Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:12:18 -0400 Subject: [PATCH 04/24] Delete 3 config files that are no longer needed Signed-off-by: Yury Fedotov --- package/.flake8 | 7 - package/.isort.cfg | 9 -- package/.pylintrc | 391 --------------------------------------------- 3 files changed, 407 deletions(-) delete mode 100644 package/.flake8 delete mode 100644 package/.isort.cfg delete mode 100644 package/.pylintrc diff --git a/package/.flake8 b/package/.flake8 deleted file mode 100644 index 9e226baf4..000000000 --- a/package/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -# copied from black - -[flake8] -ignore = E203,E231,E266,E501,F401,W503 -max-line-length = 88 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 diff --git a/package/.isort.cfg b/package/.isort.cfg deleted file mode 100644 index 78ae47d50..000000000 --- a/package/.isort.cfg +++ /dev/null @@ -1,9 +0,0 @@ -# copied from black - -[settings] -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -use_parentheses=True -line_length=88 -known_third_party=behave diff --git a/package/.pylintrc b/package/.pylintrc deleted file mode 100644 index bbf5e49a4..000000000 --- a/package/.pylintrc +++ /dev/null @@ -1,391 +0,0 @@ -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist=pydantic - -# Add files or directories to the blacklist. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the blacklist. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.docparams,pylint_pydantic - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -disable=ungrouped-imports,attribute-defined-outside-init,too-many-arguments,duplicate-code,too-many-positional-arguments,fixme - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable=useless-suppression - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -class-rgx=[A-Z_][a-zA-Z0-9]+$ - - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -good-names=i,j,k,ex,Run,_,id - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,60})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=no - -# Minimum lines number of a similarity. -min-similarity-lines=20 - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=orjson - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=12 - -# Maximum number of attributes for a class (see R0902). -max-attributes=7 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception From d3f4bf774f9d862adf9381877627a1e45665426c Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:15:30 -0400 Subject: [PATCH 05/24] Delete 4 tools from requirements and add `ruff` instead Signed-off-by: Yury Fedotov --- package/test_requirements.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package/test_requirements.txt b/package/test_requirements.txt index 14741ab0e..1df8b75a7 100644 --- a/package/test_requirements.txt +++ b/package/test_requirements.txt @@ -7,18 +7,15 @@ bandit~=1.7 behave~=1.2 black~=23.3 boto3~=1.34 -flake8~=7.1 -isort~=5.11 matplotlib~=3.9 mypy~=1.11 moto~=5.0.9 psutil==5.9.6 # same as Kedro for now -pylint~=3.2 -pylint-pydantic>=0.3.0 pytest~=8.3 pytest-asyncio~=0.21 pytest-mock~=3.14 pytest-cov~=5.0 +ruff==0.7.0 sqlalchemy-stubs~=0.4 strawberry-graphql[cli]>=0.99.0, <1.0 trufflehog~=2.2 From 51455a10c1a06f95eceb9175cb3c8254c97cebba Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:22:26 -0400 Subject: [PATCH 06/24] Include `ruff` linter in `Makefile` Signed-off-by: Yury Fedotov --- Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 9536ca63c..f27718b5e 100644 --- a/Makefile +++ b/Makefile @@ -27,18 +27,15 @@ e2e-tests: lint: format-fix lint-check format-fix: - isort package/kedro_viz package/tests package/features + ruff check package --fix black package/kedro_viz package/tests package/features format-check: - isort --check package/kedro_viz package/tests package/features + ruff check package black --check package/kedro_viz package/tests package/features lint-check: - pylint --rcfile=package/.pylintrc -j 0 package/kedro_viz - pylint --rcfile=package/.pylintrc -j 0 --disable=protected-access,missing-docstring,redefined-outer-name,invalid-name,too-few-public-methods,no-member,unused-argument,duplicate-code,abstract-class-instantiated package/tests - pylint --rcfile=package/.pylintrc -j 0 --disable=missing-docstring,no-name-in-module,unused-argument package/features - flake8 --config=package/.flake8 package + ruff check package mypy --config-file=package/mypy.ini package/kedro_viz package/features mypy --disable-error-code abstract --config-file=package/mypy.ini package/tests From 3523286c3eb3b93b40adce55b99b4885db30031b Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:30:57 -0400 Subject: [PATCH 07/24] Add a `BLE` ruleset Signed-off-by: Yury Fedotov --- package/ruff.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/package/ruff.toml b/package/ruff.toml index 2b9665493..f13cb6548 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -10,6 +10,7 @@ include = [ select = [ "I", # Isort "B", # Bugbear + "BLE", # Blind exceptions "PL", # Pylint "C90", # Mccabe complexity "E", # Pycodestyle errors From 1f3dcfe5b3dc650899b4fae476c9b459b029ee2f Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:40:20 -0400 Subject: [PATCH 08/24] Add NOQAs for `BLE` ruleset instead of `pylint` ones Signed-off-by: Yury Fedotov --- package/features/steps/cli_steps.py | 4 ++-- package/kedro_viz/data_access/managers.py | 3 +-- package/kedro_viz/data_access/repositories/catalog.py | 3 +-- package/kedro_viz/integrations/kedro/data_loader.py | 2 +- package/kedro_viz/integrations/kedro/hooks.py | 10 +++++----- package/kedro_viz/integrations/kedro/lite_parser.py | 6 ++---- package/kedro_viz/integrations/kedro/sqlite_store.py | 4 ++-- package/kedro_viz/integrations/kedro/telemetry.py | 3 +-- package/kedro_viz/launchers/cli/utils.py | 6 ++---- package/kedro_viz/launchers/utils.py | 5 ++--- package/kedro_viz/models/experiment_tracking.py | 2 +- package/kedro_viz/models/flowchart.py | 7 +++---- 12 files changed, 23 insertions(+), 32 deletions(-) diff --git a/package/features/steps/cli_steps.py b/package/features/steps/cli_steps.py index 769cb08d6..3f9deb130 100644 --- a/package/features/steps/cli_steps.py +++ b/package/features/steps/cli_steps.py @@ -166,7 +166,7 @@ def check_kedroviz_up(context): while time() < end_by: try: data_json = requests.get("http://localhost:4141/api/main").json() - except Exception: + except Exception: # noqa: BLE001 sleep(2.0) continue else: @@ -191,7 +191,7 @@ def get_main_api_response(context): response = requests.get("http://localhost:4141/api/main") context.response = response.json() assert response.status_code == 200 - except Exception: + except Exception: # noqa: BLE001 sleep(2.0) continue else: diff --git a/package/kedro_viz/data_access/managers.py b/package/kedro_viz/data_access/managers.py index 160ed9905..d853c659b 100644 --- a/package/kedro_viz/data_access/managers.py +++ b/package/kedro_viz/data_access/managers.py @@ -87,8 +87,7 @@ def resolve_dataset_factory_patterns( for dataset_name in datasets: try: catalog._get_dataset(dataset_name, suggest=False) - # pylint: disable=broad-except - except Exception: # pragma: no cover + except Exception: # noqa: BLE001 # pragma: no cover continue def add_catalog(self, catalog: DataCatalog, pipelines: Dict[str, KedroPipeline]): diff --git a/package/kedro_viz/data_access/repositories/catalog.py b/package/kedro_viz/data_access/repositories/catalog.py index 4779e3d01..6133db54d 100644 --- a/package/kedro_viz/data_access/repositories/catalog.py +++ b/package/kedro_viz/data_access/repositories/catalog.py @@ -82,8 +82,7 @@ def layers_mapping(self): # noqa: PLR0912 # Temporary try/except block so the Kedro develop branch can work with Viz. try: datasets = self._catalog._data_sets - # pylint: disable=broad-exception-caught - except Exception: # pragma: no cover + except Exception: # noqa: BLE001 # pragma: no cover datasets = self._catalog._datasets # Support for Kedro 0.18.x diff --git a/package/kedro_viz/integrations/kedro/data_loader.py b/package/kedro_viz/integrations/kedro/data_loader.py index aabc5b73a..b4aa418ef 100644 --- a/package/kedro_viz/integrations/kedro/data_loader.py +++ b/package/kedro_viz/integrations/kedro/data_loader.py @@ -46,7 +46,7 @@ def _get_dataset_stats(project_path: Path) -> Dict: stats = json.load(stats_file) return stats - except Exception as exc: # pylint: disable=broad-exception-caught + except Exception as exc: # noqa: BLE001 logger.warning( "Unable to get dataset statistics from project path %s : %s", project_path, diff --git a/package/kedro_viz/integrations/kedro/hooks.py b/package/kedro_viz/integrations/kedro/hooks.py index 97da89319..a9531989a 100644 --- a/package/kedro_viz/integrations/kedro/hooks.py +++ b/package/kedro_viz/integrations/kedro/hooks.py @@ -1,4 +1,4 @@ -# pylint: disable=broad-exception-caught, protected-access +# pylint: disable=protected-access """`kedro_viz.integrations.kedro.hooks` defines hooks to add additional functionalities for a kedro run.""" @@ -37,7 +37,7 @@ def after_catalog_created(self, catalog: DataCatalog): # Temporary try/except block so the Kedro develop branch can work with Viz. try: self.datasets = catalog._datasets - except Exception: # pragma: no cover + except Exception: # noqa: BLE001 # pragma: no cover # Support for Kedro 0.18.x self.datasets = catalog._data_sets # type: ignore[attr-defined] @@ -93,7 +93,7 @@ def after_pipeline_run(self): } json.dump(sorted_stats_data, file) - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.warning( "Unable to write dataset statistics for the pipeline: %s", exc ) @@ -129,7 +129,7 @@ def create_dataset_stats(self, dataset_name: str, data: Any): dataset_name, exc, ) - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.warning( "[hook: after_dataset_saved] Unable to create statistics for the dataset %s : %s", dataset_name, @@ -154,7 +154,7 @@ def get_file_size(self, dataset: Any) -> Union[int, None]: ) return dataset._fs.size(file_path) - except Exception as exc: + except Exception as exc: # noqa: BLE001 logger.warning( "Unable to get file size for the dataset %s: %s", dataset, exc ) diff --git a/package/kedro_viz/integrations/kedro/lite_parser.py b/package/kedro_viz/integrations/kedro/lite_parser.py index 9fe619fe5..e3af8b42e 100755 --- a/package/kedro_viz/integrations/kedro/lite_parser.py +++ b/package/kedro_viz/integrations/kedro/lite_parser.py @@ -48,8 +48,7 @@ def _is_module_importable(module_name: str) -> bool: except ValueError as val_exc: logger.debug("ValueError in resolving %s : %s", module_name, val_exc) return False - # pylint: disable=broad-except - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.debug( "An exception occurred while resolving %s : %s", module_name, exc ) @@ -262,8 +261,7 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]: ) if len(missing_dependencies) > 0: unresolved_imports[str(file_path)] = missing_dependencies - # pylint: disable=broad-except - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.error( "An error occurred in LiteParser while mocking dependencies : %s", exc, diff --git a/package/kedro_viz/integrations/kedro/sqlite_store.py b/package/kedro_viz/integrations/kedro/sqlite_store.py index 9b9b9e730..575e1ec10 100644 --- a/package/kedro_viz/integrations/kedro/sqlite_store.py +++ b/package/kedro_viz/integrations/kedro/sqlite_store.py @@ -1,7 +1,7 @@ """kedro_viz.intergrations.kedro.sqlite_store is a child of BaseSessionStore which stores sessions data in the SQLite database""" -# pylint: disable=no-member, broad-exception-caught +# pylint: disable=no-member import getpass import json @@ -87,7 +87,7 @@ def _to_json(self) -> str: value["branch"] = branch.name except ImportError as exc: # pragma: no cover logger.warning("%s:%s", exc.__class__.__name__, exc.msg) - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.warning("Something went wrong when fetching git metadata.") logger.warning(exc) diff --git a/package/kedro_viz/integrations/kedro/telemetry.py b/package/kedro_viz/integrations/kedro/telemetry.py index 2c57c4153..649330401 100644 --- a/package/kedro_viz/integrations/kedro/telemetry.py +++ b/package/kedro_viz/integrations/kedro/telemetry.py @@ -26,12 +26,11 @@ def get_heap_app_id(project_path: Path) -> Optional[str]: return None -# pylint: disable=broad-exception-caught def get_heap_identity() -> Optional[str]: # pragma: no cover """Reads a UUID from a configuration file or generates and saves a new one if not present.""" if not _IS_TELEMETRY_INSTALLED: return None try: return _get_or_create_uuid() - except Exception: # pragma: no cover + except Exception: # noqa: BLE001 # pragma: no cover return None diff --git a/package/kedro_viz/launchers/cli/utils.py b/package/kedro_viz/launchers/cli/utils.py index 290a0461c..4f089f738 100644 --- a/package/kedro_viz/launchers/cli/utils.py +++ b/package/kedro_viz/launchers/cli/utils.py @@ -96,8 +96,7 @@ def create_shareableviz_process( "you have write access to the current directory", "red", ) - # pylint: disable=broad-exception-caught - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover display_cli_message(f"ERROR: Failed to build/deploy Kedro-Viz : {exc} ", "red") finally: @@ -150,8 +149,7 @@ def _load_and_deploy_viz( else FileNotFoundError ): # pragma: no cover exception_queue.put(Exception("The specified bucket does not exist")) - # pylint: disable=broad-exception-caught - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover exception_queue.put(exc) finally: process_completed.value = 1 diff --git a/package/kedro_viz/launchers/utils.py b/package/kedro_viz/launchers/utils.py index c4b007667..00fcde64e 100644 --- a/package/kedro_viz/launchers/utils.py +++ b/package/kedro_viz/launchers/utils.py @@ -49,7 +49,7 @@ def _wait_for( while time() <= end: try: retval = func(**kwargs) - except Exception as err: # pylint: disable=broad-except + except Exception as err: # noqa: BLE001 if print_error: logger.error(err) else: @@ -103,8 +103,7 @@ def _is_project(project_path: Union[str, Path]) -> bool: try: return "[tool.kedro]" in metadata_file.read_text(encoding="utf-8") - # pylint: disable=broad-exception-caught - except Exception: + except Exception: # noqa: BLE001 return False diff --git a/package/kedro_viz/models/experiment_tracking.py b/package/kedro_viz/models/experiment_tracking.py index d662a3fea..60601e328 100644 --- a/package/kedro_viz/models/experiment_tracking.py +++ b/package/kedro_viz/models/experiment_tracking.py @@ -112,7 +112,7 @@ def load_tracking_data(self, run_id: str): } else: self.runs[run_id] = self.dataset.preview() # type: ignore - except Exception as exc: # pylint: disable=broad-except # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.warning( "'%s' with version '%s' could not be loaded. Full exception: %s: %s", self.dataset_name, diff --git a/package/kedro_viz/models/flowchart.py b/package/kedro_viz/models/flowchart.py index 8828650a7..40588da9d 100644 --- a/package/kedro_viz/models/flowchart.py +++ b/package/kedro_viz/models/flowchart.py @@ -693,7 +693,7 @@ def set_preview(cls, _): return cls.dataset.preview() return cls.dataset.preview(**preview_args) - except Exception as exc: # pylint: disable=broad-except + except Exception as exc: # noqa: BLE001 logger.warning( "'%s' could not be previewed. Full exception: %s: %s", cls.data_node.name, @@ -723,7 +723,7 @@ def set_preview_type(cls, _): ) return preview_type_name - except Exception as exc: # pylint: disable=broad-except # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.warning( "'%s' did not have preview type. Full exception: %s: %s", cls.data_node.name, @@ -877,8 +877,7 @@ def parameter_value(self) -> Any: "Cannot find parameter `%s` in the catalog.", self.parameter_name ) return None - # pylint: disable=broad-exception-caught - except Exception as exc: # pragma: no cover + except Exception as exc: # noqa: BLE001 # pragma: no cover logger.error( "An error occurred when loading parameter `%s` in the catalog :: %s", self.parameter_name, From a7a5259fc85a33f8046f97c0768f68aa65b11c23 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 19:53:30 -0400 Subject: [PATCH 09/24] Implement `N` ruleset and add settings for it Signed-off-by: Yury Fedotov --- package/kedro_viz/data_access/managers.py | 1 - package/kedro_viz/integrations/kedro/data_loader.py | 1 - package/kedro_viz/launchers/cli/utils.py | 1 - package/kedro_viz/launchers/jupyter.py | 2 +- package/kedro_viz/models/flowchart.py | 2 -- package/kedro_viz/server.py | 2 -- package/ruff.toml | 13 +++++++++++++ 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package/kedro_viz/data_access/managers.py b/package/kedro_viz/data_access/managers.py index d853c659b..10c5987c3 100644 --- a/package/kedro_viz/data_access/managers.py +++ b/package/kedro_viz/data_access/managers.py @@ -229,7 +229,6 @@ def add_node( self.tags.add_tags(task_node.tags) return task_node - # pylint: disable=too-many-positional-arguments def add_node_input( self, registered_pipeline_id: str, diff --git a/package/kedro_viz/integrations/kedro/data_loader.py b/package/kedro_viz/integrations/kedro/data_loader.py index b4aa418ef..ef12747af 100644 --- a/package/kedro_viz/integrations/kedro/data_loader.py +++ b/package/kedro_viz/integrations/kedro/data_loader.py @@ -108,7 +108,6 @@ def _load_data_helper( return catalog, pipelines_dict, session_store, stats_dict -# pylint: disable=too-many-positional-arguments def load_data( project_path: Path, env: Optional[str] = None, diff --git a/package/kedro_viz/launchers/cli/utils.py b/package/kedro_viz/launchers/cli/utils.py index 4f089f738..720c533ac 100644 --- a/package/kedro_viz/launchers/cli/utils.py +++ b/package/kedro_viz/launchers/cli/utils.py @@ -113,7 +113,6 @@ def display_cli_message(msg, msg_color=None): ) -# pylint: disable=too-many-positional-arguments def _load_and_deploy_viz( platform, is_all_previews_enabled, diff --git a/package/kedro_viz/launchers/jupyter.py b/package/kedro_viz/launchers/jupyter.py index f51f6ce7e..78579b594 100644 --- a/package/kedro_viz/launchers/jupyter.py +++ b/package/kedro_viz/launchers/jupyter.py @@ -75,7 +75,7 @@ def dbutils_get(attr): def _display_databricks_html(port: int): # pragma: no cover url = _make_databricks_url(port) - displayHTML = _get_databricks_object("displayHTML") # pylint: disable=invalid-name + displayHTML = _get_databricks_object("displayHTML") if displayHTML is not None: displayHTML(f"""Open Kedro-Viz""") else: diff --git a/package/kedro_viz/models/flowchart.py b/package/kedro_viz/models/flowchart.py index 40588da9d..2740ac689 100644 --- a/package/kedro_viz/models/flowchart.py +++ b/package/kedro_viz/models/flowchart.py @@ -165,7 +165,6 @@ def create_task_node( ) @classmethod - # pylint: disable=too-many-positional-arguments def create_data_node( cls, dataset_id: str, @@ -218,7 +217,6 @@ def create_data_node( ) @classmethod - # pylint: disable=too-many-positional-arguments def create_parameters_node( cls, dataset_id: str, diff --git a/package/kedro_viz/server.py b/package/kedro_viz/server.py index 37d31f2f1..53c0a3199 100644 --- a/package/kedro_viz/server.py +++ b/package/kedro_viz/server.py @@ -44,7 +44,6 @@ def populate_data( data_access_manager.add_pipelines(pipelines) -# pylint: disable=too-many-positional-arguments def load_and_populate_data( path: Path, env: Optional[str] = None, @@ -71,7 +70,6 @@ def load_and_populate_data( populate_data(data_access_manager, catalog, pipelines, session_store, stats_dict) -# pylint: disable=too-many-positional-arguments, too-many-locals def run_server( host: str = DEFAULT_HOST, port: int = DEFAULT_PORT, diff --git a/package/ruff.toml b/package/ruff.toml index f13cb6548..e1af7afad 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -16,6 +16,7 @@ select = [ "E", # Pycodestyle errors "F", # Pyflakes "W", # Pycodestyle warnings + "N", # PEP8-compliant object names ] ignore = [ "E203", @@ -45,3 +46,15 @@ max-complexity = 18 [lint.pylint] max-args = 12 + +[lint.pep8-naming] +extend-ignore-names = [ + "ServiceRequestError", + "mock_DeployerFactory", + "Session", + "WaitForException", + "displayHTML", + "nodeId*", + "pipelineId*", + "*_None_*", +] From acda98f11a9d9fe57ba8c942cd77bc66e0ccd9a6 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 20:45:44 -0400 Subject: [PATCH 10/24] Eliminate individual `pylint: disable` completely Signed-off-by: Yury Fedotov --- package/features/environment.py | 2 +- package/kedro_viz/api/apps.py | 2 +- package/kedro_viz/api/graphql/schema.py | 3 --- package/kedro_viz/api/graphql/types.py | 1 - package/kedro_viz/api/rest/responses.py | 1 - package/kedro_viz/api/rest/router.py | 2 -- package/kedro_viz/data_access/managers.py | 1 - .../data_access/repositories/catalog.py | 1 - .../data_access/repositories/graph.py | 1 - .../repositories/registered_pipelines.py | 1 - .../data_access/repositories/runs.py | 3 +-- .../data_access/repositories/tags.py | 1 - .../repositories/tracking_datasets.py | 1 - .../integrations/kedro/data_loader.py | 1 - package/kedro_viz/integrations/kedro/hooks.py | 3 +-- .../integrations/kedro/sqlite_store.py | 3 +-- package/kedro_viz/launchers/cli/build.py | 1 - package/kedro_viz/launchers/cli/deploy.py | 1 - .../launchers/cli/lazy_default_group.py | 3 +-- package/kedro_viz/launchers/cli/main.py | 4 +-- package/kedro_viz/launchers/cli/run.py | 1 - package/kedro_viz/launchers/cli/utils.py | 2 -- package/kedro_viz/launchers/jupyter.py | 4 +-- .../kedro_viz/models/experiment_tracking.py | 1 - package/kedro_viz/models/flowchart.py | 2 -- package/kedro_viz/models/metadata.py | 1 - package/kedro_viz/server.py | 10 ++++---- package/ruff.toml | 25 +++++++++++++++++-- .../test_api/test_rest/test_responses.py | 1 - .../test_integrations/test_sqlite_store.py | 1 - 30 files changed, 37 insertions(+), 47 deletions(-) diff --git a/package/features/environment.py b/package/features/environment.py index b0b17df59..38fb8e0e6 100644 --- a/package/features/environment.py +++ b/package/features/environment.py @@ -97,7 +97,7 @@ def _setup_context_with_venv(context, venv_dir): return context -def after_scenario(context, scenario): +def after_scenario(context, scenario): # noqa: ARG001 for path in _PATHS_TO_REMOVE: # ignore errors when attempting to remove already removed directories shutil.rmtree(path, ignore_errors=True) diff --git a/package/kedro_viz/api/apps.py b/package/kedro_viz/api/apps.py index aef4d4471..7200ad4ab 100644 --- a/package/kedro_viz/api/apps.py +++ b/package/kedro_viz/api/apps.py @@ -42,7 +42,7 @@ def _create_base_api_app() -> FastAPI: @app.middleware("http") async def set_secure_headers(request, call_next): response = await call_next(request) - secure_headers.framework.fastapi(response) # pylint: disable=no-member + secure_headers.framework.fastapi(response) return response return app diff --git a/package/kedro_viz/api/graphql/schema.py b/package/kedro_viz/api/graphql/schema.py index bb0fb5b55..24632b57b 100644 --- a/package/kedro_viz/api/graphql/schema.py +++ b/package/kedro_viz/api/graphql/schema.py @@ -1,5 +1,4 @@ """`kedro_viz.api.graphql.schema` defines the GraphQL schema: queries and mutations.""" -# pylint: disable=missing-function-docstring,missing-class-docstring from __future__ import annotations @@ -77,7 +76,6 @@ def run_tracking_data( group: TrackingDatasetGroup, show_diff: Optional[bool] = True, ) -> List[TrackingDataset]: - # pylint: disable=line-too-long tracking_dataset_models = data_access_manager.tracking_datasets.get_tracking_datasets_by_group_by_run_ids( run_ids, group ) @@ -110,7 +108,6 @@ def run_metrics_data(self, limit: Optional[int] = 25) -> MetricPlotDataset: ] group = TrackingDatasetGroup.METRIC - # pylint: disable=line-too-long metric_dataset_models = data_access_manager.tracking_datasets.get_tracking_datasets_by_group_by_run_ids( run_ids, group ) diff --git a/package/kedro_viz/api/graphql/types.py b/package/kedro_viz/api/graphql/types.py index 86848d7e6..d5ec8ad52 100644 --- a/package/kedro_viz/api/graphql/types.py +++ b/package/kedro_viz/api/graphql/types.py @@ -1,6 +1,5 @@ """`kedro_viz.api.graphql.types` defines strawberry types.""" -# pylint: disable=too-few-public-methods,missing-class-docstring from __future__ import annotations import sys diff --git a/package/kedro_viz/api/rest/responses.py b/package/kedro_viz/api/rest/responses.py index 2f59d33b1..5a38ef6b4 100644 --- a/package/kedro_viz/api/rest/responses.py +++ b/package/kedro_viz/api/rest/responses.py @@ -1,6 +1,5 @@ """`kedro_viz.api.rest.responses` defines REST response types.""" -# pylint: disable=missing-class-docstring,invalid-name import abc import json import logging diff --git a/package/kedro_viz/api/rest/router.py b/package/kedro_viz/api/rest/router.py index 3cd6a18e9..a32e20428 100644 --- a/package/kedro_viz/api/rest/router.py +++ b/package/kedro_viz/api/rest/router.py @@ -1,6 +1,5 @@ """`kedro_viz.api.rest.router` defines REST routes and handling logic.""" -# pylint: disable=missing-function-docstring, broad-exception-caught import logging from fastapi import APIRouter @@ -74,7 +73,6 @@ async def deploy_kedro_viz(input_values: DeployerConfiguration): status_code=401, content={"message": "Please provide valid credentials"} ) except ( - # pylint: disable=catching-non-exception (FileNotFoundError, ServiceRequestError) if ServiceRequestError is not None else FileNotFoundError diff --git a/package/kedro_viz/data_access/managers.py b/package/kedro_viz/data_access/managers.py index 10c5987c3..533ef9053 100644 --- a/package/kedro_viz/data_access/managers.py +++ b/package/kedro_viz/data_access/managers.py @@ -1,6 +1,5 @@ """`kedro_viz.data_access.managers` defines data access managers.""" -# pylint: disable=too-many-instance-attributes,protected-access import logging from collections import defaultdict from typing import Dict, List, Set, Union diff --git a/package/kedro_viz/data_access/repositories/catalog.py b/package/kedro_viz/data_access/repositories/catalog.py index 6133db54d..d136c498e 100644 --- a/package/kedro_viz/data_access/repositories/catalog.py +++ b/package/kedro_viz/data_access/repositories/catalog.py @@ -1,7 +1,6 @@ """`kedro_viz.data_access.repositories.catalog` defines interface to centralise access to Kedro data catalog.""" -# pylint: disable=missing-class-docstring,missing-function-docstring,protected-access import logging from typing import TYPE_CHECKING, Dict, Optional diff --git a/package/kedro_viz/data_access/repositories/graph.py b/package/kedro_viz/data_access/repositories/graph.py index 90f734ec1..f7c652493 100644 --- a/package/kedro_viz/data_access/repositories/graph.py +++ b/package/kedro_viz/data_access/repositories/graph.py @@ -1,6 +1,5 @@ """`kedro_viz.data_access.repositories.graph` defines interface to centralise access to graph objects.""" -# pylint: disable=missing-class-docstring,missing-function-docstring from typing import Dict, Generator, List, Optional, Set from kedro_viz.models.flowchart import GraphEdge, GraphNode diff --git a/package/kedro_viz/data_access/repositories/registered_pipelines.py b/package/kedro_viz/data_access/repositories/registered_pipelines.py index 16cdd98ad..73a8af0a2 100644 --- a/package/kedro_viz/data_access/repositories/registered_pipelines.py +++ b/package/kedro_viz/data_access/repositories/registered_pipelines.py @@ -1,6 +1,5 @@ """`kedro_viz.data_access.repositories.registered_pipelines` defines repository to centralise access to registered pipelines data.""" -# pylint: disable=missing-class-docstring,missing-function-docstring from collections import OrderedDict, defaultdict from typing import Dict, List, Optional, Set diff --git a/package/kedro_viz/data_access/repositories/runs.py b/package/kedro_viz/data_access/repositories/runs.py index 453cb244c..949ceaa27 100644 --- a/package/kedro_viz/data_access/repositories/runs.py +++ b/package/kedro_viz/data_access/repositories/runs.py @@ -1,6 +1,5 @@ """`kedro_viz.data_access.repositories.runs` defines repository to centralise access to runs data from the session store.""" -# pylint: disable=missing-class-docstring,missing-function-docstring import logging from functools import wraps from typing import Callable, Dict, Iterable, List, Optional @@ -19,7 +18,7 @@ def check_db_session(method: Callable) -> Callable: @wraps(method) def func(self: "RunsRepository", *method_args, **method_kwargs): - if not self._db_session_class: # pylint: disable=protected-access + if not self._db_session_class: return None return method(self, *method_args, **method_kwargs) diff --git a/package/kedro_viz/data_access/repositories/tags.py b/package/kedro_viz/data_access/repositories/tags.py index eae5c68bb..a1493b5d0 100644 --- a/package/kedro_viz/data_access/repositories/tags.py +++ b/package/kedro_viz/data_access/repositories/tags.py @@ -1,6 +1,5 @@ """`kedro_viz.data_access.repositories.tags` defines repository to centralise access to tags data.""" -# pylint: disable=missing-class-docstring,missing-function-docstring from typing import Iterable, List, Set from kedro_viz.models.flowchart import Tag diff --git a/package/kedro_viz/data_access/repositories/tracking_datasets.py b/package/kedro_viz/data_access/repositories/tracking_datasets.py index d8d06cb9a..e8d54bc7b 100644 --- a/package/kedro_viz/data_access/repositories/tracking_datasets.py +++ b/package/kedro_viz/data_access/repositories/tracking_datasets.py @@ -1,6 +1,5 @@ """`kedro_viz.data_access.repositories.tracking_datasets` defines an interface to centralise access to datasets used in experiment tracking.""" -# pylint: disable=missing-class-docstring,missing-function-docstring,protected-access from collections import defaultdict from typing import TYPE_CHECKING, Dict, List diff --git a/package/kedro_viz/integrations/kedro/data_loader.py b/package/kedro_viz/integrations/kedro/data_loader.py index ef12747af..44d030f67 100644 --- a/package/kedro_viz/integrations/kedro/data_loader.py +++ b/package/kedro_viz/integrations/kedro/data_loader.py @@ -3,7 +3,6 @@ load data from projects created in a range of Kedro versions. """ -# pylint: disable=protected-access import json import logging diff --git a/package/kedro_viz/integrations/kedro/hooks.py b/package/kedro_viz/integrations/kedro/hooks.py index a9531989a..26bd89cd6 100644 --- a/package/kedro_viz/integrations/kedro/hooks.py +++ b/package/kedro_viz/integrations/kedro/hooks.py @@ -1,4 +1,3 @@ -# pylint: disable=protected-access """`kedro_viz.integrations.kedro.hooks` defines hooks to add additional functionalities for a kedro run.""" @@ -108,7 +107,7 @@ def create_dataset_stats(self, dataset_name: str, data: Any): """ try: - import pandas as pd # pylint: disable=import-outside-toplevel + import pandas as pd stats_dataset_name = self.get_stats_dataset_name(dataset_name) diff --git a/package/kedro_viz/integrations/kedro/sqlite_store.py b/package/kedro_viz/integrations/kedro/sqlite_store.py index 575e1ec10..6c374d5cb 100644 --- a/package/kedro_viz/integrations/kedro/sqlite_store.py +++ b/package/kedro_viz/integrations/kedro/sqlite_store.py @@ -1,7 +1,6 @@ """kedro_viz.intergrations.kedro.sqlite_store is a child of BaseSessionStore which stores sessions data in the SQLite database""" -# pylint: disable=no-member import getpass import json @@ -81,7 +80,7 @@ def _to_json(self) -> str: for key, value in self.data.items(): if key == "git": try: - import git # pylint: disable=import-outside-toplevel + import git branch = git.Repo(search_parent_directories=True).active_branch value["branch"] = branch.name diff --git a/package/kedro_viz/launchers/cli/build.py b/package/kedro_viz/launchers/cli/build.py index d50626601..b0579687e 100644 --- a/package/kedro_viz/launchers/cli/build.py +++ b/package/kedro_viz/launchers/cli/build.py @@ -1,6 +1,5 @@ """`kedro_viz.launchers.cli.build` provides a cli command to build a Kedro-Viz instance""" -# pylint: disable=import-outside-toplevel import click from kedro_viz.launchers.cli.main import viz diff --git a/package/kedro_viz/launchers/cli/deploy.py b/package/kedro_viz/launchers/cli/deploy.py index 10bb31870..3762c53c2 100644 --- a/package/kedro_viz/launchers/cli/deploy.py +++ b/package/kedro_viz/launchers/cli/deploy.py @@ -1,6 +1,5 @@ """`kedro_viz.launchers.cli.deploy` provides a cli command to deploy a Kedro-Viz instance on cloud platforms""" -# pylint: disable=import-outside-toplevel import click from kedro_viz.constants import SHAREABLEVIZ_SUPPORTED_PLATFORMS diff --git a/package/kedro_viz/launchers/cli/lazy_default_group.py b/package/kedro_viz/launchers/cli/lazy_default_group.py index 861d02322..9e832d2b9 100644 --- a/package/kedro_viz/launchers/cli/lazy_default_group.py +++ b/package/kedro_viz/launchers/cli/lazy_default_group.py @@ -1,7 +1,6 @@ """`kedro_viz.launchers.cli.lazy_default_group` provides a custom mutli-command subclass for a lazy subcommand loader""" -# pylint: disable=import-outside-toplevel from typing import Any, Union import click @@ -30,7 +29,7 @@ def __init__( super().__init__(*args, **kwargs) - def list_commands(self, ctx: click.Context) -> list[str]: + def list_commands(self, ctx: click.Context) -> list[str]: # noqa: ARG002 return sorted(self.lazy_subcommands.keys()) def get_command( # type: ignore[override] diff --git a/package/kedro_viz/launchers/cli/main.py b/package/kedro_viz/launchers/cli/main.py index 0ccb1515e..9d556ab6d 100644 --- a/package/kedro_viz/launchers/cli/main.py +++ b/package/kedro_viz/launchers/cli/main.py @@ -6,7 +6,7 @@ @click.group(name="Kedro-Viz") -def viz_cli(): # pylint: disable=missing-function-docstring +def viz_cli(): pass @@ -22,5 +22,5 @@ def viz_cli(): # pylint: disable=missing-function-docstring default_if_no_args=True, ) @click.pass_context -def viz(ctx): # pylint: disable=unused-argument +def viz(ctx): """Visualise a Kedro pipeline using Kedro viz.""" diff --git a/package/kedro_viz/launchers/cli/run.py b/package/kedro_viz/launchers/cli/run.py index 97c9ab3db..4fab6c186 100644 --- a/package/kedro_viz/launchers/cli/run.py +++ b/package/kedro_viz/launchers/cli/run.py @@ -83,7 +83,6 @@ is_flag=True, help="An experimental flag to open Kedro-Viz without Kedro project dependencies", ) -# pylint: disable=import-outside-toplevel, too-many-locals, too-many-positional-arguments def run( host, port, diff --git a/package/kedro_viz/launchers/cli/utils.py b/package/kedro_viz/launchers/cli/utils.py index 720c533ac..edc862b4d 100644 --- a/package/kedro_viz/launchers/cli/utils.py +++ b/package/kedro_viz/launchers/cli/utils.py @@ -1,5 +1,4 @@ """`kedro_viz.launchers.cli.utils` provides utility functions for cli commands.""" -# pylint: disable=import-outside-toplevel from pathlib import Path from time import sleep from typing import Union @@ -142,7 +141,6 @@ def _load_and_deploy_viz( deployer.deploy(is_all_previews_enabled) except ( - # pylint: disable=catching-non-exception (FileNotFoundError, ServiceRequestError) if ServiceRequestError is not None else FileNotFoundError diff --git a/package/kedro_viz/launchers/jupyter.py b/package/kedro_viz/launchers/jupyter.py index 78579b594..22af9fb99 100644 --- a/package/kedro_viz/launchers/jupyter.py +++ b/package/kedro_viz/launchers/jupyter.py @@ -92,9 +92,7 @@ def parse_args(args): # pragma: no cover return arg_dict -def run_viz( # pylint: disable=too-many-locals - args: str = "", local_ns: Dict[str, Any] = None -) -> None: +def run_viz(args: str = "", local_ns: Dict[str, Any] = None) -> None: """ Line magic function to start Kedro Viz with optional arguments. diff --git a/package/kedro_viz/models/experiment_tracking.py b/package/kedro_viz/models/experiment_tracking.py index 60601e328..c46a1965e 100644 --- a/package/kedro_viz/models/experiment_tracking.py +++ b/package/kedro_viz/models/experiment_tracking.py @@ -1,6 +1,5 @@ """kedro_viz.models.experiment_tracking` defines data models to represent run data and tracking datasets.""" -# pylint: disable=too-few-public-methods,protected-access,missing-function-docstring import logging from dataclasses import dataclass, field from enum import Enum diff --git a/package/kedro_viz/models/flowchart.py b/package/kedro_viz/models/flowchart.py index 2740ac689..299dbc120 100644 --- a/package/kedro_viz/models/flowchart.py +++ b/package/kedro_viz/models/flowchart.py @@ -1,6 +1,5 @@ """`kedro_viz.models.flowchart` defines data models to represent Kedro entities in a viz graph.""" -# pylint: disable=protected-access, missing-function-docstring import abc import inspect import logging @@ -466,7 +465,6 @@ def set_outputs(cls, _): return cls.kedro_node.outputs -# pylint: disable=missing-function-docstring class DataNode(GraphNode): """Represent a graph node of type data diff --git a/package/kedro_viz/models/metadata.py b/package/kedro_viz/models/metadata.py index debe1f04e..6e73c104f 100644 --- a/package/kedro_viz/models/metadata.py +++ b/package/kedro_viz/models/metadata.py @@ -1,6 +1,5 @@ """`kedro_viz.models.metadata` defines metadata for Kedro-Viz application.""" -# pylint: disable=missing-function-docstring from typing import ClassVar, List from pydantic import BaseModel, field_validator diff --git a/package/kedro_viz/server.py b/package/kedro_viz/server.py index 53c0a3199..d9b8fbc2e 100644 --- a/package/kedro_viz/server.py +++ b/package/kedro_viz/server.py @@ -25,7 +25,7 @@ def populate_data( pipelines: Dict[str, Pipeline], session_store: BaseSessionStore, stats_dict: Dict, -): # pylint: disable=redefined-outer-name +): """Populate data repositories. Should be called once on application start if creating an api app from project. """ @@ -83,7 +83,7 @@ def run_server( package_name: Optional[str] = None, extra_params: Optional[Dict[str, Any]] = None, is_lite: bool = False, -): # pylint: disable=redefined-outer-name +): """Run a uvicorn server with a FastAPI app that either launches API response data from a file or from reading data from a real Kedro project. @@ -110,10 +110,10 @@ def run_server( # Importing below dependencies inside `run_server` to avoid ImportError # when calling `load_and_populate_data` from VSCode - import fsspec # pylint: disable=C0415 - import uvicorn # pylint: disable=C0415 + import fsspec + import uvicorn - from kedro_viz.api import apps # pylint: disable=C0415 + from kedro_viz.api import apps path = Path(project_path) if project_path else Path.cwd() diff --git a/package/ruff.toml b/package/ruff.toml index e1af7afad..2859a54b5 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -17,6 +17,10 @@ select = [ "F", # Pyflakes "W", # Pycodestyle warnings "N", # PEP8-compliant object names + "SLF", # Private members access + "D101", # Class docstrings + "D103", # Function docstrings + "ARG", # Unused arguments ] ignore = [ "E203", @@ -34,9 +38,26 @@ ignore = [ "*/base_deployer.py" = ["B024"] # ABCs without abstract methods "kedro_viz/__init__.py" = ["B028"] # Risky usage of positional arguments "tests/test_integrations/test_sqlite_store.py" = ["C401"] # Unnecessary generators -"kedro_viz/data_access/repositories/tags.py" = ["C413"] # Unnecessary list call around sorted() -"kedro_viz/data_access/repositories/catalog.py" = ["PLW2901"] # Overwrite for loop variable inside the loop +"kedro_viz/data_access/repositories/tags.py" = ["C413", "D101", "D103"] +"kedro_viz/data_access/repositories/catalog.py" = ["PLW2901", "SLF", "D"] "features/steps/sh_run.py" = ["PLW1510"] # `subprocess.run` without explicit `check` argument +"tests/*.py" = ["SLF", "D", "ARG"] +"kedro_viz/models/experiment_tracking.py" = ["SLF"] +"kedro_viz/models/flowchart.py" = ["SLF"] +"kedro_viz/integrations/kedro/hooks.py" = ["SLF"] +"kedro_viz/integrations/kedro/data_loader.py" = ["SLF"] +"kedro_viz/data_access/repositories/tracking_datasets.py" = ["SLF", "D"] +"kedro_viz/data_access/managers.py" = ["SLF"] +"kedro_viz/launchers/cli/main.py" = ["D"] +"kedro_viz/api/rest/router.py" = ["D"] +"features/steps/cli_steps.py" = ["D"] +"features/environment.py" = ["D"] +"kedro_viz/api/graphql/schema.py" = ["D"] +"kedro_viz/data_access/repositories/registered_pipelines.py" = ["D"] +"kedro_viz/api/rest/responses.py" = ["D"] +"kedro_viz/api/graphql/types.py" = ["D"] +"kedro_viz/data_access/repositories/graph.py" = ["D"] +"kedro_viz/data_access/repositories/runs.py" = ["D"] [lint.isort] known-first-party = ["kedro_viz"] diff --git a/package/tests/test_api/test_rest/test_responses.py b/package/tests/test_api/test_rest/test_responses.py index 3f7590440..7029b8af9 100644 --- a/package/tests/test_api/test_rest/test_responses.py +++ b/package/tests/test_api/test_rest/test_responses.py @@ -1,4 +1,3 @@ -# pylint: disable=too-many-lines import json import operator from pathlib import Path diff --git a/package/tests/test_integrations/test_sqlite_store.py b/package/tests/test_integrations/test_sqlite_store.py index ec14c6873..682cac1a2 100644 --- a/package/tests/test_integrations/test_sqlite_store.py +++ b/package/tests/test_integrations/test_sqlite_store.py @@ -1,6 +1,5 @@ # We need to disable pylint because of this issue - # https://github.com/pylint-dev/pylint/issues/8138 -# pylint: disable=E1102 import json import os from pathlib import Path From 89afdb3616a82c468ff3fdf2dc0663154d1943f1 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 20:59:32 -0400 Subject: [PATCH 11/24] Bring risk-free formats Signed-off-by: Yury Fedotov --- package/kedro_viz/__init__.py | 1 + package/kedro_viz/api/apps.py | 1 + package/kedro_viz/api/graphql/router.py | 1 + package/kedro_viz/data_access/__init__.py | 1 + package/kedro_viz/data_access/managers.py | 6 +++--- package/kedro_viz/data_access/repositories/__init__.py | 1 + package/kedro_viz/data_access/repositories/graph.py | 1 + .../data_access/repositories/modular_pipelines.py | 1 - .../data_access/repositories/registered_pipelines.py | 1 + package/kedro_viz/data_access/repositories/runs.py | 1 + package/kedro_viz/data_access/repositories/tags.py | 1 + .../data_access/repositories/tracking_datasets.py | 1 + .../kedro_viz/integrations/deployment/azure_deployer.py | 1 + .../kedro_viz/integrations/deployment/gcp_deployer.py | 1 + package/kedro_viz/integrations/kedro/data_loader.py | 1 - package/kedro_viz/integrations/kedro/sqlite_store.py | 1 - package/kedro_viz/integrations/kedro/telemetry.py | 3 +-- package/kedro_viz/integrations/pypi/__init__.py | 1 + package/kedro_viz/launchers/cli/build.py | 1 + package/kedro_viz/launchers/cli/deploy.py | 1 + package/kedro_viz/launchers/cli/utils.py | 1 + package/kedro_viz/models/experiment_tracking.py | 1 + package/kedro_viz/services/__init__.py | 1 + package/kedro_viz/services/layers.py | 1 + package/tests/test_import.py | 9 ++++----- 25 files changed, 27 insertions(+), 13 deletions(-) diff --git a/package/kedro_viz/__init__.py b/package/kedro_viz/__init__.py index 6053ab4ea..806f783d9 100644 --- a/package/kedro_viz/__init__.py +++ b/package/kedro_viz/__init__.py @@ -1,4 +1,5 @@ """Kedro plugin for visualising a Kedro pipeline""" + import sys import warnings diff --git a/package/kedro_viz/api/apps.py b/package/kedro_viz/api/apps.py index 7200ad4ab..d5b5c535c 100644 --- a/package/kedro_viz/api/apps.py +++ b/package/kedro_viz/api/apps.py @@ -1,6 +1,7 @@ """`kedro_viz.api.app` defines the FastAPI app to serve Kedro data in a RESTful API. This data could either come from a real Kedro project or a file. """ + import json import os import time diff --git a/package/kedro_viz/api/graphql/router.py b/package/kedro_viz/api/graphql/router.py index eb0b257ef..803a5b752 100644 --- a/package/kedro_viz/api/graphql/router.py +++ b/package/kedro_viz/api/graphql/router.py @@ -1,4 +1,5 @@ """`kedro_viz.api.graphql.router` defines GraphQL routes.""" + # mypy: ignore-errors from fastapi import APIRouter from strawberry.asgi import GraphQL diff --git a/package/kedro_viz/data_access/__init__.py b/package/kedro_viz/data_access/__init__.py index 2dd525fd7..c5f408f9e 100644 --- a/package/kedro_viz/data_access/__init__.py +++ b/package/kedro_viz/data_access/__init__.py @@ -1,4 +1,5 @@ """`kedro_viz.data_access` provides an interface to save and load data for viz backend.""" + from .managers import DataAccessManager data_access_manager = DataAccessManager() diff --git a/package/kedro_viz/data_access/managers.py b/package/kedro_viz/data_access/managers.py index 533ef9053..614a6b0dc 100644 --- a/package/kedro_viz/data_access/managers.py +++ b/package/kedro_viz/data_access/managers.py @@ -389,9 +389,9 @@ def add_parameters_to_task_node( if parameters_node.is_all_parameters(): task_node.parameters = parameters_node.parameter_value else: - task_node.parameters[ - parameters_node.parameter_name - ] = parameters_node.parameter_value + task_node.parameters[parameters_node.parameter_name] = ( + parameters_node.parameter_value + ) def get_default_selected_pipeline(self) -> RegisteredPipeline: """Return the default selected pipeline ID to display on first page load. diff --git a/package/kedro_viz/data_access/repositories/__init__.py b/package/kedro_viz/data_access/repositories/__init__.py index d1210cb98..6c0d3842c 100644 --- a/package/kedro_viz/data_access/repositories/__init__.py +++ b/package/kedro_viz/data_access/repositories/__init__.py @@ -1,5 +1,6 @@ """`kedro_viz.data_access.repositories` defines repositories to centralise access to application data.""" + from .catalog import CatalogRepository from .graph import GraphEdgesRepository, GraphNodesRepository from .modular_pipelines import ModularPipelinesRepository diff --git a/package/kedro_viz/data_access/repositories/graph.py b/package/kedro_viz/data_access/repositories/graph.py index f7c652493..601e52d06 100644 --- a/package/kedro_viz/data_access/repositories/graph.py +++ b/package/kedro_viz/data_access/repositories/graph.py @@ -1,5 +1,6 @@ """`kedro_viz.data_access.repositories.graph` defines interface to centralise access to graph objects.""" + from typing import Dict, Generator, List, Optional, Set from kedro_viz.models.flowchart import GraphEdge, GraphNode diff --git a/package/kedro_viz/data_access/repositories/modular_pipelines.py b/package/kedro_viz/data_access/repositories/modular_pipelines.py index 25b7645ff..746f6700d 100644 --- a/package/kedro_viz/data_access/repositories/modular_pipelines.py +++ b/package/kedro_viz/data_access/repositories/modular_pipelines.py @@ -1,7 +1,6 @@ """`kedro_viz.data_access.repositories.modular_pipelines` defines repository to centralise access for modular pipelines data.""" - from collections import defaultdict from typing import Dict, List, Set, Tuple, Union diff --git a/package/kedro_viz/data_access/repositories/registered_pipelines.py b/package/kedro_viz/data_access/repositories/registered_pipelines.py index 73a8af0a2..d73f62186 100644 --- a/package/kedro_viz/data_access/repositories/registered_pipelines.py +++ b/package/kedro_viz/data_access/repositories/registered_pipelines.py @@ -1,5 +1,6 @@ """`kedro_viz.data_access.repositories.registered_pipelines` defines repository to centralise access to registered pipelines data.""" + from collections import OrderedDict, defaultdict from typing import Dict, List, Optional, Set diff --git a/package/kedro_viz/data_access/repositories/runs.py b/package/kedro_viz/data_access/repositories/runs.py index 949ceaa27..c2e5b7628 100644 --- a/package/kedro_viz/data_access/repositories/runs.py +++ b/package/kedro_viz/data_access/repositories/runs.py @@ -1,5 +1,6 @@ """`kedro_viz.data_access.repositories.runs` defines repository to centralise access to runs data from the session store.""" + import logging from functools import wraps from typing import Callable, Dict, Iterable, List, Optional diff --git a/package/kedro_viz/data_access/repositories/tags.py b/package/kedro_viz/data_access/repositories/tags.py index a1493b5d0..0bb46949a 100644 --- a/package/kedro_viz/data_access/repositories/tags.py +++ b/package/kedro_viz/data_access/repositories/tags.py @@ -1,5 +1,6 @@ """`kedro_viz.data_access.repositories.tags` defines repository to centralise access to tags data.""" + from typing import Iterable, List, Set from kedro_viz.models.flowchart import Tag diff --git a/package/kedro_viz/data_access/repositories/tracking_datasets.py b/package/kedro_viz/data_access/repositories/tracking_datasets.py index e8d54bc7b..ca6d47db7 100644 --- a/package/kedro_viz/data_access/repositories/tracking_datasets.py +++ b/package/kedro_viz/data_access/repositories/tracking_datasets.py @@ -1,5 +1,6 @@ """`kedro_viz.data_access.repositories.tracking_datasets` defines an interface to centralise access to datasets used in experiment tracking.""" + from collections import defaultdict from typing import TYPE_CHECKING, Dict, List diff --git a/package/kedro_viz/integrations/deployment/azure_deployer.py b/package/kedro_viz/integrations/deployment/azure_deployer.py index a14790254..ad7130e5c 100644 --- a/package/kedro_viz/integrations/deployment/azure_deployer.py +++ b/package/kedro_viz/integrations/deployment/azure_deployer.py @@ -1,5 +1,6 @@ """`kedro_viz.integrations.deployment.azure_deployer` defines deployment class for Azure Blob Storage""" + import glob import logging import mimetypes diff --git a/package/kedro_viz/integrations/deployment/gcp_deployer.py b/package/kedro_viz/integrations/deployment/gcp_deployer.py index c02010b24..3e9a6fae0 100644 --- a/package/kedro_viz/integrations/deployment/gcp_deployer.py +++ b/package/kedro_viz/integrations/deployment/gcp_deployer.py @@ -1,5 +1,6 @@ """`kedro_viz.integrations.deployment.gcp_deployer` defines deployment class for Google Cloud Storage Bucket""" + import glob import logging import mimetypes diff --git a/package/kedro_viz/integrations/kedro/data_loader.py b/package/kedro_viz/integrations/kedro/data_loader.py index 44d030f67..0e61165a1 100644 --- a/package/kedro_viz/integrations/kedro/data_loader.py +++ b/package/kedro_viz/integrations/kedro/data_loader.py @@ -3,7 +3,6 @@ load data from projects created in a range of Kedro versions. """ - import json import logging import sys diff --git a/package/kedro_viz/integrations/kedro/sqlite_store.py b/package/kedro_viz/integrations/kedro/sqlite_store.py index 6c374d5cb..40576ec0c 100644 --- a/package/kedro_viz/integrations/kedro/sqlite_store.py +++ b/package/kedro_viz/integrations/kedro/sqlite_store.py @@ -1,7 +1,6 @@ """kedro_viz.intergrations.kedro.sqlite_store is a child of BaseSessionStore which stores sessions data in the SQLite database""" - import getpass import json import logging diff --git a/package/kedro_viz/integrations/kedro/telemetry.py b/package/kedro_viz/integrations/kedro/telemetry.py index 649330401..572da919d 100644 --- a/package/kedro_viz/integrations/kedro/telemetry.py +++ b/package/kedro_viz/integrations/kedro/telemetry.py @@ -1,5 +1,4 @@ -"""`kedro_viz.integrations.kedro.telemetry` helps integrate Kedro-Viz with Kedro-Telemetry -""" +"""`kedro_viz.integrations.kedro.telemetry` helps integrate Kedro-Viz with Kedro-Telemetry""" from pathlib import Path from typing import Optional diff --git a/package/kedro_viz/integrations/pypi/__init__.py b/package/kedro_viz/integrations/pypi/__init__.py index 06f97172d..4383f2475 100644 --- a/package/kedro_viz/integrations/pypi/__init__.py +++ b/package/kedro_viz/integrations/pypi/__init__.py @@ -1,4 +1,5 @@ """`kedro_viz.integrations.pypi` provides an interface to integrate Kedro-Viz with PyPI.""" + import logging from typing import Optional, Union diff --git a/package/kedro_viz/launchers/cli/build.py b/package/kedro_viz/launchers/cli/build.py index b0579687e..6e5463978 100644 --- a/package/kedro_viz/launchers/cli/build.py +++ b/package/kedro_viz/launchers/cli/build.py @@ -1,5 +1,6 @@ """`kedro_viz.launchers.cli.build` provides a cli command to build a Kedro-Viz instance""" + import click from kedro_viz.launchers.cli.main import viz diff --git a/package/kedro_viz/launchers/cli/deploy.py b/package/kedro_viz/launchers/cli/deploy.py index 3762c53c2..75d0b8bb4 100644 --- a/package/kedro_viz/launchers/cli/deploy.py +++ b/package/kedro_viz/launchers/cli/deploy.py @@ -1,5 +1,6 @@ """`kedro_viz.launchers.cli.deploy` provides a cli command to deploy a Kedro-Viz instance on cloud platforms""" + import click from kedro_viz.constants import SHAREABLEVIZ_SUPPORTED_PLATFORMS diff --git a/package/kedro_viz/launchers/cli/utils.py b/package/kedro_viz/launchers/cli/utils.py index edc862b4d..b5a376022 100644 --- a/package/kedro_viz/launchers/cli/utils.py +++ b/package/kedro_viz/launchers/cli/utils.py @@ -1,4 +1,5 @@ """`kedro_viz.launchers.cli.utils` provides utility functions for cli commands.""" + from pathlib import Path from time import sleep from typing import Union diff --git a/package/kedro_viz/models/experiment_tracking.py b/package/kedro_viz/models/experiment_tracking.py index c46a1965e..c5bf8f9fc 100644 --- a/package/kedro_viz/models/experiment_tracking.py +++ b/package/kedro_viz/models/experiment_tracking.py @@ -1,5 +1,6 @@ """kedro_viz.models.experiment_tracking` defines data models to represent run data and tracking datasets.""" + import logging from dataclasses import dataclass, field from enum import Enum diff --git a/package/kedro_viz/services/__init__.py b/package/kedro_viz/services/__init__.py index 81991d1b4..b12ebc205 100644 --- a/package/kedro_viz/services/__init__.py +++ b/package/kedro_viz/services/__init__.py @@ -1,2 +1,3 @@ """`kedro_viz.services` provides an additional business logic layer for the API.""" + from . import layers as layers_services diff --git a/package/kedro_viz/services/layers.py b/package/kedro_viz/services/layers.py index 4eab727e8..f8840534f 100644 --- a/package/kedro_viz/services/layers.py +++ b/package/kedro_viz/services/layers.py @@ -1,4 +1,5 @@ """`kedro_viz.services.layers` defines layers-related logic.""" + import logging from collections import defaultdict from graphlib import CycleError, TopologicalSorter diff --git a/package/tests/test_import.py b/package/tests/test_import.py index e67a60c38..e9e918c6c 100644 --- a/package/tests/test_import.py +++ b/package/tests/test_import.py @@ -12,8 +12,7 @@ def test_import_kedro_viz_with_no_official_support_emits_warning(mocker): kedro_viz.__loader__.exec_module(kedro_viz) assert len(record) == 1 - assert ( - """Please be advised that Kedro Viz is not yet fully - compatible with the Python version you are currently using.""" - in record[0].message.args[0] - ) + assert """Please be advised that Kedro Viz is not yet fully + compatible with the Python version you are currently using.""" in record[ + 0 + ].message.args[0] From 80a912100e0ed4b925cbd293ab6b12ec44f25f0f Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 21:22:34 -0400 Subject: [PATCH 12/24] Switch from `...` to `pass` in dummy function definition to satisfy `ruff` Signed-off-by: Yury Fedotov --- package/tests/conftest.py | 8 ++++---- package/tests/test_api/test_rest/test_responses.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package/tests/conftest.py b/package/tests/conftest.py index d63fca7fd..7c6605132 100644 --- a/package/tests/conftest.py +++ b/package/tests/conftest.py @@ -60,10 +60,10 @@ def example_stats_dict(): @pytest.fixture def example_pipelines(): def process_data(raw_data, train_test_split): - ... + pass def train_model(model_inputs, parameters): - ... + pass data_processing_pipeline = pipeline( [ @@ -420,10 +420,10 @@ def example_catalog(): @pytest.fixture def example_transcoded_pipelines(): def process_data(raw_data, train_test_split): - ... + pass def train_model(model_inputs, parameters): - ... + pass data_processing_pipeline = pipeline( [ diff --git a/package/tests/test_api/test_rest/test_responses.py b/package/tests/test_api/test_rest/test_responses.py index 7029b8af9..6f4581d3a 100644 --- a/package/tests/test_api/test_rest/test_responses.py +++ b/package/tests/test_api/test_rest/test_responses.py @@ -627,7 +627,7 @@ def test_task_node_metadata(self, client): metadata = response.json() assert ( metadata["code"].replace(" ", "") - == "defprocess_data(raw_data,train_test_split):\n...\n" + == "defprocess_data(raw_data,train_test_split):\npass\n" ) assert metadata["parameters"] == {"uk.data_processing.train_test_split": 0.1} assert metadata["inputs"] == [ From 5812946dc9f4aa4fef53d7cc214cda8e5c09fb0b Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 21:25:01 -0400 Subject: [PATCH 13/24] Get rid of final pylint disable Signed-off-by: Yury Fedotov --- package/tests/test_api/test_graphql/test_queries.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index 16cfd36ae..05dcf6fcd 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -1,5 +1,3 @@ -# pylint:disable=line-too-long - import json import pytest From 671ada4f726e40d85022ed2cdc4d27ec12efee56 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 21:26:03 -0400 Subject: [PATCH 14/24] Update CONTRIBUTING.md Signed-off-by: Yury Fedotov --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eb3458d2c..8b8fda0c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -311,7 +311,7 @@ make pytest make e2e-tests ``` -#### Linting tests (`isort`, `black`, `pylint`, `flake8` and `mypy`) +#### Linting tests (`ruff` linter and formatter, and `mypy`) ```bash make lint From 51c05a924a00bb9126db895e8a339fc8e01db645 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 21:30:22 -0400 Subject: [PATCH 15/24] Remove `black` from requirements and Makefile Signed-off-by: Yury Fedotov --- Makefile | 4 ++-- package/test_requirements.txt | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f27718b5e..a4bfb19f9 100644 --- a/Makefile +++ b/Makefile @@ -28,11 +28,11 @@ lint: format-fix lint-check format-fix: ruff check package --fix - black package/kedro_viz package/tests package/features + ruff format package format-check: ruff check package - black --check package/kedro_viz package/tests package/features + ruff format package --check lint-check: ruff check package diff --git a/package/test_requirements.txt b/package/test_requirements.txt index 1df8b75a7..3260a2480 100644 --- a/package/test_requirements.txt +++ b/package/test_requirements.txt @@ -5,7 +5,6 @@ kedro-datasets[pandas.ParquetDataset, pandas.CSVDataset, pandas.ExcelDataset, pl kedro-telemetry>=0.1.1 # for testing telemetry integration bandit~=1.7 behave~=1.2 -black~=23.3 boto3~=1.34 matplotlib~=3.9 mypy~=1.11 From 13ba5a11c664a6c2f5cc6eb97775d743993d91d6 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 21:38:38 -0400 Subject: [PATCH 16/24] Delete reference to `pylint` issue that's no longer needed Signed-off-by: Yury Fedotov --- package/tests/test_integrations/test_sqlite_store.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/package/tests/test_integrations/test_sqlite_store.py b/package/tests/test_integrations/test_sqlite_store.py index 682cac1a2..4f0cb6a00 100644 --- a/package/tests/test_integrations/test_sqlite_store.py +++ b/package/tests/test_integrations/test_sqlite_store.py @@ -1,5 +1,3 @@ -# We need to disable pylint because of this issue - -# https://github.com/pylint-dev/pylint/issues/8138 import json import os from pathlib import Path From afaab24da23790e5fc433aaa51b670113f4a4cc6 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Tue, 22 Oct 2024 21:41:38 -0400 Subject: [PATCH 17/24] Sort `ruff.toml` Signed-off-by: Yury Fedotov --- package/ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/ruff.toml b/package/ruff.toml index 2859a54b5..6a2e7a331 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -46,8 +46,8 @@ ignore = [ "kedro_viz/models/flowchart.py" = ["SLF"] "kedro_viz/integrations/kedro/hooks.py" = ["SLF"] "kedro_viz/integrations/kedro/data_loader.py" = ["SLF"] -"kedro_viz/data_access/repositories/tracking_datasets.py" = ["SLF", "D"] "kedro_viz/data_access/managers.py" = ["SLF"] +"kedro_viz/data_access/repositories/tracking_datasets.py" = ["SLF", "D"] "kedro_viz/launchers/cli/main.py" = ["D"] "kedro_viz/api/rest/router.py" = ["D"] "features/steps/cli_steps.py" = ["D"] From aad35025514a15c4a2147ac113cc5ba34d8e8d7d Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 00:10:45 -0400 Subject: [PATCH 18/24] Introduce hierarchical config Signed-off-by: Yury Fedotov --- demo-project/ruff.toml | 5 +++ package/ruff.toml | 79 +--------------------------------------- ruff.toml | 83 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 demo-project/ruff.toml create mode 100644 ruff.toml diff --git a/demo-project/ruff.toml b/demo-project/ruff.toml new file mode 100644 index 000000000..ca826c294 --- /dev/null +++ b/demo-project/ruff.toml @@ -0,0 +1,5 @@ +extend = "../ruff.toml" + +[lint.isort] +known-first-party = ["demo_project"] +known-third-party = ["kedro"] diff --git a/package/ruff.toml b/package/ruff.toml index 6a2e7a331..8ac1da3d2 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -1,81 +1,4 @@ -target-version = "py39" - -include = [ - "kedro_viz/*.py", - "tests/*.py", - "features/*.py", -] - -[lint] -select = [ - "I", # Isort - "B", # Bugbear - "BLE", # Blind exceptions - "PL", # Pylint - "C90", # Mccabe complexity - "E", # Pycodestyle errors - "F", # Pyflakes - "W", # Pycodestyle warnings - "N", # PEP8-compliant object names - "SLF", # Private members access - "D101", # Class docstrings - "D103", # Function docstrings - "ARG", # Unused arguments -] -ignore = [ - "E203", - "E231", - "E266", - "E501", - "F401", - "B030", # Except handler is something other than exception class - "C405", # Inconsistent definition of literal collections - "PLR2004", # Magic values in comparisons -] - -[lint.per-file-ignores] -"*/cli_steps.py" = ["B011"] # assert False instead of AssertionError -"*/base_deployer.py" = ["B024"] # ABCs without abstract methods -"kedro_viz/__init__.py" = ["B028"] # Risky usage of positional arguments -"tests/test_integrations/test_sqlite_store.py" = ["C401"] # Unnecessary generators -"kedro_viz/data_access/repositories/tags.py" = ["C413", "D101", "D103"] -"kedro_viz/data_access/repositories/catalog.py" = ["PLW2901", "SLF", "D"] -"features/steps/sh_run.py" = ["PLW1510"] # `subprocess.run` without explicit `check` argument -"tests/*.py" = ["SLF", "D", "ARG"] -"kedro_viz/models/experiment_tracking.py" = ["SLF"] -"kedro_viz/models/flowchart.py" = ["SLF"] -"kedro_viz/integrations/kedro/hooks.py" = ["SLF"] -"kedro_viz/integrations/kedro/data_loader.py" = ["SLF"] -"kedro_viz/data_access/managers.py" = ["SLF"] -"kedro_viz/data_access/repositories/tracking_datasets.py" = ["SLF", "D"] -"kedro_viz/launchers/cli/main.py" = ["D"] -"kedro_viz/api/rest/router.py" = ["D"] -"features/steps/cli_steps.py" = ["D"] -"features/environment.py" = ["D"] -"kedro_viz/api/graphql/schema.py" = ["D"] -"kedro_viz/data_access/repositories/registered_pipelines.py" = ["D"] -"kedro_viz/api/rest/responses.py" = ["D"] -"kedro_viz/api/graphql/types.py" = ["D"] -"kedro_viz/data_access/repositories/graph.py" = ["D"] -"kedro_viz/data_access/repositories/runs.py" = ["D"] +extend = "../ruff.toml" [lint.isort] known-first-party = ["kedro_viz"] - -[lint.mccabe] -max-complexity = 18 - -[lint.pylint] -max-args = 12 - -[lint.pep8-naming] -extend-ignore-names = [ - "ServiceRequestError", - "mock_DeployerFactory", - "Session", - "WaitForException", - "displayHTML", - "nodeId*", - "pipelineId*", - "*_None_*", -] diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..029295e53 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,83 @@ +target-version = "py39" + +include = [ + "package/kedro_viz/*.py", + "package/tests/*.py", + "package/features/*.py", + "demo-project/*.py", +] + +[lint] +select = [ + "I", # Isort + "B", # Bugbear + "BLE", # Blind exceptions + "PL", # Pylint + "C90", # Mccabe complexity + "E", # Pycodestyle errors + "F", # Pyflakes + "W", # Pycodestyle warnings + "N", # PEP8-compliant object names + "SLF", # Private members access + "D101", # Class docstrings + "D103", # Function docstrings + "ARG", # Unused arguments +] +ignore = [ + "E203", + "E231", + "E266", + "E501", + "F401", + "B030", # Except handler is something other than exception class + "C405", # Inconsistent definition of literal collections + "PLR2004", # Magic values in comparisons +] + +[lint.per-file-ignores] +"*/cli_steps.py" = ["B011"] # assert False instead of AssertionError +"*/base_deployer.py" = ["B024"] # ABCs without abstract methods +"package/kedro_viz/__init__.py" = ["B028"] # Risky usage of positional arguments +"package/tests/test_integrations/test_sqlite_store.py" = ["C401"] # Unnecessary generators +"package/kedro_viz/data_access/repositories/tags.py" = ["C413", "D101", "D103"] +"package/kedro_viz/data_access/repositories/catalog.py" = ["PLW2901", "SLF", "D"] +"package/features/steps/sh_run.py" = ["PLW1510"] # `subprocess.run` without explicit `check` argument +"*/tests/*.py" = ["SLF", "D", "ARG"] +"package/kedro_viz/models/experiment_tracking.py" = ["SLF"] +"package/kedro_viz/models/flowchart.py" = ["SLF"] +"package/kedro_viz/integrations/kedro/hooks.py" = ["SLF"] +"package/kedro_viz/integrations/kedro/data_loader.py" = ["SLF"] +"package/kedro_viz/data_access/managers.py" = ["SLF"] +"package/kedro_viz/data_access/repositories/tracking_datasets.py" = ["SLF", "D"] +"package/kedro_viz/launchers/cli/main.py" = ["D"] +"package/kedro_viz/api/rest/router.py" = ["D"] +"package/features/steps/cli_steps.py" = ["D"] +"package/features/environment.py" = ["D"] +"package/kedro_viz/api/graphql/schema.py" = ["D"] +"package/kedro_viz/data_access/repositories/registered_pipelines.py" = ["D"] +"package/kedro_viz/api/rest/responses.py" = ["D"] +"package/kedro_viz/api/graphql/types.py" = ["D"] +"package/kedro_viz/data_access/repositories/graph.py" = ["D"] +"package/kedro_viz/data_access/repositories/runs.py" = ["D"] +"demo-project/*.py" = ["D", "ARG", "PLW0603"] # Allow unused arguments in node functions for them to generate constant outputs, but mimic the DAG and technically have inputs. + +[lint.mccabe] +max-complexity = 18 + +[lint.pylint] +max-args = 12 + +[lint.pep8-naming] +extend-ignore-names = [ + "ServiceRequestError", + "mock_DeployerFactory", + "Session", + "WaitForException", + "displayHTML", + "nodeId*", + "pipelineId*", + "*_None_*", + "X_test", + "X_train", + "X", +] From 582e98ed961b35e82b7812c4ff716ea97607cf57 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 00:13:41 -0400 Subject: [PATCH 19/24] Apply `ruff` lint and format fixes to demo project Signed-off-by: Yury Fedotov --- demo-project/docs/source/conf.py | 1 + demo-project/src/demo_project/__init__.py | 3 +-- demo-project/src/demo_project/__main__.py | 1 + demo-project/src/demo_project/hooks.py | 1 + demo-project/src/demo_project/pipeline_registry.py | 4 +++- .../demo_project/pipelines/data_ingestion/pipeline.py | 10 +++++----- .../pipelines/feature_engineering/pipeline.py | 1 - .../src/demo_project/pipelines/modelling/nodes.py | 10 +++------- .../src/demo_project/pipelines/modelling/pipeline.py | 6 +++--- .../demo_project/pipelines/reporting/image_utils.py | 1 - .../src/demo_project/pipelines/reporting/nodes.py | 5 ++++- .../src/demo_project/pipelines/reporting/pipeline.py | 2 +- demo-project/src/tests/test_run.py | 1 + 13 files changed, 24 insertions(+), 22 deletions(-) diff --git a/demo-project/docs/source/conf.py b/demo-project/docs/source/conf.py index 4220ef0a6..25f0f2626 100644 --- a/demo-project/docs/source/conf.py +++ b/demo-project/docs/source/conf.py @@ -22,6 +22,7 @@ from kedro.framework.cli.utils import find_stylesheets from recommonmark.transform import AutoStructify + from demo_project import __version__ as release # -- Project information ----------------------------------------------------- diff --git a/demo-project/src/demo_project/__init__.py b/demo-project/src/demo_project/__init__.py index 8ed604c68..72074eaac 100644 --- a/demo-project/src/demo_project/__init__.py +++ b/demo-project/src/demo_project/__init__.py @@ -1,4 +1,3 @@ -"""demo-project -""" +"""demo-project""" __version__ = "0.1" diff --git a/demo-project/src/demo_project/__main__.py b/demo-project/src/demo_project/__main__.py index e9c8eea9f..9b25b41ce 100644 --- a/demo-project/src/demo_project/__main__.py +++ b/demo-project/src/demo_project/__main__.py @@ -1,6 +1,7 @@ """demo-project file for ensuring the package is executable as `demo-project` and `python -m demo_project` """ + from pathlib import Path from kedro.framework.project import configure_project diff --git a/demo-project/src/demo_project/hooks.py b/demo-project/src/demo_project/hooks.py index c2bb3ef03..3f4b47498 100644 --- a/demo-project/src/demo_project/hooks.py +++ b/demo-project/src/demo_project/hooks.py @@ -1,4 +1,5 @@ """Project hooks.""" + import logging import time from typing import Any diff --git a/demo-project/src/demo_project/pipeline_registry.py b/demo-project/src/demo_project/pipeline_registry.py index 659a3701a..49fa22539 100644 --- a/demo-project/src/demo_project/pipeline_registry.py +++ b/demo-project/src/demo_project/pipeline_registry.py @@ -1,4 +1,5 @@ """Project pipelines.""" + from typing import Dict from kedro.pipeline import Pipeline @@ -8,6 +9,7 @@ from demo_project.pipelines import modelling as mod from demo_project.pipelines import reporting as rep + def register_pipelines() -> Dict[str, Pipeline]: """Register the project's pipelines. @@ -24,7 +26,7 @@ def register_pipelines() -> Dict[str, Pipeline]: ) reporting_pipeline = rep.create_pipeline() - + return { "__default__": ( ingestion_pipeline diff --git a/demo-project/src/demo_project/pipelines/data_ingestion/pipeline.py b/demo-project/src/demo_project/pipelines/data_ingestion/pipeline.py index 1acbdf953..49904271b 100755 --- a/demo-project/src/demo_project/pipelines/data_ingestion/pipeline.py +++ b/demo-project/src/demo_project/pipelines/data_ingestion/pipeline.py @@ -27,21 +27,21 @@ def create_pipeline(**kwargs) -> Pipeline: func=apply_types_to_companies, inputs="companies", outputs="int_typed_companies", - name='apply_types_to_companies', - tags='companies' + name="apply_types_to_companies", + tags="companies", ), node( func=apply_types_to_shuttles, inputs="shuttles", outputs="int_typed_shuttles@pandas1", - name='apply_types_to_shuttles', - tags='shuttles' + name="apply_types_to_shuttles", + tags="shuttles", ), node( func=apply_types_to_reviews, inputs=["reviews", "params:typing.reviews.columns_as_floats"], outputs="int_typed_reviews", - name='apply_types_to_reviews' + name="apply_types_to_reviews", ), node( func=aggregate_company_data, diff --git a/demo-project/src/demo_project/pipelines/feature_engineering/pipeline.py b/demo-project/src/demo_project/pipelines/feature_engineering/pipeline.py index f4706df75..fe8f87e27 100644 --- a/demo-project/src/demo_project/pipelines/feature_engineering/pipeline.py +++ b/demo-project/src/demo_project/pipelines/feature_engineering/pipeline.py @@ -3,7 +3,6 @@ generated using Kedro 0.18.1 """ - from kedro.pipeline import Pipeline, node from kedro.pipeline.modular_pipeline import pipeline diff --git a/demo-project/src/demo_project/pipelines/modelling/nodes.py b/demo-project/src/demo_project/pipelines/modelling/nodes.py index 94382c0ec..a56b974ce 100755 --- a/demo-project/src/demo_project/pipelines/modelling/nodes.py +++ b/demo-project/src/demo_project/pipelines/modelling/nodes.py @@ -85,15 +85,11 @@ def evaluate_model( """ y_pred = regressor.predict(X_test) score = r2_score(y_test, y_pred) - a2_score = random.randint(0,100)*0.1 - b2_score = random.randint(0,100)*0.1 + a2_score = random.randint(0, 100) * 0.1 + b2_score = random.randint(0, 100) * 0.1 logger = logging.getLogger(__name__) logger.info( f"Model has a coefficient R^2 of {score:.3f} on test data using a " f"regressor of type '{type(regressor)}'" ) - return { - "r2_score": score, - "a2_score":a2_score, - "b2_score":b2_score - } + return {"r2_score": score, "a2_score": a2_score, "b2_score": b2_score} diff --git a/demo-project/src/demo_project/pipelines/modelling/pipeline.py b/demo-project/src/demo_project/pipelines/modelling/pipeline.py index 808a4e77e..1244720b1 100755 --- a/demo-project/src/demo_project/pipelines/modelling/pipeline.py +++ b/demo-project/src/demo_project/pipelines/modelling/pipeline.py @@ -22,13 +22,13 @@ def new_train_eval_template() -> Pipeline: func=train_model, inputs=["X_train", "y_train", "params:dummy_model_options"], outputs=["regressor", "experiment_params"], - tags="train" + tags="train", ), node( func=evaluate_model, inputs=["regressor", "X_test", "y_test"], outputs="r2_score", - tags="evaluate" + tags="evaluate", ), ] ) @@ -83,7 +83,7 @@ def create_pipeline(model_types: List[str]) -> Pipeline: pipeline( pipe=new_train_eval_template(), parameters={"dummy_model_options": f"model_options.{model_type}"}, - inputs={k: k for k in test_train_refs}, + inputs={k: k for k in test_train_refs}, namespace=model_type, ) for model_type in model_types diff --git a/demo-project/src/demo_project/pipelines/reporting/image_utils.py b/demo-project/src/demo_project/pipelines/reporting/image_utils.py index 701d1d1b2..00334dd9f 100644 --- a/demo-project/src/demo_project/pipelines/reporting/image_utils.py +++ b/demo-project/src/demo_project/pipelines/reporting/image_utils.py @@ -22,7 +22,6 @@ def __init__(self, _df: pd.DataFrame, x: int = 500, y: int = 200): self._populate(_df) def _draw_grid(self): - width, height = self.image.size row_step = (height - self.border * 2) / (self.rows) col_step = (width - self.border * 2) / (self.cols) diff --git a/demo-project/src/demo_project/pipelines/reporting/nodes.py b/demo-project/src/demo_project/pipelines/reporting/nodes.py index cd4796ceb..dbcc8033a 100644 --- a/demo-project/src/demo_project/pipelines/reporting/nodes.py +++ b/demo-project/src/demo_project/pipelines/reporting/nodes.py @@ -2,6 +2,9 @@ This is a boilerplate pipeline 'reporting' generated using Kedro 0.18.1 """ + +from typing import Dict + import matplotlib.pyplot as plt import numpy as np import pandas as pd @@ -9,7 +12,7 @@ import plotly.express as px import seaborn as sn from plotly import graph_objects as go -from typing import Dict + from .image_utils import DrawTable diff --git a/demo-project/src/demo_project/pipelines/reporting/pipeline.py b/demo-project/src/demo_project/pipelines/reporting/pipeline.py index 4b6eb4e6d..e7db18ef5 100644 --- a/demo-project/src/demo_project/pipelines/reporting/pipeline.py +++ b/demo-project/src/demo_project/pipelines/reporting/pipeline.py @@ -8,10 +8,10 @@ from demo_project.pipelines.reporting.nodes import ( create_feature_importance_plot, create_matplotlib_chart, + get_top_shuttles_data, make_cancel_policy_bar_chart, make_price_analysis_image, make_price_histogram, - get_top_shuttles_data, ) diff --git a/demo-project/src/tests/test_run.py b/demo-project/src/tests/test_run.py index cedc6bcd4..0097339aa 100644 --- a/demo-project/src/tests/test_run.py +++ b/demo-project/src/tests/test_run.py @@ -7,6 +7,7 @@ To run the tests, run ``kedro test``. """ + from pathlib import Path import pytest From 4600f92fdd9391d29f2e39f223fc190ec754386a Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 00:16:10 -0400 Subject: [PATCH 20/24] Remove `package` directory pointer from `make lint` Signed-off-by: Yury Fedotov --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a4bfb19f9..864537c6b 100644 --- a/Makefile +++ b/Makefile @@ -27,15 +27,15 @@ e2e-tests: lint: format-fix lint-check format-fix: - ruff check package --fix - ruff format package + ruff check --fix + ruff format format-check: - ruff check package - ruff format package --check + ruff check + ruff format --check lint-check: - ruff check package + ruff check mypy --config-file=package/mypy.ini package/kedro_viz package/features mypy --disable-error-code abstract --config-file=package/mypy.ini package/tests From 233cf2fa344da9465a84192259a4447a729abf42 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 00:32:19 -0400 Subject: [PATCH 21/24] Refactor all `demo_project` dev workflows to `ruff` Signed-off-by: Yury Fedotov --- demo-project/.pre-commit-config.yaml | 30 ++++--------------- demo-project/pyproject.toml | 8 ----- demo-project/setup.cfg | 3 -- demo-project/src/demo_project/requirements.in | 4 +-- .../repositories/tracking_datasets.py | 2 +- .../kedro_viz/models/experiment_tracking.py | 2 +- ruff.toml | 1 + 7 files changed, 9 insertions(+), 41 deletions(-) delete mode 100644 demo-project/setup.cfg diff --git a/demo-project/.pre-commit-config.yaml b/demo-project/.pre-commit-config.yaml index 921362983..cbf969987 100644 --- a/demo-project/.pre-commit-config.yaml +++ b/demo-project/.pre-commit-config.yaml @@ -14,31 +14,11 @@ repos: - id: check-json # Checks json files for parseable syntax. - id: check-case-conflict # Check for files that would conflict in case-insensitive filesystems - id: check-merge-conflict # Check for files that contain merge conflict strings. - - id: debug-statements # Check for debugger imports and py37+ `breakpoint()` calls in python source. - id: requirements-txt-fixer # Sorts entries in requirements.txt - - id: flake8 - args: - - "--max-line-length=100" - - "--max-complexity=18" - - "--max-complexity=18" - - "--select=B,C,E,F,W,T4,B9" - - "--ignore=E203,E266,E501,W503" - - repo: local + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.0 hooks: - - id: isort - name: "Sort imports" - language: system - types: [file, python] - entry: isort - - id: black - name: "Black" - language: system - types: [file, python] - entry: black - - id: kedro lint - name: "Kedro lint" - language: python_venv - types: [file, python] - entry: kedro lint - stages: [commit] + - id: ruff + args: [--fix] + - id: ruff-format diff --git a/demo-project/pyproject.toml b/demo-project/pyproject.toml index 0be0a5449..76b0de5fc 100644 --- a/demo-project/pyproject.toml +++ b/demo-project/pyproject.toml @@ -3,14 +3,6 @@ package_name = "demo_project" project_name = "modular-spaceflights" kedro_init_version = "0.19.0" -[tool.isort] -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -use_parentheses = true -line_length = 88 -known_third_party = "kedro" - [tool.pytest.ini_options] addopts = """ --cov-report term-missing \ diff --git a/demo-project/setup.cfg b/demo-project/setup.cfg deleted file mode 100644 index 63ea67300..000000000 --- a/demo-project/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length=88 -extend-ignore=E203 diff --git a/demo-project/src/demo_project/requirements.in b/demo-project/src/demo_project/requirements.in index dff89fa8d..3d6956618 100644 --- a/demo-project/src/demo_project/requirements.in +++ b/demo-project/src/demo_project/requirements.in @@ -1,7 +1,4 @@ -black~=22.0 -flake8>=3.7.9, <4.0 ipython~=7.0 -isort~=5.0 jupyter~=1.0 jupyter_client>=5.1, <7.0 jupyterlab~=3.0 @@ -16,4 +13,5 @@ wheel>=0.35, <0.37 pillow~=9.0 matplotlib==3.5.0 pre-commit~=1.17 +ruff==0.7.0 seaborn>=0.13.0 diff --git a/package/kedro_viz/data_access/repositories/tracking_datasets.py b/package/kedro_viz/data_access/repositories/tracking_datasets.py index ca6d47db7..911bc439a 100644 --- a/package/kedro_viz/data_access/repositories/tracking_datasets.py +++ b/package/kedro_viz/data_access/repositories/tracking_datasets.py @@ -17,7 +17,7 @@ from kedro.io import AbstractVersionedDataset except ImportError: # older versions - from kedro.io import ( # type: ignore # isort:skip + from kedro.io import ( # type: ignore AbstractVersionedDataSet as AbstractVersionedDataset, ) diff --git a/package/kedro_viz/models/experiment_tracking.py b/package/kedro_viz/models/experiment_tracking.py index c5bf8f9fc..516b1d2a1 100644 --- a/package/kedro_viz/models/experiment_tracking.py +++ b/package/kedro_viz/models/experiment_tracking.py @@ -21,7 +21,7 @@ from kedro.io import AbstractVersionedDataset except ImportError: # older versions - from kedro.io import ( # type: ignore # isort:skip + from kedro.io import ( # type: ignore AbstractVersionedDataSet as AbstractVersionedDataset, ) diff --git a/ruff.toml b/ruff.toml index 029295e53..72033e0a9 100644 --- a/ruff.toml +++ b/ruff.toml @@ -22,6 +22,7 @@ select = [ "D101", # Class docstrings "D103", # Function docstrings "ARG", # Unused arguments + "T10", # Debug statements ] ignore = [ "E203", From 337cce6a44ef87207bd845171193aeae813b8bb9 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 00:59:06 -0400 Subject: [PATCH 22/24] Replace a few BLE noqas by config exclude Signed-off-by: Yury Fedotov --- package/kedro_viz/integrations/kedro/hooks.py | 8 ++++---- package/kedro_viz/integrations/kedro/sqlite_store.py | 2 +- ruff.toml | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package/kedro_viz/integrations/kedro/hooks.py b/package/kedro_viz/integrations/kedro/hooks.py index 26bd89cd6..3089e61f5 100644 --- a/package/kedro_viz/integrations/kedro/hooks.py +++ b/package/kedro_viz/integrations/kedro/hooks.py @@ -36,7 +36,7 @@ def after_catalog_created(self, catalog: DataCatalog): # Temporary try/except block so the Kedro develop branch can work with Viz. try: self.datasets = catalog._datasets - except Exception: # noqa: BLE001 # pragma: no cover + except Exception: # pragma: no cover # Support for Kedro 0.18.x self.datasets = catalog._data_sets # type: ignore[attr-defined] @@ -92,7 +92,7 @@ def after_pipeline_run(self): } json.dump(sorted_stats_data, file) - except Exception as exc: # noqa: BLE001 # pragma: no cover + except Exception as exc: # pragma: no cover logger.warning( "Unable to write dataset statistics for the pipeline: %s", exc ) @@ -128,7 +128,7 @@ def create_dataset_stats(self, dataset_name: str, data: Any): dataset_name, exc, ) - except Exception as exc: # noqa: BLE001 # pragma: no cover + except Exception as exc: # pragma: no cover logger.warning( "[hook: after_dataset_saved] Unable to create statistics for the dataset %s : %s", dataset_name, @@ -153,7 +153,7 @@ def get_file_size(self, dataset: Any) -> Union[int, None]: ) return dataset._fs.size(file_path) - except Exception as exc: # noqa: BLE001 + except Exception as exc: logger.warning( "Unable to get file size for the dataset %s: %s", dataset, exc ) diff --git a/package/kedro_viz/integrations/kedro/sqlite_store.py b/package/kedro_viz/integrations/kedro/sqlite_store.py index 40576ec0c..8ba1a5ac9 100644 --- a/package/kedro_viz/integrations/kedro/sqlite_store.py +++ b/package/kedro_viz/integrations/kedro/sqlite_store.py @@ -85,7 +85,7 @@ def _to_json(self) -> str: value["branch"] = branch.name except ImportError as exc: # pragma: no cover logger.warning("%s:%s", exc.__class__.__name__, exc.msg) - except Exception as exc: # noqa: BLE001 # pragma: no cover + except Exception as exc: # pragma: no cover logger.warning("Something went wrong when fetching git metadata.") logger.warning(exc) diff --git a/ruff.toml b/ruff.toml index 72033e0a9..52a1d6c8f 100644 --- a/ruff.toml +++ b/ruff.toml @@ -46,7 +46,8 @@ ignore = [ "*/tests/*.py" = ["SLF", "D", "ARG"] "package/kedro_viz/models/experiment_tracking.py" = ["SLF"] "package/kedro_viz/models/flowchart.py" = ["SLF"] -"package/kedro_viz/integrations/kedro/hooks.py" = ["SLF"] +"package/kedro_viz/integrations/kedro/hooks.py" = ["SLF", "BLE"] +"package/kedro_viz/integrations/kedro/sqlite_store.py" = ["BLE"] "package/kedro_viz/integrations/kedro/data_loader.py" = ["SLF"] "package/kedro_viz/data_access/managers.py" = ["SLF"] "package/kedro_viz/data_access/repositories/tracking_datasets.py" = ["SLF", "D"] From 57a320071ad139256a77dadd8d3fe93b207078f1 Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 01:14:54 -0400 Subject: [PATCH 23/24] Modify RELEASE.md Signed-off-by: Yury Fedotov --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index 66d6a51a2..aaed5e9a5 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -18,6 +18,7 @@ Please follow the established format: - Fix unserializable parameters value (#2122) - Display full dataset type with library prefix in metadata panel (#2136) - Enable SQLite WAL mode for Azure ML to fix database locking issues (#2131) +- Replace `flake8`, `isort`, `pylint` and `black` by `ruff` (#2149) # Release 10.0.0 From 267c50ff84eaa4c6cc420f9835aff921393dc77a Mon Sep 17 00:00:00 2001 From: Yury Fedotov Date: Wed, 23 Oct 2024 08:25:55 -0400 Subject: [PATCH 24/24] Add `kedro` to 3rd party imports of `package` Signed-off-by: Yury Fedotov --- package/ruff.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/package/ruff.toml b/package/ruff.toml index 8ac1da3d2..c911fbf7e 100644 --- a/package/ruff.toml +++ b/package/ruff.toml @@ -2,3 +2,4 @@ extend = "../ruff.toml" [lint.isort] known-first-party = ["kedro_viz"] +known-third-party = ["kedro"]