Skip to content

Commit

Permalink
Use ruff instead of flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Nov 25, 2023
1 parent 57b59c7 commit a66961b
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 37 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ jobs:
- name: Install the workflow call library
run: |
python3 -m pip install .[docs,lint,tests]
- name: Run flake8
- name: Clean build files
run: |
python3 -m flake8 .
python3 -m nbqa flake8 .
git clean -xdf
- name: Run ruff
run: |
python3 -m ruff .
python3 -m nbqa ruff .
- name: Run isort
run: |
python3 -m isort --check --diff .
Expand Down
2 changes: 1 addition & 1 deletion open_in_cloud_workflow/add_installation_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _package_is_imported(package_import: str, cell: nbformat.NotebookNode) -> bo
return f"import {package_import}" in cell.source or f"from {package_import}" in cell.source


def __main__(
def __main__( # noqa: N807
work_dir: str, nb_pattern: str, cloud_provider: str, fem_on_cloud_packages: str, pip_packages: str
) -> None:
"""Add installation cells on top of every notebook in the work directory matching the prescribed pattern."""
Expand Down
2 changes: 1 addition & 1 deletion open_in_cloud_workflow/replace_images_in_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def replace_images_in_markdown(
return updated_nb_cells


def __main__(work_dir: str, nb_pattern: str) -> None:
def __main__(work_dir: str, nb_pattern: str) -> None: # noqa: N807
"""Replace images in every notebook in the work directory matching the prescribed pattern."""
images_as_base64 = glob_images(work_dir)

Expand Down
2 changes: 1 addition & 1 deletion open_in_cloud_workflow/replace_links_in_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def replace_links_in_markdown(
return updated_nb_cells


def __main__(
def __main__( # noqa: N807
work_dir: str, nb_pattern: str, cloud_provider: str, publisher: typing.Union[str, PublishOnBaseClass]
) -> None:
"""Replace links in every notebook in the work directory matching the prescribed pattern."""
Expand Down
40 changes: 17 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ docs = [
"sphinx"
]
lint = [
"flake8",
"flake8-annotations",
"flake8-docstrings",
"flake8-import-restrictions",
"flake8-isort",
"Flake8-pyproject",
"flake8-quotes",
"isort",
"mypy",
"ruff",
"yamllint"
]
tests = [
Expand All @@ -65,21 +60,6 @@ tests = [
"requests"
]

[tool.flake8]
max-line-length = 120
show-source = true
docstring-convention = "numpy"
inline-quotes = "double"
imr241_exclude = ["open_in_cloud_workflow", "open_in_cloud_workflow.*"]
imr245_include = "*"
imr245_exclude = ["open_in_cloud_workflow", "open_in_cloud_workflow.*"]
ignore = ["ANN101", "W503"]
exclude = [".eggs", "build", "dist"]
per-file-ignores = [
"open_in_cloud_workflow/__init__.py: F401",
"tests/data/**/*.py: D100, I004"
]

[tool.isort]
line_length = 120
multi_line_output = 4
Expand All @@ -90,7 +70,6 @@ combine_as_imports = true
check_untyped_defs = true
disallow_any_unimported = true
disallow_untyped_defs = true
exclude = "(^\\.eggs|^build|^dist|conftest\\.py$)"
no_implicit_optional = true
pretty = true
show_error_codes = true
Expand All @@ -105,3 +84,18 @@ ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "requests"
ignore_missing_imports = true

[tool.ruff]
line-length = 120
select = ["ANN", "D", "E", "F", "ICN", "N", "Q", "RUF", "W"]
ignore = ["ANN101"]

[tool.ruff.per-file-ignores]
"open_in_cloud_workflow/__init__.py" = ["F401"]
"tests/data/**/*.py" = ["D100"]

[tool.ruff.pycodestyle]
max-doc-length = 120

[tool.ruff.pydocstyle]
convention = "numpy"
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def root_directory() -> str:
@pytest.fixture
def open_notebook(root_directory: str) -> typing.Callable[[str, str, typing.Optional[str]], nbformat.NotebookNode]:
"""Return a fixture to open a local notebook."""
def _(local_directory: str, filename: str, data_directory: str = None) -> nbformat.NotebookNode:
def _(local_directory: str, filename: str, data_directory: typing.Optional[str] = None) -> nbformat.NotebookNode:
"""Open notebook with nbformat."""
if data_directory is None:
data_directory = os.path.join(root_directory, "tests", "data")
Expand Down
2 changes: 1 addition & 1 deletion tests/data/add_installation_cells/from_numpy_import.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"metadata": {},
"outputs": [],
"source": [
"from numpy import * # noqa: F401, F403, IMR241, IMR243, IMR245"
"from numpy import * # noqa: F403"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"outputs": [],
"source": [
"import mpi4py # type: ignore[import-not-found] # noqa: F401\n",
"import numpy # noqa: F401"
"import numpy as np # noqa: F401"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion tests/data/add_installation_cells/import_numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy # noqa: F401"
"import numpy as np # noqa: F401"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy # noqa: F401"
"import numpy as np # noqa: F401"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion tests/data/add_installation_cells/import_numpy_scipy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy # noqa: F401\n",
"import numpy as np # noqa: F401\n",
"import scipy # type: ignore[import-not-found] # noqa: F401"
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/data/replace_images_in_markdown/image_and_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy # noqa: F401"
"import numpy as np # noqa: F401"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion tests/data/replace_links_in_markdown/link_and_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy # noqa: F401"
"import numpy as np # noqa: F401"
]
}
],
Expand Down

0 comments on commit a66961b

Please sign in to comment.