Skip to content

Commit

Permalink
build: Upgrade precommits (#115)
Browse files Browse the repository at this point in the history
* build: Update pre commit configuration

* refactor: Update code to support new pre-commits

* build: Upgrade version

* refactor: Solve test issues for python 3.9

* build: Upgrade mlflow version

* docs: Update changelog

* docs: Update readme

* build: Remove black from dev dependencies

* build: Replace certain pylint checks with ruff

* refactor: Apply updated pre-commits

* build: Fix wrong pylintrc file

* fix: Fix wrong variable used in function

* build: Reformat pylintrc to use tabs

* build: Replace mlflow requirement with mlflow-skinny
  • Loading branch information
lorenzomammana authored May 3, 2024
1 parent 2b175e6 commit 5d5dbe6
Show file tree
Hide file tree
Showing 89 changed files with 1,436 additions and 1,620 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1_bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ body:
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell
render: shell
57 changes: 9 additions & 48 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
fail_fast: true

repos:
- repo: local
hooks:
- id: ruff
name: ruff
files: \.py$
entry: ruff
language: python
exclude: ^(tests|scripts|notebooks|quadra/utils/tests)/
- repo: local
hooks:
- id: jupyter-nb-clear-output
Expand All @@ -23,47 +15,16 @@ repos:
- id: prettier
name: (prettier) Reformat YAML files with prettier
types: [yaml]

- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
name: Remove unused variables and imports
language: python
entry: autoflake
types: [python]
args:
[
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variables",
"--expand-star-imports",
"--ignore-init-module-imports",
]
files: \.py$
- repo: local
hooks:
- id: isort
name: (isort) Sorting import statements
args: [--settings-path=pyproject.toml]
language: python
types: [python]
files: \.py$
entry: isort
- repo: local
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
hooks:
- id: black
name: (black) Format Python code
args: [--config=pyproject.toml]
language: python
types: [python]
entry: black
- id: black-jupyter
name: (black-jupyter) Format jupyter notebooks
args: [--config=pyproject.toml]
language: python
types: [jupyter]
entry: black
- id: ruff
types_or: [python, pyi, jupyter]
args: ["--config", "pyproject.toml", "--fix"]
exclude: ^(tests|scripts|notebooks|quadra/utils/tests)/
- id: ruff-format
types_or: [python, pyi, jupyter]
args: ["--config", "pyproject.toml"]
- repo: local
hooks:
- id: pylint
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
# Changelog
All notable changes to this project will be documented in this file.

### [2.1.4]

#### Updated

- Remove black from pre-commit hooks
- Use ruff as the main formatter and linting tool
- Upgrade mypy version
- Upgrade mlflow version
- Apply new pre-commits to all tests
- Update most of typing to py310 style

### [2.1.3]

#### Updated
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
</p>

<div align="center">

<a href="https://github.com/astral-sh/ruff">
<img
src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json"
alt="ruff"
></a>
<a href="https://github.com/pre-commit/pre-commit"><img
src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white"
alt="pre-commit"
Expand All @@ -27,14 +31,6 @@
src="https://www.mypy-lang.org/static/mypy_badge.svg"
alt="Checked with mypy"
/></a>
<a href="https://github.com/psf/black"><img
src="https://img.shields.io/badge/code%20style-black-000000.svg"
alt="black"
/></a>
<a href="https://pycqa.github.io/isort/"><img
src="https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336"
alt="isort"
/></a>

</div>

Expand Down Expand Up @@ -251,7 +247,7 @@ First clone the repository from `Github`, then we need to install the package wi

Now you can start developing and the pre-commit hooks will run automatically to prevent you from committing code that does not pass the linting and formatting checks.

We rely on a combination of `Black`, `Pylint`, `Mypy`, `Ruff` and `Isort` to enforce code quality.
We rely on a combination of `Pylint`, `Mypy` and `Ruff` to enforce code quality.

## Building Documentations

Expand All @@ -273,7 +269,7 @@ This project is based on many open-source libraries and frameworks, we would lik
- Documentation website is using [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) and [MkDocs](https://www.mkdocs.org/). For code documentation we are using [Mkdocstrings](https://mkdocstrings.github.io/). For releasing software versions we combine [Bumpver](https://github.com/mbarkhau/bumpver) and [Mike](https://github.com/jimporter/mike).
- Models can be exported in different ways (`torchscript` or `torch` file). We have also added [ONNX](https://onnx.ai/) support for some models.
- Testing framework is based on [Pytest](https://docs.pytest.org/en/) and related plug-ins.
- Code quality is ensured by [pre-commit](https://pre-commit.com/) hooks. We are using [Black](https://github.com/psf/black) for formatting, [Pylint](https://www.pylint.org/) for linting, [Mypy](https://mypy.readthedocs.io/en/stable/) for type checking, [Isort](https://pycqa.github.io/isort/) for sorting imports, and [Ruff](https://github.com/astral-sh/ruff) for checking futher code and documentation quality.
- Code quality is ensured by [pre-commit](https://pre-commit.com/) hooks. We are using [Ruff](https://github.com/astral-sh/ruff) for linting, enforcing code quality and formatting, [Pylint](https://www.pylint.org/) for in depth linting and [Mypy](https://mypy.readthedocs.io/en/stable/) for type checking.

## FAQ

Expand Down
8 changes: 4 additions & 4 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def init_file_imports(init_file: Path) -> bool:
Returns:
True if the file imports anything, False otherwise.
"""
with open(init_file, "r") as fd:
with open(init_file) as fd:
return any(line.startswith("__all__") for line in fd.readlines())


Expand Down Expand Up @@ -61,7 +61,7 @@ def add_submodules_as_list(parent_folder: Path) -> str:
full_doc_path = full_doc_path.with_name("index.md")
readme_file = path.parent / "README.md"
if readme_file.exists():
with open(readme_file, "r") as rfd:
with open(readme_file) as rfd:
MARKDOWN_CONTENTS += f"{rfd.read()}\n"
if not init_file_imports(path):
MARKDOWN_CONTENTS += add_submodules_as_list(path.parent)
Expand All @@ -76,14 +76,14 @@ def add_submodules_as_list(parent_folder: Path) -> str:

mkdocs_gen_files.set_edit_path(full_doc_path, path)

with open(Path("README.md"), "r") as read_fd:
with open(Path("README.md")) as read_fd:
readme = read_fd.read()
readme = readme.replace("# Quadra: Deep Learning Experiment Orchestration Library", "# Home")
readme = readme.replace("docs/", "")
with mkdocs_gen_files.open("getting_started.md", "w") as nav_file: # (2)
nav_file.write(readme)

with open("CHANGELOG.md", "r") as change_fd:
with open("CHANGELOG.md") as change_fd:
changelog = change_fd.read()
changelog = changelog.replace("All notable changes to this project will be documented in this file.", "")
with mkdocs_gen_files.open("reference/CHANGELOG.md", "w") as nav_file: # (2)
Expand Down
Loading

0 comments on commit 5d5dbe6

Please sign in to comment.