Skip to content

Commit

Permalink
Maintenance (#527)
Browse files Browse the repository at this point in the history
* Migrate pre-commit to `ruff`.

* remove `pylint`

* Drop `nox`.
Update CONTRIBUTING.

Closes #433

* fix InvalidReportModeError
  • Loading branch information
daavoo authored Apr 13, 2023
1 parent 4f6c994 commit 3e0ac41
Show file tree
Hide file tree
Showing 41 changed files with 209 additions and 360 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ jobs:
- name: Full install
run: pip install -e '.[dev]'

- name: pylint
run: |
python -m pylint src tests
- name: mypy
run: |
python -m mypy --install-types --non-interactive
Expand Down
36 changes: 11 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -23,31 +19,21 @@ repos:
args: ['--fix=lf']
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: pyupgrade
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.1.20
- flake8-comprehensions==3.10.1
- flake8-debugger==4.1.2
- flake8-string-format==0.3.0
- repo: https://github.com/pycqa/bandit
rev: 1.7.4
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.261'
hooks:
- id: bandit
args: [-c, pyproject.toml]
additional_dependencies: ["toml"]
- id: ruff
41 changes: 19 additions & 22 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,39 @@ Request features on the `Issue Tracker`_.
How to set up your development environment
------------------------------------------

You need Python 3.8+ and the following tools:
You need Python 3.8+.

- Nox_

Install the package with development requirements:
- Clone the repository:

.. code:: console
$ pip install nox
$ git clone https://github.com/iterative/dvclive
$ cd dvclive
.. _Nox: https://nox.thea.codes/
- Set up a virtual environment:

.. code:: console
How to test the project
-----------------------
$ python -m venv .venv
$ source .venv/bin/activate
Run the full test suite:
Install in editable mode:

.. code:: console
$ nox
$ pip install -e .
List the available Nox sessions:
.. code:: console
$ nox --list-sessions
How to test the project
-----------------------

You can also run a specific Nox session.
For example, invoke the unit test suite like this:
Run the full test suite:

.. code:: console
$ nox --session=tests
$ pytest -v tests
Unit tests are located in the ``tests`` directory,
Tests are located in the ``tests`` directory,
and are written using the pytest_ testing framework.

.. _pytest: https://pytest.readthedocs.io/
Expand All @@ -89,17 +86,17 @@ Open a `pull request`_ to submit changes to this project.

Your pull request needs to meet the following guidelines for acceptance:

- The Nox test suite must pass without errors and warnings.
- Include unit tests. This project maintains 100% code coverage.
- The test suite must pass without errors and warnings.
- Include unit tests.
- If your changes add functionality, update the documentation accordingly.

Feel free to submit early, though—we can always iterate on this.

To run linting and code formatting checks, you can invoke a `lint` session in nox:
To run linting and code formatting checks, you can use `pre-commit`:

.. code:: console
$ nox -s lint
$ pre-commit run --all-files
It is recommended to open an issue before starting work on anything.
This will allow a chance to talk it over with the owners and validate your approach.
Expand Down
62 changes: 0 additions & 62 deletions noxfile.py

This file was deleted.

32 changes: 9 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,15 @@ ignore_missing_imports = true
files = ["src", "tests"]
enable_recursive_aliases = true

[tool.pylint.format]
max-line-length = 88

[tool.pylint.message_control]
enable = ["c-extension-no-member", "no-else-return"]
disable = [
"format", "refactoring", "spelling", "design",
"invalid-name", "duplicate-code", "fixme",
"unused-wildcard-import", "cyclic-import", "wrong-import-order",
"wrong-import-position", "ungrouped-imports", "multiple-imports",
"logging-format-interpolation", "logging-fstring-interpolation",
"missing-function-docstring", "missing-module-docstring",
"missing-class-docstring", "raise-missing-from", "import-outside-toplevel",
]

[tool.pylint.variables]
dummy-variables-rgx = "_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_"
ignored-argument-names = "_.*|^ignored_|^unused_|args|kwargs"
generated-members = ["torch.*"]

[tool.codespell]
ignore-words-list = "fpr"

[tool.bandit]
exclude_dirs = ["tests"]
skips = ["B101"]
[tool.ruff]
ignore = ["N818", "UP006", "UP007", "UP035", "UP038", "B905", "PGH003"]
select = ["F", "E", "W", "C90", "N", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "EXE", "ISC", "INP", "PIE", "T20", "PT", "Q", "RSE", "RET", "SLF", "SIM", "TID", "TCH", "INT", "ARG", "PGH", "PL", "TRY", "NPY", "RUF"]

[tool.ruff.per-file-ignores]
"tests/*" = ["S101", "INP001", "SLF001", "ARG001", "ARG002", "ARG005", "PLR2004", "NPY002"]

[tool.ruff.pylint]
max-args = 10
21 changes: 1 addition & 20 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ tests =
pytest-sugar==0.9.5
pytest-cov==3.0.0
pytest-mock==3.8.2
pylint==2.15.0
pylint-plugin-utils>=0.6
mypy>=1.1.1
%(image)s
%(plots)s
%(markdown)s
ipython
dev =
%(tests)s
%(all)s
mypy>=1.1.1
mmcv =
mmcv
tf =
Expand Down Expand Up @@ -97,20 +95,3 @@ exclude =
tests
tests.*
where=src

[flake8]
ignore=
# Whitespace before ':'
E203
# Too many leading '#' for block comment
E266
# Line break occurred before a binary operator
W503
# unindexed parameters in the str.format, see:
# https://pypi.org/project/flake8-string-format/
P1
max_line_length = 88
max-complexity = 15
select = B,C,E,F,W,T4,B902,T,P
show_source = true
count = true
8 changes: 5 additions & 3 deletions src/dvclive/catalyst.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: ARG002
from typing import Optional

from catalyst import utils
Expand All @@ -15,8 +16,9 @@ def __init__(self, model_file=None, live: Optional[Live] = None, **kwargs):
def on_epoch_end(self, runner) -> None:
for loader_key, per_loader_metrics in runner.epoch_metrics.items():
for key, value in per_loader_metrics.items():
key = key.replace("/", "_")
self.live.log_metric(f"{loader_key}/{key}", float(value))
self.live.log_metric(
f"{loader_key}/{key.replace('/', '_')}", float(value)
)

if self.model_file:
checkpoint = utils.pack_checkpoint(
Expand All @@ -28,5 +30,5 @@ def on_epoch_end(self, runner) -> None:
utils.save_checkpoint(checkpoint, self.model_file)
self.live.next_step()

def on_experiment_end(self, runner): # pylint: disable=unused-argument
def on_experiment_end(self, runner):
self.live.end()
Loading

0 comments on commit 3e0ac41

Please sign in to comment.