Skip to content

Commit

Permalink
sorted imports
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Dec 28, 2019
1 parent 2ef5397 commit 1e3a057
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 113 deletions.
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ repos:
language: system
entry: flake8
types: [python]
- repo: https://github.com/pre-commit/mirrors-isort
rev: '' # Use the revision sha / tag you want to point at
hooks:
- id: isort
1 change: 1 addition & 0 deletions news/105.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OmegaConf now passes strict mypy tests
1 change: 1 addition & 0 deletions news/107.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add isort to ensure imports are kept sorted
5 changes: 4 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# type: ignore
import nox
import os

import nox

DEFAULT_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"]

PYTHON_VERSIONS = os.environ.get(
Expand Down Expand Up @@ -55,6 +56,8 @@ def lint(session):
session.run("mypy", "tests")
session.run("mypy", "omegaconf", "--strict")

session.run("isort", "--check", "--verbose")


@nox.session(python=PYTHON_VERSIONS)
def test_jupyter_notebook(session):
Expand Down
10 changes: 5 additions & 5 deletions omegaconf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from .base import Node
from .basecontainer import BaseContainer
from .dictconfig import DictConfig
from .errors import (
MissingMandatoryValue,
ValidationError,
ReadonlyConfigError,
UnsupportedKeyType,
UnsupportedValueType,
ValidationError,
)
from .listconfig import ListConfig
from .base import Node
from .nodes import (
ValueNode,
AnyNode,
BooleanNode,
EnumNode,
FloatNode,
IntegerNode,
StringNode,
AnyNode,
ValueNode,
)
from .omegaconf import OmegaConf, flag_override, read_write, open_dict, II, SI, MISSING
from .omegaconf import II, MISSING, SI, OmegaConf, flag_override, open_dict, read_write
from .version import __version__

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion omegaconf/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from enum import Enum
from typing import Any, Tuple, Dict, List, Union, Optional, Match
from typing import Any, Dict, List, Match, Optional, Tuple, Union

import yaml

Expand Down
8 changes: 4 additions & 4 deletions omegaconf/basecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
from abc import abstractmethod
from collections import defaultdict
from enum import Enum
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union

import yaml
from typing import Any, Optional, Dict, List, Iterator, Union, Tuple

from ._utils import (
get_value_kind,
ValueKind,
get_yaml_loader,
_re_parent,
get_value_kind,
get_yaml_loader,
is_structured_config,
)
from .base import Container, Node
from .errors import (
MissingMandatoryValue,
ReadonlyConfigError,
UnsupportedInterpolationType,
)
from .base import Node, Container


class BaseContainer(Container):
Expand Down
12 changes: 6 additions & 6 deletions omegaconf/dictconfig.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import copy
from enum import Enum
from typing import Any, Optional, Iterator, Union, Tuple, Dict, List, Iterable
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union

from ._utils import (
_re_parent,
get_structured_config_data,
is_structured_config_frozen,
is_structured_config,
_re_parent,
is_structured_config_frozen,
)
from .base import Node, Container
from .base import Container, Node
from .basecontainer import BaseContainer
from .errors import (
ReadonlyConfigError,
MissingMandatoryValue,
ReadonlyConfigError,
UnsupportedInterpolationType,
UnsupportedValueType,
UnsupportedKeyType,
UnsupportedValueType,
ValidationError,
)
from .nodes import ValueNode
Expand Down
10 changes: 5 additions & 5 deletions omegaconf/listconfig.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import copy
import itertools
from typing import Any, Optional, Iterator, List, Tuple, Union, Dict, Iterable, Callable
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union

from ._utils import isint, _re_parent
from .base import Node, Container
from ._utils import _re_parent, isint
from .base import Container, Node
from .basecontainer import BaseContainer
from .errors import ReadonlyConfigError, UnsupportedValueType, UnsupportedKeyType
from .nodes import ValueNode, AnyNode
from .errors import ReadonlyConfigError, UnsupportedKeyType, UnsupportedValueType
from .nodes import AnyNode, ValueNode


class ListConfig(BaseContainer):
Expand Down
7 changes: 3 additions & 4 deletions omegaconf/nodes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import copy
import math
from abc import abstractmethod
from enum import Enum
from typing import Any, Dict, Optional, Type

import math
from typing import Optional, Dict, Type, Any

from .errors import ValidationError, UnsupportedValueType
from .base import Node
from .basecontainer import BaseContainer
from .errors import UnsupportedValueType, ValidationError


class ValueNode(Node):
Expand Down
20 changes: 10 additions & 10 deletions omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
import sys
from contextlib import contextmanager
from enum import Enum
from typing import Any, Callable, Union, Optional, Dict, List, Tuple, Match, Generator
from typing import Any, Callable, Dict, Generator, List, Match, Optional, Tuple, Union

import yaml

from . import ListConfig, DictConfig
from ._utils import is_structured_config, decode_primitive, isint
from .base import Node, Container
from . import DictConfig, ListConfig
from ._utils import decode_primitive, is_structured_config, isint
from .base import Container, Node
from .basecontainer import BaseContainer
from .errors import ValidationError, MissingMandatoryValue
from .errors import MissingMandatoryValue, ValidationError
from .nodes import (
ValueNode,
StringNode,
IntegerNode,
BooleanNode,
FloatNode,
AnyNode,
BooleanNode,
EnumNode,
FloatNode,
IntegerNode,
StringNode,
ValueNode,
)

MISSING: Any = "???"
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import codecs
import os

import re

import setuptools

here = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -72,8 +72,9 @@ def read(*parts):
"twine",
"sphinx",
"mypy",
"isort",
],
"coverage": ["coveralls"],
"lint": ["black", "flake8", "mypy"],
"lint": ["black", "flake8", "mypy", "isort"],
},
)
11 changes: 5 additions & 6 deletions tests/examples/test_dataclass_example.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import Dict, List, Optional

import pytest

from dataclasses import dataclass, field
from typing import List, Dict, Optional

from omegaconf import (
OmegaConf,
ValidationError,
MISSING,
MissingMandatoryValue,
OmegaConf,
ReadonlyConfigError,
MISSING,
ValidationError,
)


Expand Down
9 changes: 5 additions & 4 deletions tests/structured_conf/attr_test_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Any, Dict, List, Optional

import attr # noqaE402
import pytest # type: ignore
from typing import List, Dict, Any, Optional

from omegaconf import MISSING, II, SI
from omegaconf import II, MISSING, SI

from .common import Color

# attr is a dependency of pytest which means it's always available when testing with pytest.
pytest.importorskip("attr")

import attr # noqaE402


@attr.s(auto_attribs=True)
class User:
Expand Down
9 changes: 5 additions & 4 deletions tests/structured_conf/dataclass_test_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from dataclasses import dataclass, field # noqaE402
from typing import Any, Dict, List, Optional

import pytest # type: ignore
from typing import List, Dict, Optional, Any

from omegaconf import MISSING, II, SI
from omegaconf import II, MISSING, SI

from .common import Color

# skip test if dataclasses are not available
pytest.importorskip("dataclasses")

from dataclasses import dataclass, field # noqaE402


@dataclass
class User:
Expand Down
13 changes: 7 additions & 6 deletions tests/test_base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import pytest

from omegaconf import (
OmegaConf,
MISSING,
DictConfig,
IntegerNode,
StringNode,
ValidationError,
ListConfig,
DictConfig,
OmegaConf,
ReadonlyConfigError,
read_write,
open_dict,
StringNode,
ValidationError,
flag_override,
open_dict,
read_write,
)

from . import does_not_raise


Expand Down
17 changes: 9 additions & 8 deletions tests/test_basic_ops_dict.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import tempfile

import pytest # type: ignore
import re
import tempfile
from enum import Enum
from typing import Any

import pytest # type: ignore

from omegaconf import (
OmegaConf,
MissingMandatoryValue,
UnsupportedValueType,
UnsupportedKeyType,
DictConfig,
AnyNode,
BaseContainer,
DictConfig,
MissingMandatoryValue,
OmegaConf,
UnsupportedKeyType,
UnsupportedValueType,
)

from . import IllegalType


Expand Down
8 changes: 5 additions & 3 deletions tests/test_basic_ops_list.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest
import re

from omegaconf import OmegaConf, AnyNode, ListConfig, DictConfig
from omegaconf.errors import UnsupportedValueType, UnsupportedKeyType
import pytest

from omegaconf import AnyNode, DictConfig, ListConfig, OmegaConf
from omegaconf.errors import UnsupportedKeyType, UnsupportedValueType
from omegaconf.nodes import IntegerNode, StringNode

from . import IllegalType, does_not_raise


Expand Down
3 changes: 2 additions & 1 deletion tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Testing for OmegaConf"""
import re
import sys

import pytest
import re

from omegaconf import OmegaConf
from omegaconf.errors import UnsupportedValueType

from . import IllegalType


Expand Down
1 change: 0 additions & 1 deletion tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest


from omegaconf import OmegaConf


Expand Down
5 changes: 3 additions & 2 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from dataclasses import dataclass, field
from typing import Dict

from omegaconf import OmegaConf, nodes, MISSING
import pytest

from omegaconf import MISSING, OmegaConf, nodes


@dataclass
Expand Down
Loading

0 comments on commit 1e3a057

Please sign in to comment.