From 6864fdce71f1604facf0ab374feb9b46c694329e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 18 Dec 2023 22:13:13 +0200 Subject: [PATCH] Pre-commit fixes (#763) * pre-commit: don't prescribe python 3.8 * pre-commit: get rid of yesqa, it's for flake8 only flake8 was dropped in https://github.com/nteract/papermill/pull/752 * pre-commit: use ruff's UP rules instead of pyupgrade --- .pre-commit-config.yaml | 17 +---------------- papermill/exceptions.py | 10 +++++----- papermill/tests/test_inspect.py | 2 +- papermill/tests/test_translators.py | 2 +- papermill/translators.py | 2 +- pyproject.toml | 3 +++ 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index adb877b6..7574a1fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,3 @@ -default_language_version: - python: python3.8 - ci: autofix_prs: true autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions' @@ -21,13 +18,6 @@ repos: - id: check-docstring-first - id: detect-private-key - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: ["--py38-plus"] - name: Upgrade code - #- repo: https://github.com/myint/docformatter # rev: v1.5.0 # hooks: @@ -55,13 +45,8 @@ repos: - mdformat-gfm - mdformat_frontmatter - - repo: https://github.com/asottile/yesqa - rev: v1.5.0 - hooks: - - id: yesqa - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.4 + rev: v0.1.8 hooks: - id: ruff args: ["--fix"] diff --git a/papermill/exceptions.py b/papermill/exceptions.py index 363f255b..95c2d1ef 100644 --- a/papermill/exceptions.py +++ b/papermill/exceptions.py @@ -59,8 +59,8 @@ class PapermillParameterOverwriteWarning(PapermillWarning): def missing_dependency_generator(package, dep): def missing_dep(): raise PapermillOptionalDependencyException( - "The {package} optional dependency is missing. " - "Please run pip install papermill[{dep}] to install this dependency".format(package=package, dep=dep) + f"The {package} optional dependency is missing. " + f"Please run pip install papermill[{dep}] to install this dependency" ) return missing_dep @@ -69,9 +69,9 @@ def missing_dep(): def missing_environment_variable_generator(package, env_key): def missing_dep(): raise PapermillOptionalDependencyException( - "The {package} optional dependency is present, but the environment " - "variable {env_key} is not set. Please set this variable as " - "required by {package} on your platform.".format(package=package, env_key=env_key) + f"The {package} optional dependency is present, but the environment " + f"variable {env_key} is not set. Please set this variable as " + f"required by {package} on your platform." ) return missing_dep diff --git a/papermill/tests/test_inspect.py b/papermill/tests/test_inspect.py index f2b476c1..3b1cca7f 100644 --- a/papermill/tests/test_inspect.py +++ b/papermill/tests/test_inspect.py @@ -94,7 +94,7 @@ def test_str_path(): [ "Dummy usage", "\nParameters inferred for notebook '{name}':", - "\n Can't infer anything about this notebook's parameters. It may not have any parameter defined.", # noqa + "\n Can't infer anything about this notebook's parameters. It may not have any parameter defined.", ], ), ], diff --git a/papermill/tests/test_translators.py b/papermill/tests/test_translators.py index 232630ae..0edc1f07 100644 --- a/papermill/tests/test_translators.py +++ b/papermill/tests/test_translators.py @@ -87,7 +87,7 @@ def test_translate_comment_python(test_input, expected): [Parameter("a", "List[str]", "['this','is','a','string','list']", "Nice variable a")], ), ( - "a: List[str] = [\n 'this',\n 'is',\n 'a',\n 'string',\n 'list'\n] # Nice variable a", # noqa + "a: List[str] = [\n 'this',\n 'is',\n 'a',\n 'string',\n 'list'\n] # Nice variable a", [Parameter("a", "List[str]", "['this','is','a','string','list']", "Nice variable a")], ), ( diff --git a/papermill/translators.py b/papermill/translators.py index e1e5095c..1cb43d89 100644 --- a/papermill/translators.py +++ b/papermill/translators.py @@ -143,7 +143,7 @@ def inspect(cls, parameters_cell): class PythonTranslator(Translator): # Pattern to capture parameters within cell input PARAMETER_PATTERN = re.compile( - r"^(?P\w[\w_]*)\s*(:\s*[\"']?(?P\w[\w_\[\],\s]*)[\"']?\s*)?=\s*(?P.*?)(\s*#\s*(type:\s*(?P[^\s]*)\s*)?(?P.*))?$" # noqa + r"^(?P\w[\w_]*)\s*(:\s*[\"']?(?P\w[\w_\[\],\s]*)[\"']?\s*)?=\s*(?P.*?)(\s*#\s*(type:\s*(?P[^\s]*)\s*)?(?P.*))?$" ) @classmethod diff --git a/pyproject.toml b/pyproject.toml index eb7e07b2..3f2fd235 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ ignore-words-list = "dne, compiletime" [tool.ruff] +target-version = "py38" line-length = 120 # Enable Pyflakes `E` and `F` codes by default. select = [ @@ -42,6 +43,8 @@ select = [ "I", # isort # "D", # see: https://pypi.org/project/pydocstyle # "N", # see: https://pypi.org/project/pep8-naming + "RUF100", # unnecessary noqa comment + "UP", # pyupgrade ] #extend-select = [ # "C4", # see: https://pypi.org/project/flake8-comprehensions