Skip to content

Commit

Permalink
🛠 Fix tox configuration (#446)
Browse files Browse the repository at this point in the history
* Update pre-commit configurations

* Combine code quality checks into pre-commit.

* Address pylint issues

* Update dev requirements

* Modify github actions

* Fix pylint version in pre-commit configurations

* Remove requirements/dev.txt from the repo.

* Removed dev requirements from setup.py

Co-authored-by: someone <someone@example.com>
  • Loading branch information
samet-akcay and someone committed Jul 27, 2022
1 parent d3aba6e commit 150ff7a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Tox
run: pip install tox
- name: Code quality checks
run: tox -e black,isort,flake8,pylint,mypy,pydocstyle,notebooks
run: tox -e pre-commit
- name: Coverage
run: |
export ANOMALIB_DATASET_PATH=/media/data1/datasets/
Expand Down
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.3.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
Expand All @@ -12,35 +12,36 @@ repos:

# python code formatting
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.6.0
hooks:
- id: black
args: [--line-length, "120"]

# python import sorting
- repo: https://github.com/PyCQA/isort
rev: 5.8.0
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black"]

# yaml formatting
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.3.0
rev: v2.7.1
hooks:
- id: prettier
types: [yaml]

# python code analysis
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
rev: 4.0.1
hooks:
- id: flake8
args: [--config=tox.ini]
exclude: "tests|anomalib/models/components/freia"

# python linting
- repo: local
- repo: https://github.com/PyCQA/pylint
rev: v2.14.5
hooks:
- id: pylint
name: pylint
Expand All @@ -51,7 +52,7 @@ repos:

# python static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.910"
rev: "v0.971"
hooks:
- id: mypy
args: [--config-file=tox.ini]
Expand All @@ -71,7 +72,7 @@ repos:

# notebooks.
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.3.1
rev: 1.4.0
hooks:
- id: nbqa-black
- id: nbqa-isort
Expand Down
2 changes: 1 addition & 1 deletion anomalib/models/components/base/dynamic_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_tensor_attribute(self, attribute_name: str) -> Tensor:
Returns:
Tensor: Tensor attribute
"""
attribute = self.__getattr__(attribute_name)
attribute = getattr(self, attribute_name)
if isinstance(attribute, Tensor):
return attribute

Expand Down
15 changes: 0 additions & 15 deletions requirements/dev.txt

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ def get_required_packages(requirement_files: List[str]) -> List[str]:
LONG_DESCRIPTION = (Path(__file__).parent / "README.md").read_text(encoding="utf8")
INSTALL_REQUIRES = get_required_packages(requirement_files=["base"])
EXTRAS_REQUIRE = {
"dev": get_required_packages(requirement_files=["dev", "docs"]),
"openvino": get_required_packages(requirement_files=["openvino"]),
"full": get_required_packages(requirement_files=["dev", "docs", "openvino"]),
"full": get_required_packages(requirement_files=["docs", "openvino"]),
}


Expand Down
4 changes: 4 additions & 0 deletions tools/hpo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""HPO Tools."""

# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
3 changes: 2 additions & 1 deletion tools/hpo/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
from omegaconf import DictConfig, ListConfig, OmegaConf
from pytorch_lightning import seed_everything
from pytorch_lightning.loggers import WandbLogger
from utils import flatten_hpo_params

import wandb
from anomalib.config import get_configurable_parameters, update_input_size_config
from anomalib.data import get_datamodule
from anomalib.models import get_model
from anomalib.utils.sweep import flatten_sweep_params, set_in_nested_config

from .utils import flatten_hpo_params


class WandbSweep:
"""wandb sweep.
Expand Down
68 changes: 4 additions & 64 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,14 @@
isolated_build = True
skip_missing_interpreters = true
envlist =
black
isort
flake8
pylint
mypy
pydocstyle
pre-commit
pre_merge
nightly

[testenv:black]
[testenv:pre-commit]
basepython = python3
deps = black==22.3.0
commands = black --check --diff anomalib -l 120

[testenv:isort]
basepython = python3
deps = isort==5.10.1
commands = isort --check-only --df anomalib --profile=black

[testenv:flake8]
skip_install = true
basepython = python3
deps =
flake8
mccabe
commands = flake8 anomalib --exclude=anomalib/models/components/freia


[testenv:pylint]
skip_install = true
basepython = python3
deps =
pylint<2.14
-r{toxinidir}/requirements/base.txt
commands = pylint anomalib --rcfile=tox.ini --ignore=anomalib/models/components/freia/

[testenv:mypy]
basepython = python3
passenv = ftp_proxy
HTTP_PROXY
HTTPS_PROXY
deps =
mypy
-r{toxinidir}/requirements/base.txt
commands =
python -m mypy --install-types --non-interactive anomalib --config-file tox.ini
python -m mypy --install-types --non-interactive tools/train.py --config-file tox.ini
python -m mypy --install-types --non-interactive tools/test.py --config-file tox.ini


[testenv:pydocstyle]
basepython = python3
deps =
pydocstyle
commands = pydocstyle anomalib --config=tox.ini

[testenv:notebooks]
basepython = python3
deps =
-r{toxinidir}/requirements/dev.txt
commands =
nbqa black notebooks --nbqa-diff
nbqa isort notebooks --nbqa-diff
nbqa flake8 notebooks
nbqa pylint notebooks --disable=C0103,C0114,C0116,R0801,W0106
nbqa mdformat notebooks --nbqa-md --nbqa-diff

deps = pre-commit
commands = pre-commit run --all-files

[testenv:pre_merge]
basepython = python3
Expand Down Expand Up @@ -121,7 +62,6 @@ disable = duplicate-code,
arguments-differ,
fixme,
import-error,
no-self-use,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
Expand Down

0 comments on commit 150ff7a

Please sign in to comment.