Skip to content

Commit

Permalink
Refactor: decythonize configuration space (#321)
Browse files Browse the repository at this point in the history
* refactor: Initial Cleanup

* refactor: ...

* chore: Update and Fix tooling

* fix: Make tooling work for 3.7
  • Loading branch information
eddiebergman authored Jun 13, 2023
1 parent eb1ff7e commit df6dd5e
Show file tree
Hide file tree
Showing 54 changed files with 6,410 additions and 5,298 deletions.
11 changes: 0 additions & 11 deletions .flake8

This file was deleted.

14 changes: 14 additions & 0 deletions .github/.dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2

updates:
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "main"
schedule:
interval: "weekly"
assignees:
- "Neonkraft"
reviewers:
- "Neonkraft"
commit-message:
prefix: "chore: "
3 changes: 1 addition & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ jobs:

- name: Install dependencies
run: |
pip install build
pip install ".[docs]"
pip install ".[dev]"
- name: Make docs
run: |
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:

package-name: ConfigSpace
test-dir: test
extra-requires: "[test]" # "" for no extra_requires
extra-requires: "[dev]" # "" for no extra_requires

# Arguments used for pytest
pytest-args: >-
Expand All @@ -37,7 +37,7 @@ env:
#
code-cov-active: true # Copied in job setup
code-cov-os: ubuntu-latest # Copied in job setup
code-cov-python-version: "3.7"
code-cov-python-version: "3.8"
code-cov-args: >-
--cov=ConfigSpace
--cov-report=xml
Expand Down Expand Up @@ -71,7 +71,6 @@ jobs:
- name: Install ${{ env.package-name }}
run: |
python -m pip install --upgrade pip
python -m pip install wheel
python -m pip install -e ".${{ env.extra-requires }}"
- name: Store git status
Expand Down Expand Up @@ -107,7 +106,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]

steps:
Expand Down Expand Up @@ -144,7 +143,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]

steps:
Expand Down
1 change: 0 additions & 1 deletion .landscape.yaml

This file was deleted.

77 changes: 60 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
default_language_version:
python: python3
files: |
(?x)^(
ConfigSpace|
test
)/.*\.py$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
files: ".*"
- id: check-case-conflict
files: ".*"
- id: check-merge-conflict
files: ".*"
- id: check-yaml
files: ".*"
- id: end-of-file-fixer
files: ".*"
types: ["yaml"]
- id: check-toml
files: ".*"
types: ["toml"]
- id: debug-statements
files: '^src/.*\.py$'
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.22.0
hooks:
- id: check-github-workflows
files: '^github/workflows/.*\.ya?ml$'
types: ["yaml"]
- id: check-dependabot
files: '^\.github/dependabot\.ya?ml$'
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
rev: v1.2.0
hooks:
- id: mypy
args: [--show-error-codes, --ignore-missing-imports, --follow-imports, skip]
name: mypy ConfigSpace
files: ConfigSpace
files: '^ConfigSpace/.*\.py$'
args:
- "--no-warn-return-any" # Disable this because it doesn't know about 3rd party imports
- "--ignore-missing-imports"
- "--show-traceback"
- id: mypy
files: '^test/.*\.py$'
args:
- "--no-warn-return-any" # Disable this because it doesn't know about 3rd party imports
- "--ignore-missing-imports"
- "--show-traceback"
- "--disable-error-code"
- "no-untyped-def"

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: flake8
name: flake8 ConfigSpace
files: ConfigSpace

- id: flake8
name: flake8 test
files: test

- id: black
args: ["--config=pyproject.toml"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.263
hooks:
- id: ruff
args: ["--fix", "ConfigSpace", "test"]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.14.0
rev: v0.15.0
hooks:
- id: cython-lint
- id: cython-lint
args: [--ignore=E501]
- id: double-quote-cython-strings
- id: double-quote-cython-strings
3 changes: 3 additions & 0 deletions ConfigSpace/__authors__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

__authors__ = [
"Matthias Feurer",
"Katharina Eggensperger",
Expand All @@ -9,4 +11,5 @@
"Marius Lindauer",
"Jorn Tuyls",
"Eddie Bergman",
"Arjun Krishnakumar",
]
93 changes: 67 additions & 26 deletions ConfigSpace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,63 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ConfigSpace.__version__ import __version__
from ConfigSpace.__authors__ import __authors__

from ConfigSpace.api import (Beta, Categorical, Distribution, Float, Integer,
Normal, Uniform)
from ConfigSpace.conditions import (AndConjunction, EqualsCondition,
GreaterThanCondition, InCondition,
LessThanCondition, NotEqualsCondition,
OrConjunction)
from ConfigSpace.configuration_space import Configuration, ConfigurationSpace
from ConfigSpace.forbidden import (ForbiddenAndConjunction,
ForbiddenEqualsClause,
ForbiddenEqualsRelation,
ForbiddenGreaterThanRelation,
ForbiddenInClause,
ForbiddenLessThanRelation)
from ConfigSpace.hyperparameters import (BetaFloatHyperparameter,
BetaIntegerHyperparameter,
CategoricalHyperparameter, Constant,
NormalFloatHyperparameter,
NormalIntegerHyperparameter,
OrdinalHyperparameter,
UniformFloatHyperparameter,
UniformIntegerHyperparameter,
UnParametrizedHyperparameter)
import ConfigSpace.api.distributions as distributions
import ConfigSpace.api.types as types
from ConfigSpace.__version__ import __version__
from ConfigSpace.api import (
Beta,
Categorical,
Distribution,
Float,
Integer,
Normal,
Uniform,
distributions,
types,
)
from ConfigSpace.conditions import (
AndConjunction,
EqualsCondition,
GreaterThanCondition,
InCondition,
LessThanCondition,
NotEqualsCondition,
OrConjunction,
)
from ConfigSpace.configuration import Configuration
from ConfigSpace.configuration_space import ConfigurationSpace
from ConfigSpace.exceptions import (
ActiveHyperparameterNotSetError,
AmbiguousConditionError,
ChildNotFoundError,
CyclicDependancyError,
ForbiddenValueError,
HyperparameterAlreadyExistsError,
HyperparameterIndexError,
HyperparameterNotFoundError,
IllegalValueError,
InactiveHyperparameterSetError,
ParentNotFoundError,
)
from ConfigSpace.forbidden import (
ForbiddenAndConjunction,
ForbiddenEqualsClause,
ForbiddenEqualsRelation,
ForbiddenGreaterThanRelation,
ForbiddenInClause,
ForbiddenLessThanRelation,
)
from ConfigSpace.hyperparameters import (
BetaFloatHyperparameter,
BetaIntegerHyperparameter,
CategoricalHyperparameter,
Constant,
NormalFloatHyperparameter,
NormalIntegerHyperparameter,
OrdinalHyperparameter,
UniformFloatHyperparameter,
UniformIntegerHyperparameter,
UnParametrizedHyperparameter,
)

__all__ = [
"__authors__",
Expand Down Expand Up @@ -91,4 +121,15 @@
"Uniform",
"distributions",
"types",
"ForbiddenValueError",
"IllegalValueError",
"ActiveHyperparameterNotSetError",
"InactiveHyperparameterSetError",
"HyperparameterNotFoundError",
"ChildNotFoundError",
"ParentNotFoundError",
"HyperparameterIndexError",
"AmbiguousConditionError",
"HyperparameterAlreadyExistsError",
"CyclicDependancyError",
]
2 changes: 2 additions & 0 deletions ConfigSpace/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
from __future__ import annotations

__version__ = "0.6.1"
3 changes: 1 addition & 2 deletions ConfigSpace/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ConfigSpace.api.distributions as distributions
import ConfigSpace.api.types as types
from ConfigSpace.api import distributions, types
from ConfigSpace.api.distributions import Beta, Distribution, Normal, Uniform
from ConfigSpace.api.types import Categorical, Float, Integer

Expand Down
10 changes: 4 additions & 6 deletions ConfigSpace/api/distributions.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from __future__ import annotations

from dataclasses import dataclass


@dataclass
class Distribution:
"""Base distribution type"""

pass
"""Base distribution type."""


@dataclass
class Uniform(Distribution):
"""A uniform distribution"""

pass
"""A uniform distribution."""


@dataclass
Expand Down
29 changes: 15 additions & 14 deletions ConfigSpace/api/types/categorical.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

from typing import Sequence, Union, overload
from typing import (
Sequence,
Union,
overload,
)
from typing_extensions import Literal, TypeAlias

from typing_extensions import (Literal, # Move to `typing` when 3.8 minimum
TypeAlias)

from ConfigSpace.hyperparameters import (CategoricalHyperparameter,
OrdinalHyperparameter)
from ConfigSpace.hyperparameters import CategoricalHyperparameter, OrdinalHyperparameter

# We only accept these types in `items`
T: TypeAlias = Union[str, int, float]
Expand Down Expand Up @@ -130,11 +131,11 @@ def Categorical(
default_value=default,
meta=meta,
)
else:
return CategoricalHyperparameter(
name=name,
choices=items,
default_value=default,
weights=weights,
meta=meta,
)

return CategoricalHyperparameter(
name=name,
choices=items,
default_value=default,
weights=weights,
meta=meta,
)
Loading

0 comments on commit df6dd5e

Please sign in to comment.