Skip to content

Commit a835f52

Browse files
authored
Merge pull request #94 from automl/bug/pre-commit-hooks
Bug/pre commit hooks
2 parents bff04ce + 4eacae3 commit a835f52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+6128
-1087
lines changed

.flake8

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ extend-exclude =
66
.venv
77
build
88
extend-ignore =
9-
E203 # No whitespace before ':' in [x : y]
10-
E731 # No lambdas — too strict
9+
# No whitespace before ':' in [x : y]
10+
E203
11+
# No lambdas — too strict
12+
E731

.pre-commit-config.yaml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
files: tests
1515

1616
- repo: https://github.com/ambv/black
17-
rev: 23.1.0
17+
rev: 23.3.0
1818
hooks:
1919
- id: black
2020
name: black formatter deepcave
@@ -33,14 +33,38 @@ repos:
3333
hooks:
3434
- id: pydocstyle
3535
files: deepcave
36-
additional_dependencies: ["toml"] # Needed to parse pyproject.toml
36+
additional_dependencies: ["tomli"] # Needed to parse pyproject.toml
3737

3838
- repo: https://github.com/pre-commit/mirrors-mypy
39-
rev: v0.930
39+
rev: v1.5.1
4040
hooks:
4141
- id: mypy
4242
name: mypy deepcave
4343
files: deepcave
44+
args: [--install-types, --non-interactive]
45+
additional_dependencies: [
46+
'wheel>=0.41.2',
47+
'setuptools==68.2.2',
48+
'absl-py>=1.0.0',
49+
'jsonlines>=3.0.0',
50+
'pandas>=1.3.4',
51+
'numpy>=1.22.2',
52+
'matplotlib>=3.5.1',
53+
'pyyaml>=6.0.1',
54+
'kaleido>=0.2.1',
55+
'gplearn>=0.4.2',
56+
'sympy>=1.12',
57+
'ConfigSpace==0.6.1',
58+
'pyrfr>=0.9.0',
59+
'hpbandster==0.7.4',
60+
'dash==2.0.0',
61+
'dash-extensions==0.0.71',
62+
'dash-bootstrap-components==1.0.3',
63+
'redis>=4.1.4',
64+
'rq>=1.10.1',
65+
'werkzeug==2.0.3',
66+
'pyPDPPartitioner>=0.1.8'
67+
] # Needed for mypy, so that it knows the types to check
4468

4569
- repo: https://github.com/PyCQA/flake8
4670
rev: 6.0.0

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
- Fix errors due to changing inputs before runselection (#64).
2121
- For fANOVA, remove constant hyperparameters from configspace (#9).
2222

23+
## Version-Updates
24+
- Black version from 23.1.0 to 23.3.0
25+
- Mypy from 0.930 to 1.5.1
26+
27+
## Mypy
28+
- Updated args so there are no missing imports
29+
- Updated additional dependencies, so mypy can check all types
30+
- Note: If the installs in requirements change, it has to be adapted in additional dependencies
31+
- Added many type annotations
32+
- In some cases internal refactoring for variables, due to typing
33+
34+
## Pydocstyle and Linter
35+
- Major overhaul of docstrings in various files
36+
- Removed unused imports and variables
37+
38+
## Additional Changes
39+
- Added a "make install examples" in Makefile
40+
2341
# Version 1.1.3
2442

2543
## Bug-Fixes

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ install:
4848
install-dev:
4949
$(PIP) install -e ".[dev]"
5050
pre-commit install
51-
51+
52+
install-examples:
53+
$(PIP) install -e ".[examples]"
54+
5255
check-black:
5356
$(BLACK) ${SOURCE_DIR} --check || :
5457
$(BLACK) ${EXAMPLES_DIR} --check || :
@@ -62,7 +65,7 @@ check-pydocstyle:
6265
$(PYDOCSTYLE) ${SOURCE_DIR} || :
6366

6467
check-mypy:
65-
$(MYPY) ${SOURCE_DIR} || :
68+
$(MYPY) --check-untyped-defs --install-types --non-interactive --ignore-missing-imports ${SOURCE_DIR} || :
6669

6770
check-flake8:
6871
$(FLAKE8) ${SOURCE_DIR} || :

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ conda install -c anaconda swig
4747
make install-dev
4848
```
4949

50+
If you want to use the given examples, run this after installing:
51+
```bash
52+
make install-examples
53+
```
54+
5055
Please visit the [documentation](https://automl.github.io/DeepCAVE/main/installation.html) to get
5156
further help (e.g. if you can not install redis server or you are on a mac).
5257

deepcave/__init__.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# noqa: D400
2+
"""
3+
# DeepCAVE
4+
5+
This module is used to initialize and set up the configuration for the DeepCAVE framework.
6+
7+
The Dash application gets created.
8+
"""
9+
110
from typing import Any, Callable, TypeVar, cast
211

312
import datetime
@@ -25,7 +34,20 @@
2534
ROOT_DIR = Path(__file__).parent
2635

2736

28-
def get_app(title: str):
37+
def get_app(title: str) -> Any:
38+
"""
39+
Get the Dash Proxy.
40+
41+
Parameters
42+
----------
43+
title : str
44+
The title of the application.
45+
46+
Returns
47+
-------
48+
DashProxy
49+
The dash proxy.
50+
"""
2951
import dash_bootstrap_components as dbc
3052
from dash_extensions.enrich import (
3153
DashProxy,
@@ -61,8 +83,8 @@ def get_app(title: str):
6183
if any(file in _exec_file for file in _exec_files):
6284
from deepcave.custom_queue import Queue
6385
from deepcave.runs.handler import RunHandler
64-
from deepcave.runs.objective import Objective # noqa
65-
from deepcave.runs.recorder import Recorder # noqa
86+
from deepcave.runs.objective import Objective
87+
from deepcave.runs.recorder import Recorder
6688
from deepcave.utils.cache import Cache
6789
from deepcave.utils.configs import parse_config
6890
from deepcave.utils.notification import Notification
@@ -129,8 +151,37 @@ def get_app(title: str):
129151

130152

131153
def interactive(func: F) -> F:
154+
"""
155+
Define the interactive decorator.
156+
157+
Parameters
158+
----------
159+
func : F
160+
The function to be decorated.
161+
162+
Returns
163+
-------
164+
F
165+
The decorated function.
166+
"""
167+
132168
@wraps(func)
133169
def inner(*args: Any, **kwargs: Any) -> Any:
170+
"""
171+
Inner function of the decorator.
172+
173+
Parameters
174+
----------
175+
*args : Any
176+
Arguments to be passed to the wrap function.
177+
**kwargs : Any
178+
Keyword arguments to be passed to the wrap function.
179+
180+
Returns
181+
-------
182+
Any
183+
The result of the function.
184+
"""
134185
if _api_mode:
135186
return
136187

deepcave/cli.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# noqa: D400
2+
"""
3+
# CLI
4+
5+
This module defines command-line options using flags.
6+
7+
This includes the entry point for the programs execution.
8+
"""
9+
10+
from typing import Any
11+
112
import multiprocessing
213
import subprocess
314
from pathlib import Path
@@ -21,7 +32,8 @@
2132
)
2233

2334

24-
def execute(_) -> None:
35+
def execute(_: Any) -> None:
36+
"""Entry point for the programs execution."""
2537
if (config_key := FLAGS.get_config_value) is not None:
2638
config = FLAGS.config
2739
if config is not None:
@@ -47,6 +59,7 @@ def execute(_) -> None:
4759

4860

4961
def main() -> None:
62+
"""Call the execute function."""
5063
try:
5164
app.run(execute)
5265
except KeyboardInterrupt:

deepcave/config.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
1+
# noqa: D400
2+
"""
3+
# Config
4+
5+
This module defines the config object and its constants.
6+
Also defines multiple constants for directories, the server name, available plugins and converters.
7+
8+
## Classes
9+
- Config: Describe the config object.
10+
"""
11+
112
from typing import Any, Dict, List, Type
213

314
from pathlib import Path
415

16+
from deepcave.runs.run import Run
17+
518

619
class Config:
20+
"""
21+
Describe the config object.
22+
23+
Also define the constants of the config object.
24+
Includes multiple constants for directories, the server name, available plugins and converters.
25+
26+
Constants
27+
---------
28+
TITLE : str
29+
DEBUG: bool
30+
REFRESH_RATE: int
31+
SAVE_IMAGES: bool
32+
FIGURE_MARGIN: Dict
33+
FIGURE_HEIGHT: str
34+
REDIS_PORT: int
35+
REDIS_ADDRESS: str
36+
DASH_PORT: int
37+
DASH_ADDRESS: str
38+
META_DEFAULT: Dict
39+
40+
Properties
41+
----------
42+
DASH_ADRESS : str
43+
The address of the server name.
44+
DASH_PORT : int
45+
The port of the server name.
46+
"""
47+
748
# General config
849
TITLE: str = "DeepCAVE"
950
DEBUG: bool = False
@@ -34,18 +75,22 @@ class Config:
3475

3576
@property
3677
def DEFAULT_WORKING_DIRECTORY(self) -> Path:
78+
"""Specifies the default working directory."""
3779
return Path.cwd() / "logs"
3880

3981
@property
4082
def CACHE_DIR(self) -> Path:
83+
"""Specifies the default cache directory."""
4184
return Path(__file__).parent / "cache"
4285

4386
@property
4487
def SERVER_NAME(self) -> str:
88+
"""Specifies the server name, consisting of address and port."""
4589
return f"http://{self.DASH_ADDRESS}:{self.DASH_PORT}"
4690

4791
@property
48-
def PLUGINS(self) -> Dict[str, List["Plugin"]]:
92+
def PLUGINS(self) -> Dict[str, List[Any]]:
93+
"""A list of available plugins per category."""
4994
from deepcave.plugins.budget.budget_correlation import BudgetCorrelation
5095
from deepcave.plugins.hyperparameter.importances import Importances
5196
from deepcave.plugins.hyperparameter.pdp import PartialDependencies
@@ -60,6 +105,7 @@ def PLUGINS(self) -> Dict[str, List["Plugin"]]:
60105
from deepcave.plugins.summary.footprint import FootPrint
61106
from deepcave.plugins.summary.overview import Overview
62107

108+
plugins: Dict[str, List[Any]] = {}
63109
plugins = {
64110
"Summary": [
65111
Overview(),
@@ -85,6 +131,7 @@ def PLUGINS(self) -> Dict[str, List["Plugin"]]:
85131

86132
@property
87133
def CONVERTERS(self) -> List[Type["Run"]]:
134+
"""Get a list of available run converters."""
88135
from deepcave.runs.converters.bohb import BOHBRun
89136
from deepcave.runs.converters.deepcave import DeepCAVERun
90137
from deepcave.runs.converters.smac3v1 import SMAC3v1Run

deepcave/constants.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# noqa: D400
2+
"""
3+
# Constants
4+
5+
This module defines the constants for the DeepCAVE framework.
6+
7+
## Constants
8+
NAN_VALUE: float
9+
NAN_LABEL: str
10+
VALUE_RANGE: List
11+
CONSTANT_VALUE: float
12+
BORDER_CONFIG_ID: int
13+
RANDOM_CONFIG_ID: innt
14+
COMBINED_COST_NAME: str
15+
COMBINED_BUDGET: int
16+
"""
17+
118
NAN_VALUE = -0.2
219
NAN_LABEL = "NaN"
320
VALUE_RANGE = [NAN_VALUE, 1]

0 commit comments

Comments
 (0)