Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/sara-nl/hydra-2.0 into fix-…
Browse files Browse the repository at this point in the history
…default-list-interpolation
  • Loading branch information
robogast committed Apr 19, 2022
2 parents d21c9fc + a78d1f6 commit 7c3dd5a
Show file tree
Hide file tree
Showing 351 changed files with 8,438 additions and 4,619 deletions.
30 changes: 25 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ commands:
- run:
name: Preparing environment - system
command: |
choco install -y --no-progress miniconda3
choco install -y --no-progress miniconda3 --params '"/AddToPath:1"'
C:\tools\miniconda3\Scripts\conda.exe init powershell
choco install -y --no-progress openssl javaruntime
- run:
name: Preparing environment - Hydra
# Using virtualenv==20.0.33 higher versions of virtualenv are not compatible with conda on windows. Relevant issue: https://github.com/ContinuumIO/anaconda-issues/issues/12094
command: |
conda create -n hydra python=<< parameters.py_version >> virtualenv==20.0.33 -qy
conda create -n hydra python=<< parameters.py_version >> -qy
conda activate hydra
pip install nox dataclasses --progress-bar off
- save_cache:
Expand Down Expand Up @@ -224,6 +223,23 @@ jobs:
conda activate hydra
nox -s lint_plugins test_plugins -ts
exit $LASTEXITCODE
test_linux_omc_dev:
parameters:
py_version:
type: string
docker:
- image: cimg/base:stable-18.04
steps:
- linux:
py_version: << parameters.py_version >>
- run:
name: Testing Hydra
command: |
export PATH="$HOME/miniconda3/envs/hydra/bin:$PATH"
export NOX_PYTHON_VERSIONS=<< parameters.py_version >>
export USE_OMEGACONF_DEV_VERSION=1
pip install nox dataclasses --progress-bar off
nox -s test_core -ts
# Misc
coverage:
docker:
Expand All @@ -250,7 +266,11 @@ workflows:
- test_win:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8"]
py_version: ["3.6", "3.7", "3.8", "3.9"]
- test_linux_omc_dev:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9"]


plugin_tests:
Expand All @@ -269,7 +289,7 @@ workflows:
- test_plugin_win:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8",]
py_version: ["3.6", "3.7", "3.8", "3.9"]
test_plugin: [<< pipeline.parameters.test_plugins >>]


Expand Down
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exclude =
,tools/configen/example/gen
,tools/configen/tests/test_modules/expected
,temp
,build

# flake8-copyright does not support unicode, savoirfairelinux/flake8-copyright#15
,examples/plugins/example_configsource_plugin/hydra_plugins/example_configsource_plugin/example_configsource_plugin.py
Expand Down
1 change: 1 addition & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ skip=
,tools/configen/example/gen
,tools/configen/tests/test_modules/expected
,temp
,build
4 changes: 4 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[mypy]
python_version = 3.6
mypy_path=.stubs
exclude = (?x)(
build/
| ^hydra/grammar/gen/
)

[mypy-antlr4.*]
ignore_missing_imports = True
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
files: 'tools/.*'

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.1.0
hooks:
- id: black
language_version: python3.6
Expand All @@ -25,4 +25,4 @@ repos:
rev: v1.25.0
hooks:
- id: yamllint
args: [-c=.yamllint]
args: [-c=.yamllint, --strict]
27 changes: 11 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
<a href="https://lgtm.com/projects/g/facebookresearch/hydra/context:python">
<img src="https://img.shields.io/lgtm/grade/python/g/facebookresearch/hydra.svg?logo=lgtm&logoWidth=18" alt="Language grade: Python" />
</a>
<a href="https://hydra-framework.zulipchat.com">
<img src="https://img.shields.io/badge/zulip-join_chat-brightgreen.svg" alt="zulip" />
</a>
<p align="center">
<i>A framework for elegantly configuring complex applications.</i>
</p>
<p align="center">
<i>Check the <a href="https://hydra.cc/">website</a> for more information.</i>
<i>Check the <a href="https://hydra.cc/">website</a> for more information,<br>
or click the thumbnail below for a one-minute video introduction to Hydra.</i>
</p>
<p align="center">
<a href="http://www.youtube.com/watch?feature=player_embedded&v=Slc3gRQpnBI" target="_blank">
<img src="http://img.youtube.com/vi/Slc3gRQpnBI/hqdefault.jpg" alt="1 minute overview" width="240" height="180" border="10" />
</a>
</p>
</p>

Expand All @@ -43,26 +46,18 @@

#### Stable

**Hydra 1.0** is the stable version of Hydra.
**Hydra 1.1** is the stable version of Hydra.
- [Documentation](https://hydra.cc/docs/intro)
- Installation : `pip install hydra-core --upgrade`

#### Release candidate
**Hydra 1.1** is now a release candidate!

Please try it out and report any issues.

- [Documentation](https://hydra.cc/docs/next/intro)
- [Release notes](https://github.com/facebookresearch/hydra/releases/tag/v1.1.0.rc1)
- Installation : `pip install hydra-core --upgrade --pre`
- Release candidates are more likely to have bugs, please report any issues.

### License
Hydra is licensed under [MIT License](LICENSE).

## Community
Ask questions in the chat or StackOverflow (Use the tag #fb-hydra or #omegaconf):
* [Chat](https://hydra-framework.zulipchat.com)

Ask questions in Github Discussions or StackOverflow (Use the tag #fb-hydra or #omegaconf):
* [Github Discussions](https://github.com/facebookresearch/hydra/discussions)
* [StackOverflow](https://stackexchange.com/filters/391828/hydra-questions)
* [Twitter](https://twitter.com/Hydra_Framework)

Expand Down
12 changes: 6 additions & 6 deletions build_helpers/build_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import List, Optional

from setuptools import Command
from setuptools.command import build_py, develop, sdist # type: ignore
from setuptools.command import build_py, develop, sdist


def find_version(*file_paths: str) -> str:
Expand Down Expand Up @@ -143,24 +143,24 @@ def run_antlr(cmd: Command) -> None:
raise


class BuildPyCommand(build_py.build_py): # type: ignore
class BuildPyCommand(build_py.build_py):
def run(self) -> None:
if not self.dry_run:
self.run_command("clean")
run_antlr(self)
build_py.build_py.run(self)


class Develop(develop.develop): # type: ignore
def run(self) -> None:
class Develop(develop.develop):
def run(self) -> None: # type: ignore
if not self.dry_run:
run_antlr(self)
develop.develop.run(self)


class SDistCommand(sdist.sdist): # type: ignore
class SDistCommand(sdist.sdist):
def run(self) -> None:
if not self.dry_run:
if not self.dry_run: # type: ignore
self.run_command("clean")
run_antlr(self)
sdist.sdist.run(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
if __name__ == "__main__":
# initialize the Hydra subsystem.
# This is needed for apps that cannot have a standard @hydra.main() entry point
initialize(config_path="conf")
initialize(version_base=None, config_path="conf")
cfg = compose("config.yaml", overrides=["db=mysql", "db.user=${oc.env:USER}"])
print(OmegaConf.to_yaml(cfg, resolve=True))
2 changes: 1 addition & 1 deletion examples/advanced/config_search_path/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(OmegaConf.to_yaml(cfg))

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/defaults_list_interpolation/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(OmegaConf.to_yaml(cfg))

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/hydra_app_example/hydra_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def add(app_cfg: DictConfig, key1: str, key2: str) -> Any:
return ret


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def main(cfg: DictConfig) -> None:
add(cfg.app, "num1", "num2")

Expand Down
10 changes: 6 additions & 4 deletions examples/advanced/hydra_app_example/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 2. The module with your configs should be importable. it needs to have a __init__.py (can be empty).
# 3. The config path is relative to the file calling initialize (this file)
def test_with_initialize() -> None:
with initialize(config_path="../hydra_app/conf"):
with initialize(version_base=None, config_path="../hydra_app/conf"):
# config is relative to a module
cfg = compose(config_name="config", overrides=["app.user=test_user"])
assert cfg == {
Expand All @@ -26,7 +26,7 @@ def test_with_initialize() -> None:
# 3. The module should be absolute
# 4. This approach is not sensitive to the location of this file, the test can be relocated freely.
def test_with_initialize_config_module() -> None:
with initialize_config_module(config_module="hydra_app.conf"):
with initialize_config_module(version_base=None, config_module="hydra_app.conf"):
# config is relative to a module
cfg = compose(config_name="config", overrides=["app.user=test_user"])
assert cfg == {
Expand All @@ -38,7 +38,9 @@ def test_with_initialize_config_module() -> None:
# Usage in unittest style tests is similar.
class TestWithUnittest(unittest.TestCase):
def test_generated_config(self) -> None:
with initialize_config_module(config_module="hydra_app.conf"):
with initialize_config_module(
version_base=None, config_module="hydra_app.conf"
):
cfg = compose(config_name="config", overrides=["app.user=test_user"])
assert cfg == {
"app": {"user": "test_user", "num1": 10, "num2": 20},
Expand All @@ -57,6 +59,6 @@ def test_generated_config(self) -> None:
],
)
def test_user_logic(overrides: List[str], expected: int) -> None:
with initialize_config_module(config_module="hydra_app.conf"):
with initialize_config_module(version_base=None, config_module="hydra_app.conf"):
cfg = compose(config_name="config", overrides=overrides)
assert hydra_app.main.add(cfg.app, "num1", "num2") == expected
2 changes: 1 addition & 1 deletion examples/advanced/nested_defaults_list/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(OmegaConf.to_yaml(cfg))

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/package_overrides/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf", config_name="simple")
@hydra.main(version_base=None, config_path="conf", config_name="simple")
def my_app(cfg: DictConfig) -> None:
print(OmegaConf.to_yaml(cfg))

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/package_overrides/two_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf", config_name="two_packages")
@hydra.main(version_base=None, config_path="conf", config_name="two_packages")
def my_app(cfg: DictConfig) -> None:
print(OmegaConf.to_yaml(cfg))

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/ray_example/ray_compose_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def train(overrides: List[str], cfg: DictConfig) -> Tuple[List[str], float]:
return overrides, 0.9


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def main(cfg: DictConfig) -> None:
ray.init(**cfg.ray.init)

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/custom_help/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(OmegaConf.to_yaml(cfg))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from hydra.core.hydra_config import HydraConfig


@hydra.main(config_path=None)
@hydra.main(version_base=None)
def experiment(_cfg: DictConfig) -> None:
print(HydraConfig.get().job.name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from hydra.core.hydra_config import HydraConfig


@hydra.main(config_path=".", config_name="config")
@hydra.main(version_base=None, config_path=".", config_name="config")
def experiment(_cfg: DictConfig) -> None:
print(HydraConfig.get().job.name)

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/job_override_dirname/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import hydra


@hydra.main(config_path=".", config_name="config")
@hydra.main(version_base=None, config_path=".", config_name="config")
def my_app(_cfg: DictConfig) -> None:
print(f"Working dir {os.getcwd()}")

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/logging/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(_cfg: DictConfig) -> None:
log.info("Info level message")

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/workdir/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import hydra


@hydra.main(config_path="conf", config_name="config")
@hydra.main(version_base=None, config_path="conf", config_name="config")
def experiment(_cfg: DictConfig) -> None:
print(os.getcwd())

Expand Down
8 changes: 8 additions & 0 deletions examples/experimental/rerun/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
foo: bar

hydra:
callbacks:
save_job_info:
_target_: hydra.experimental.callbacks.PickleJobInfoCallback
job:
chdir: false
20 changes: 20 additions & 0 deletions examples/experimental/rerun/my_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved

import logging

from omegaconf import DictConfig

import hydra
from hydra.core.hydra_config import HydraConfig

log = logging.getLogger(__name__)


@hydra.main(version_base=None, config_path=".", config_name="config")
def my_app(cfg: DictConfig) -> None:
log.info(f"Output_dir={HydraConfig.get().runtime.output_dir}")
log.info(f"cfg.foo={cfg.foo}")


if __name__ == "__main__":
my_app()
2 changes: 1 addition & 1 deletion examples/instantiate/docs_example/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __repr__(self) -> str:
return f"Trainer(\n optimizer={self.optimizer},\n dataset={self.dataset}\n)"


@hydra.main(config_path=".", config_name="config")
@hydra.main(version_base=None, config_path=".", config_name="config")
def my_app(cfg: DictConfig) -> None:
optimizer = instantiate(cfg.trainer.optimizer)
print(optimizer)
Expand Down
Loading

0 comments on commit 7c3dd5a

Please sign in to comment.