Refactor: turn iniconfig import optional
This commit is contained in:
parent
b4ab2f0942
commit
8db673c1f1
|
@ -10,8 +10,6 @@ from typing import Tuple
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import iniconfig
|
|
||||||
|
|
||||||
from .exceptions import UsageError
|
from .exceptions import UsageError
|
||||||
from _pytest.outcomes import fail
|
from _pytest.outcomes import fail
|
||||||
from _pytest.pathlib import absolutepath
|
from _pytest.pathlib import absolutepath
|
||||||
|
@ -19,17 +17,20 @@ from _pytest.pathlib import commonpath
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from . import Config
|
from . import Config
|
||||||
|
from iniconfig import IniConfig # NOQA: F401
|
||||||
|
|
||||||
|
|
||||||
def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
|
def _parse_ini_config(path: Path) -> "IniConfig":
|
||||||
"""Parse the given generic '.ini' file using legacy IniConfig parser, returning
|
"""Parse the given generic '.ini' file using legacy IniConfig parser, returning
|
||||||
the parsed object.
|
the parsed object.
|
||||||
|
|
||||||
Raise UsageError if the file cannot be parsed.
|
Raise UsageError if the file cannot be parsed.
|
||||||
"""
|
"""
|
||||||
|
from iniconfig import IniConfig, ParseError # NOQA: F811
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return iniconfig.IniConfig(str(path))
|
return IniConfig(os.fspath(path), data=path.read_text())
|
||||||
except iniconfig.ParseError as exc:
|
except ParseError as exc:
|
||||||
raise UsageError(str(exc)) from exc
|
raise UsageError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue