Import `packaging` package lazily

This commit is contained in:
Ran Benita 2020-05-13 16:59:44 +03:00
parent 796fba6788
commit f1f9c7792b
2 changed files with 6 additions and 3 deletions

View File

@ -23,7 +23,6 @@ from typing import Union
import attr import attr
import py import py
from packaging.version import Version
from pluggy import HookimplMarker from pluggy import HookimplMarker
from pluggy import HookspecMarker from pluggy import HookspecMarker
from pluggy import PluginManager from pluggy import PluginManager
@ -1059,6 +1058,9 @@ class Config:
minver = self.inicfg.get("minversion", None) minver = self.inicfg.get("minversion", None)
if minver: if minver:
# Imported lazily to improve start-up time.
from packaging.version import Version
if Version(minver) > Version(pytest.__version__): if Version(minver) > Version(pytest.__version__):
raise pytest.UsageError( raise pytest.UsageError(
"%s:%d: requires pytest-%s, actual pytest-%s'" "%s:%d: requires pytest-%s, actual pytest-%s'"

View File

@ -9,8 +9,6 @@ from typing import cast
from typing import Optional from typing import Optional
from typing import TypeVar from typing import TypeVar
from packaging.version import Version
TYPE_CHECKING = False # avoid circular import through compat TYPE_CHECKING = False # avoid circular import through compat
if TYPE_CHECKING: if TYPE_CHECKING:
@ -217,6 +215,9 @@ def importorskip(
return mod return mod
verattr = getattr(mod, "__version__", None) verattr = getattr(mod, "__version__", None)
if minversion is not None: if minversion is not None:
# Imported lazily to improve start-up time.
from packaging.version import Version
if verattr is None or Version(verattr) < Version(minversion): if verattr is None or Version(verattr) < Version(minversion):
raise Skipped( raise Skipped(
"module %r has __version__ %r, required is: %r" "module %r has __version__ %r, required is: %r"