From 1e3edc977ab976667becfcb97b2f8c7ffa843cf5 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Thu, 14 Nov 2024 15:26:40 +0100 Subject: [PATCH 01/15] Add Ruff for lint/format; clean-up pre-commit --- .pre-commit-config.yaml | 102 +++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76ade282..51fb1f0a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,52 +8,70 @@ repos: hooks: - id: end-of-file-fixer - id: trailing-whitespace - exclude: miscellaneous/structures/SiO2.xyz - id: check-yaml - id: check-added-large-files args: [--maxkb=6000] - - repo: https://github.com/pycqa/isort - rev: 5.13.2 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.3 hooks: - - id: isort - args: [--profile, black, --filter-files] - - repo: https://github.com/PyCQA/autoflake - rev: v2.3.1 - hooks: - - id: autoflake - - repo: https://github.com/asottile/pyupgrade - rev: v3.16.0 - hooks: - - id: pyupgrade - args: [--py38-plus] - - repo: https://github.com/psf/black - rev: 24.4.2 - hooks: - - id: black - language_version: python3 # Should be a command that runs python3.6+ - - repo: https://github.com/PyCQA/flake8 - rev: 7.1.0 - hooks: - - id: flake8 - args: [--count, --show-source, --statistics] - additional_dependencies: - - flake8-bugbear - - flake8-builtins - - flake8-comprehensions - - flake8-debugger - - flake8-logging-format - - pep8-naming - - pyflakes - - tryceratops - # - repo: https://github.com/pre-commit/mirrors-mypy - # rev: v1.5.1 - # hooks: - # - id: mypy - # additional_dependencies: - # - types-click-spinner - # - types-requests - # - types-tabulate - # - types-toml + # Ruff check + - id: ruff + types_or: [python, pyi] + args: [--no-fix] + name: ruff (check) + # Ruff fix + - id: ruff + types_or: [python, pyi] + args: [--fix] + name: ruff (fix) + # Ruff formatter + - id: ruff-format + types_or: [python, pyi] + name: ruff (format) + # + # - repo: https://github.com/pycqa/isort + # rev: 5.13.2 + # hooks: + # - id: isort + # args: [--profile, black, --filter-files] + # - repo: https://github.com/PyCQA/autoflake + # rev: v2.3.1 + # hooks: + # - id: autoflake + # - repo: https://github.com/asottile/pyupgrade + # rev: v3.16.0 + # hooks: + # - id: pyupgrade + # args: [--py38-plus] + # - repo: https://github.com/psf/black + # rev: 24.4.2 + # hooks: + # - id: black + # language_version: python3 # Should be a command that runs python3.6+ + # - repo: https://github.com/PyCQA/flake8 + # rev: 7.1.0 + # hooks: + # - id: flake8 + # args: [--count, --show-source, --statistics] + # additional_dependencies: + # - flake8-bugbear + # - flake8-builtins + # - flake8-comprehensions + # - flake8-debugger + # - flake8-logging-format + # - pep8-naming + # - pyflakes + # - tryceratops + # - repo: https://github.com/pre-commit/mirrors-mypy + # rev: v1.5.1 + # hooks: + # - id: mypy + # additional_dependencies: + # - types-click-spinner + # - types-requests + # - types-tabulate + # - types-toml + # - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt rev: 0.2.3 hooks: From 490ffd0f8e516887eb94221dfdc56d39998444ea Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Thu, 14 Nov 2024 15:43:23 +0100 Subject: [PATCH 02/15] Cleanup pre-commit stuff; remove some unneded config files --- .flake8 | 8 ------- .pre-commit-config.yaml | 49 ---------------------------------------- pyproject.toml | 50 +++++++++++++++++++++++++++++++++++++++++ pytest.ini | 2 -- 4 files changed, 50 insertions(+), 59 deletions(-) delete mode 100644 .flake8 create mode 100644 pyproject.toml delete mode 100644 pytest.ini diff --git a/.flake8 b/.flake8 deleted file mode 100644 index c84a0d1b..00000000 --- a/.flake8 +++ /dev/null @@ -1,8 +0,0 @@ -[flake8] -ignore = - E501 - W503 - E203 - TRY301 -per-file-ignores = - binder/ipython_config.py:E266 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 51fb1f0a..c0300005 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,11 +14,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.7.3 hooks: - # Ruff check - - id: ruff - types_or: [python, pyi] - args: [--no-fix] - name: ruff (check) # Ruff fix - id: ruff types_or: [python, pyi] @@ -28,50 +23,6 @@ repos: - id: ruff-format types_or: [python, pyi] name: ruff (format) - # - # - repo: https://github.com/pycqa/isort - # rev: 5.13.2 - # hooks: - # - id: isort - # args: [--profile, black, --filter-files] - # - repo: https://github.com/PyCQA/autoflake - # rev: v2.3.1 - # hooks: - # - id: autoflake - # - repo: https://github.com/asottile/pyupgrade - # rev: v3.16.0 - # hooks: - # - id: pyupgrade - # args: [--py38-plus] - # - repo: https://github.com/psf/black - # rev: 24.4.2 - # hooks: - # - id: black - # language_version: python3 # Should be a command that runs python3.6+ - # - repo: https://github.com/PyCQA/flake8 - # rev: 7.1.0 - # hooks: - # - id: flake8 - # args: [--count, --show-source, --statistics] - # additional_dependencies: - # - flake8-bugbear - # - flake8-builtins - # - flake8-comprehensions - # - flake8-debugger - # - flake8-logging-format - # - pep8-naming - # - pyflakes - # - tryceratops - # - repo: https://github.com/pre-commit/mirrors-mypy - # rev: v1.5.1 - # hooks: - # - id: mypy - # additional_dependencies: - # - types-click-spinner - # - types-requests - # - types-tabulate - # - types-toml - # - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt rev: 0.2.3 hooks: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..73964896 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,50 @@ +[tool.ruff] +# Line length (same as Black) +line-length = 88 + +# Python target version +target-version = "py38" + +# Ignored rules for the entire project +[tool.ruff.lint] +ignore = [ + "E501", # Line too long + "E203", # Whitespace before ':' + "TRY301", # Raise within try block + # "W503" # Line break before binary operator (not PEP8 enforced, so not implemented in Ruff) +] + +# flake8 plugins to enable: +# - flake8-bugbear B +# - flake8-builtins A +# - flake8-comprehensions C4 +# - flake8-debugger T10 +# - flake8-logging-format G +# - pep8-naming N +# - pyflakes F +# - tryceratops TRY +select = [ + "A", # flake8-builtins + "T10", # flake8-debugger + "E", # pycodestyle errors + "F", # pyflakes + "I", # isort + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "N", # pep8-naming + "UP", # pyupgrade + "TRY", # tryceratops +] + +# Per-file rule ignores +[tool.ruff.lint.per-file-ignores] +"binder/ipython_config.py" = ["E266"] # Trailing whitespace in comment + +# Ruff formatting +[tool.ruff.format] +quote-style = "double" +indent-style = "space" + +# pytest +[tool.pytest.ini_options] +addopts = "-v --tb=short" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index bbd083ac..00000000 --- a/pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = --tb=short From b5f3c6fbba33cb574577aa961984c3762ce9bc91 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:54:09 +0000 Subject: [PATCH 03/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tutorial/tests/test_functional_programming.py | 2 +- tutorial/tests/test_input_output.py | 4 +--- tutorial/toc.py | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tutorial/tests/test_functional_programming.py b/tutorial/tests/test_functional_programming.py index 8cf0c240..d9ef3fda 100644 --- a/tutorial/tests/test_functional_programming.py +++ b/tutorial/tests/test_functional_programming.py @@ -143,7 +143,7 @@ def reference_exercise6(my_list: List[Tuple[str, int]]) -> List[Tuple[str, float def test_exercise6( - function_to_test: Callable[[List[Tuple[str, int]]], List[Tuple[str, float]]] + function_to_test: Callable[[List[Tuple[str, int]]], List[Tuple[str, float]]], ): input_data = reference_exercise5(get_data_exercise5()) assert function_to_test(input_data) == reference_exercise6(input_data) diff --git a/tutorial/tests/test_input_output.py b/tutorial/tests/test_input_output.py index 419aa8f3..152b7258 100644 --- a/tutorial/tests/test_input_output.py +++ b/tutorial/tests/test_input_output.py @@ -75,9 +75,7 @@ def test_write_file(function_to_test, tmp_path: pl.Path): function_to_test(tmp_user) reference_write_file(tmp_test) - assert ( - tmp_user.exists() - ), """The file was not created. Make sure to create the file in the function. Hint: use `open(output_file, "w")`""" + assert tmp_user.exists(), """The file was not created. Make sure to create the file in the function. Hint: use `open(output_file, "w")`""" assert ( tmp_user.read_text() == tmp_test.read_text() diff --git a/tutorial/toc.py b/tutorial/toc.py index 2a8814a0..93c72f58 100755 --- a/tutorial/toc.py +++ b/tutorial/toc.py @@ -1,5 +1,6 @@ #!/usr/bin/env python """CLI script to build a table of contents for an IPython notebook""" + import argparse as ap import pathlib import re From 6ea8055a38efa8620733d1979f1a4ee5c2a0a080 Mon Sep 17 00:00:00 2001 From: Snowwpanda Date: Fri, 15 Nov 2024 16:04:33 +0100 Subject: [PATCH 04/15] Fixing --- tutorial/tests/test_functions_advanced.py | 8 +++++--- tutorial/tests/testsuite/testsuite.py | 2 +- tutorial/toc.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tutorial/tests/test_functions_advanced.py b/tutorial/tests/test_functions_advanced.py index dd6bc4dd..371b26e1 100644 --- a/tutorial/tests/test_functions_advanced.py +++ b/tutorial/tests/test_functions_advanced.py @@ -144,6 +144,10 @@ def hello(name): def reference_once(allowed_time: int = 15) -> t.Callable: """Decorator to run a function at most once""" + class TooSoonError(RuntimeError): + def __init__(self, wait: float): + super().__init__(f"Wait another {wait:.2f} seconds") + def decorator(func: t.Callable) -> t.Callable: timer = 0.0 @@ -156,9 +160,7 @@ def wrapper(*args, **kwargs) -> t.Any: return func(*args, **kwargs) if (stop := time.perf_counter()) - timer < allowed_time: - raise RuntimeError( - f"Wait another {allowed_time - (stop - timer):.2f} seconds" - ) + raise TooSoonError(allowed_time - (stop - timer)) timer = time.perf_counter() diff --git a/tutorial/tests/testsuite/testsuite.py b/tutorial/tests/testsuite/testsuite.py index 4cccc262..30c12b57 100644 --- a/tutorial/tests/testsuite/testsuite.py +++ b/tutorial/tests/testsuite/testsuite.py @@ -273,7 +273,7 @@ def ipytest(self, line: str, cell: str): if not ( module_file := pathlib.Path(f"tutorial/tests/test_{self.module_name}.py") ).exists(): - raise FileNotFoundError(f"Module file '{module_file}' does not exist") + raise FileNotFoundError(module_file) self.module_file = module_file diff --git a/tutorial/toc.py b/tutorial/toc.py index 93c72f58..c1a382ed 100755 --- a/tutorial/toc.py +++ b/tutorial/toc.py @@ -83,7 +83,7 @@ def main(): args = parser.parse_args() if not (input_nb := pathlib.Path(args.notebook)).exists(): - raise FileNotFoundError(f"Notebook '{input_nb}' does not exist.") + raise FileNotFoundError(input_nb) if args.output is None: output_nb = input_nb.with_suffix(".toc.ipynb") From 0cc1a4b859d856896bbf872c74b22f4349415b58 Mon Sep 17 00:00:00 2001 From: Snowwpanda Date: Fri, 15 Nov 2024 16:09:28 +0100 Subject: [PATCH 05/15] Replacing variable l: E741 Ambiguous variable name: `l` --- tutorial/tests/test_functions.py | 2 +- tutorial/tests/test_library_scipy.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorial/tests/test_functions.py b/tutorial/tests/test_functions.py index 1f49708a..644f5872 100644 --- a/tutorial/tests/test_functions.py +++ b/tutorial/tests/test_functions.py @@ -297,7 +297,7 @@ def test_password_validator2(start: int, end: int, function_to_test) -> None: # Exercise: Buckets reorganization # -prio = {l: i for i, l in enumerate(ascii_lowercase + ascii_uppercase, start=1)} +prio = {letter: i for i, letter in enumerate(ascii_lowercase + ascii_uppercase, start=1)} buckets_1, buckets_2 = (read_data(f"buckets_{num}.txt") for num in (1, 2)) diff --git a/tutorial/tests/test_library_scipy.py b/tutorial/tests/test_library_scipy.py index 8c34f3ac..c2c3e74f 100644 --- a/tutorial/tests/test_library_scipy.py +++ b/tutorial/tests/test_library_scipy.py @@ -39,10 +39,10 @@ def reference_lu(): # 1. TODO: define the matrix a_ref here: a_ref = np.array([[9, 3, 3], [3, 2, 2], [3, 4, 2]]) # 2. TODO: call the lu function here: - p, l, u = lu(a_ref) + p_matrix, l_matrix, u_matrix = lu(a_ref) # 3. TODO: return p, l, u matrices in this order here: - return p, l, u + return p_matrix, l_matrix, u_matrix def test_lu(function_to_test): From 0d1427a72acee65466a09a3636e10349e652790c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:09:50 +0000 Subject: [PATCH 06/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tutorial/tests/test_functions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tutorial/tests/test_functions.py b/tutorial/tests/test_functions.py index 644f5872..c0ad1b9a 100644 --- a/tutorial/tests/test_functions.py +++ b/tutorial/tests/test_functions.py @@ -297,7 +297,9 @@ def test_password_validator2(start: int, end: int, function_to_test) -> None: # Exercise: Buckets reorganization # -prio = {letter: i for i, letter in enumerate(ascii_lowercase + ascii_uppercase, start=1)} +prio = { + letter: i for i, letter in enumerate(ascii_lowercase + ascii_uppercase, start=1) +} buckets_1, buckets_2 = (read_data(f"buckets_{num}.txt") for num in (1, 2)) From 570cacc7b609a42a11f0470f8ac08d0ce8c7ab9a Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Mon, 18 Nov 2024 13:13:20 +0100 Subject: [PATCH 07/15] Double-check Ruff lint & format behavior --- .pre-commit-config.yaml | 8 ++++---- pyproject.toml | 38 +++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c0300005..50c0dfac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -12,7 +12,7 @@ repos: - id: check-added-large-files args: [--maxkb=6000] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.3 + rev: v0.7.4 hooks: # Ruff fix - id: ruff @@ -28,10 +28,10 @@ repos: hooks: - id: yamlfmt - repo: https://github.com/asottile/setup-cfg-fmt - rev: v2.5.0 + rev: v2.7.0 hooks: - id: setup-cfg-fmt - repo: https://github.com/kynan/nbstripout - rev: 0.7.1 + rev: 0.8.1 hooks: - id: nbstripout diff --git a/pyproject.toml b/pyproject.toml index 73964896..1184065c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.ruff] -# Line length (same as Black) +# Line length (Black default) line-length = 88 # Python target version @@ -8,37 +8,41 @@ target-version = "py38" # Ignored rules for the entire project [tool.ruff.lint] ignore = [ - "E501", # Line too long - "E203", # Whitespace before ':' - "TRY301", # Raise within try block + "E501", # Line too long + "E203", # Whitespace before ':' + # "TRY301", # Raise within try block (this is actually a good practice) # "W503" # Line break before binary operator (not PEP8 enforced, so not implemented in Ruff) ] # flake8 plugins to enable: -# - flake8-bugbear B -# - flake8-builtins A -# - flake8-comprehensions C4 -# - flake8-debugger T10 -# - flake8-logging-format G -# - pep8-naming N -# - pyflakes F -# - tryceratops TRY +# - flake8-bugbear B +# - flake8-builtins A +# - flake8-comprehensions C4 +# - flake8-debugger T10 +# - flake8-logging-format G +# - pep8-naming N +# - pyflakes F +# - tryceratops TRY select = [ "A", # flake8-builtins - "T10", # flake8-debugger - "E", # pycodestyle errors - "F", # pyflakes - "I", # isort "B", # flake8-bugbear "C4", # flake8-comprehensions + "T10", # flake8-debugger + "G", # flake8-logging-format "N", # pep8-naming - "UP", # pyupgrade + "F", # pyflakes "TRY", # tryceratops + "I", # isort + "E", # pycodestyle errors + "UP", # pyupgrade ] # Per-file rule ignores [tool.ruff.lint.per-file-ignores] "binder/ipython_config.py" = ["E266"] # Trailing whitespace in comment +"tutorial/tests/test_object_oriented_programming.py" = [ + "B904", +] # suppress raise ... from err # Ruff formatting [tool.ruff.format] From a378750ecf50ff5f5a61691be567572cc7e0775c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:13:55 +0000 Subject: [PATCH 08/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tutorial/tests/test_object_oriented_programming.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorial/tests/test_object_oriented_programming.py b/tutorial/tests/test_object_oriented_programming.py index 5be87d87..43af192a 100644 --- a/tutorial/tests/test_object_oriented_programming.py +++ b/tutorial/tests/test_object_oriented_programming.py @@ -177,8 +177,8 @@ def test_oop_str_and_repr(first_name, last_name, function_to_test): validate_oop_str_method(solution_result) validate_oop_repr_method(solution_result) - assert str(solution_result) == str( - reference_result + assert ( + str(solution_result) == str(reference_result) ), "The __str__() result does not match the template 'My name is {first_name} {last_name}'." assert ( solution_result.__repr__() == reference_result.__repr__() From edcfed5aaae6337c6fc35796a9726e4b89ee9b84 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Mon, 18 Nov 2024 17:09:43 +0100 Subject: [PATCH 09/15] Normalize YAML formatting --- .github/workflows/build-docker-image.yml | 48 ++++++++-------- .pre-commit-config.yaml | 70 +++++++++++++----------- binder/environment.yml | 38 ++++++------- 3 files changed, 82 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 41d4da70..e5995102 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -1,30 +1,30 @@ --- name: Build Tutorial Container on: - push: - branches: - - main - paths-ignore: - - '*.md' - - slides/** - - images/** - - .gitignore - workflow_dispatch: + push: + branches: + - main + paths-ignore: + - '*.md' + - slides/** + - images/** + - .gitignore + workflow_dispatch: jobs: - repo2docker: - runs-on: ubuntu-latest - permissions: - packages: write - steps: - - name: checkout files in repo - uses: actions/checkout@main + repo2docker: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: checkout files in repo + uses: actions/checkout@main - - name: update jupyter dependencies with repo2docker - uses: jupyterhub/repo2docker-action@master - with: - DOCKER_USERNAME: ${{ github.actor }} - DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} - DOCKER_REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - FORCE_REPO2DOCKER_VERSION: jupyter-repo2docker==2023.06.0 + - name: update jupyter dependencies with repo2docker + uses: jupyterhub/repo2docker-action@master + with: + DOCKER_USERNAME: ${{ github.actor }} + DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + DOCKER_REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + FORCE_REPO2DOCKER_VERSION: jupyter-repo2docker==2023.06.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50c0dfac..30851d70 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,37 +1,45 @@ --- ci: - autoupdate_schedule: quarterly + autoupdate_schedule: quarterly repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: end-of-file-fixer - - id: trailing-whitespace - - id: check-yaml - - id: check-added-large-files - args: [--maxkb=6000] - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 - hooks: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-yaml + - id: check-added-large-files + args: [--maxkb=6000] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.4 + hooks: # Ruff fix - - id: ruff - types_or: [python, pyi] - args: [--fix] - name: ruff (fix) + - id: ruff + types_or: [python, pyi] + args: [--fix] + name: ruff (fix) # Ruff formatter - - id: ruff-format - types_or: [python, pyi] - name: ruff (format) - - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt - rev: 0.2.3 - hooks: - - id: yamlfmt - - repo: https://github.com/asottile/setup-cfg-fmt - rev: v2.7.0 - hooks: - - id: setup-cfg-fmt - - repo: https://github.com/kynan/nbstripout - rev: 0.8.1 - hooks: - - id: nbstripout + - id: ruff-format + types_or: [python, pyi] + name: ruff (format) + - repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint + args: [--format, parsable] + name: YAML (check) + - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt + rev: 0.2.3 + hooks: + - id: yamlfmt + args: [--mapping, '2', --sequence, '4', --offset, '2'] + name: YAML (format) + - repo: https://github.com/asottile/setup-cfg-fmt + rev: v2.7.0 + hooks: + - id: setup-cfg-fmt + - repo: https://github.com/kynan/nbstripout + rev: 0.8.1 + hooks: + - id: nbstripout diff --git a/binder/environment.yml b/binder/environment.yml index 9aa9817f..7d382e1d 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -1,23 +1,23 @@ --- name: python-tutorial channels: - - conda-forge + - conda-forge dependencies: - - python=3.10 - - pip - - pip: - - numpy - - matplotlib - - pandas - - ipywidgets - - ipynbname - - jupyterlab - - pytest - - pytest-timeout - - markdown - - pre-commit - - geostatspy - - gstools - - scikit-learn - - attrs - - multiprocess + - python=3.10 + - pip + - pip: + - numpy + - matplotlib + - pandas + - ipywidgets + - ipynbname + - jupyterlab + - pytest + - pytest-timeout + - markdown + - pre-commit + - geostatspy + - gstools + - scikit-learn + - attrs + - multiprocess From 9bdfe5db06bde2f2a5e8caf5e2d0ad820f74d1ad Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Mon, 18 Nov 2024 17:15:14 +0100 Subject: [PATCH 10/15] Explain why B904 is ignored in OOP test --- pyproject.toml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1184065c..f7e54a65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,10 +39,14 @@ select = [ # Per-file rule ignores [tool.ruff.lint.per-file-ignores] -"binder/ipython_config.py" = ["E266"] # Trailing whitespace in comment -"tutorial/tests/test_object_oriented_programming.py" = [ - "B904", -] # suppress raise ... from err +# Trailing whitespace in comment +"binder/ipython_config.py" = ["E266"] +# suppress `raise ... from err` +# Why we ignore B904 from the object-oriented tests? +# We do want to raise an assertion error if the check on the solution function attributes fails, +# but Python by default will raise a TypeError via vars(solution_result) +# if the result is not a class and therefore doesn't have a __dict__ attribute. +"tutorial/tests/test_object_oriented_programming.py" = ["B904"] # Ruff formatting [tool.ruff.format] From 46cd79899a0fccba4c3ef2ea82cfb2427de9562f Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Tue, 19 Nov 2024 10:37:28 +0100 Subject: [PATCH 11/15] Removed hook 'jumanjihouse/pre-commit-hook-yamlfmt' Due to a bug on Windows, which makes it very fragile Check out: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt/pull/42 --- .pre-commit-config.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 30851d70..5e891c3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,6 @@ --- ci: autoupdate_schedule: quarterly - repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -29,12 +28,12 @@ repos: - id: yamllint args: [--format, parsable] name: YAML (check) - - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt - rev: 0.2.3 + - repo: https://github.com/google/yamlfmt + rev: v0.14.0 hooks: - id: yamlfmt - args: [--mapping, '2', --sequence, '4', --offset, '2'] name: YAML (format) + types: [yaml] - repo: https://github.com/asottile/setup-cfg-fmt rev: v2.7.0 hooks: From 3ef7e19d0362e91aec02e184928a8999c37df56c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:39:02 +0000 Subject: [PATCH 12/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/build-docker-image.yml | 3 --- .pre-commit-config.yaml | 1 - binder/environment.yml | 1 - 3 files changed, 5 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index e5995102..41b4364a 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -1,4 +1,3 @@ ---- name: Build Tutorial Container on: push: @@ -10,7 +9,6 @@ on: - images/** - .gitignore workflow_dispatch: - jobs: repo2docker: runs-on: ubuntu-latest @@ -19,7 +17,6 @@ jobs: steps: - name: checkout files in repo uses: actions/checkout@main - - name: update jupyter dependencies with repo2docker uses: jupyterhub/repo2docker-action@master with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e891c3e..f1d20cb2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,3 @@ ---- ci: autoupdate_schedule: quarterly repos: diff --git a/binder/environment.yml b/binder/environment.yml index 7d382e1d..c43c346e 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -1,4 +1,3 @@ ---- name: python-tutorial channels: - conda-forge From d2b0ddd5e7ed4d0702161e764535132046ac3563 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Tue, 19 Nov 2024 10:40:37 +0100 Subject: [PATCH 13/15] Add yaml formatter hook config --- .github/workflows/build-docker-image.yml | 1 + .pre-commit-config.yaml | 1 + .yamlfmt | 5 +++++ binder/environment.yml | 1 + 4 files changed, 8 insertions(+) create mode 100644 .yamlfmt diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 41b4364a..d012f10a 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -1,3 +1,4 @@ +--- name: Build Tutorial Container on: push: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f1d20cb2..5e891c3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +--- ci: autoupdate_schedule: quarterly repos: diff --git a/.yamlfmt b/.yamlfmt new file mode 100644 index 00000000..437e1ceb --- /dev/null +++ b/.yamlfmt @@ -0,0 +1,5 @@ +formatter: + type: basic + include_document_start: true + retain_line_breaks: true +output_format: line diff --git a/binder/environment.yml b/binder/environment.yml index c43c346e..7d382e1d 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -1,3 +1,4 @@ +--- name: python-tutorial channels: - conda-forge From 85cc660875a7f331302db455641811725939692b Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 09:45:39 +0100 Subject: [PATCH 14/15] Remove yamllint --- .pre-commit-config.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e891c3e..9a058f5a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,12 +22,6 @@ repos: - id: ruff-format types_or: [python, pyi] name: ruff (format) - - repo: https://github.com/adrienverge/yamllint - rev: v1.35.1 - hooks: - - id: yamllint - args: [--format, parsable] - name: YAML (check) - repo: https://github.com/google/yamlfmt rev: v0.14.0 hooks: From 956dfe6c38c2e6a6b566ec0a7a7a04b41448ed46 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Wed, 20 Nov 2024 11:54:55 +0100 Subject: [PATCH 15/15] Remove setup-cfg-fmt hook --- .pre-commit-config.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9a058f5a..c62419bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,10 +28,6 @@ repos: - id: yamlfmt name: YAML (format) types: [yaml] - - repo: https://github.com/asottile/setup-cfg-fmt - rev: v2.7.0 - hooks: - - id: setup-cfg-fmt - repo: https://github.com/kynan/nbstripout rev: 0.8.1 hooks: