Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decrease memory consumption, use importlib.metadata to get package version instead of pkg_resources.get_dictribution #579

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cerberus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

"""

from pkg_resources import get_distribution, DistributionNotFound
from typing import Dict, Optional, Tuple, Union

from cerberus.base import (
Expand All @@ -21,11 +20,9 @@
from cerberus.schema import SchemaError
from cerberus.validator import Validator

from cerberus.platform import importlib_metadata

try:
__version__ = get_distribution("Cerberus").version
except DistributionNotFound:
__version__ = "unknown"
__version__ = importlib_metadata.version("Cerberus")


def validator_factory(
Expand Down
4 changes: 4 additions & 0 deletions cerberus/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


if sys.version_info < (3, 7):
import importlib_metadata
from typing import _ForwardRef as ForwardRef, GenericMeta as GenericAlias
from typing import _Union, Union

Expand All @@ -24,6 +25,7 @@ def has_concrete_args(tp):


elif sys.version_info < (3, 8):
import importlib_metadata
from typing import ForwardRef, _GenericAlias as GenericAlias

def get_type_args(tp):
Expand All @@ -41,6 +43,7 @@ def has_concrete_args(tp):


elif sys.version_info < (3, 9):
import importlib.metadata as importlib_metadata
from typing import ForwardRef, _GenericAlias as GenericAlias # type: ignore
from typing import get_args as get_type_args
from typing import get_origin as get_type_origin
Expand All @@ -50,6 +53,7 @@ def has_concrete_args(tp):


else:
import importlib.metadata as importlib_metadata
from typing import ForwardRef, _BaseGenericAlias as GenericAlias
from typing import get_args as get_type_args
from typing import get_origin as get_type_origin
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
setup_requires=setup_requires,
tests_require=["pytest"],
test_suite="cerberus.tests",
install_requires=["setuptools"],
install_requires=[
"setuptools",
"importlib-metadata; python_version < '3.8'",
],
keywords=["validation", "schema", "dictionaries", "documents", "normalization"],
python_requires=">=3.5",
classifiers=[
Expand Down