Skip to content

Commit

Permalink
Replace pkg_resources usage with packaging + importlib.metadata (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-indigo authored Jul 28, 2022
1 parent 8a9eeeb commit ca3cf55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
27 changes: 20 additions & 7 deletions geoalchemy2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,25 @@ def load_spatialite(dbapi_conn, connection_record):

# Get version number
__version__ = "UNKNOWN VERSION"

# Attempt to use importlib.metadata first because it's much faster
# though it's only available in Python 3.8+ so we'll need to fall
# back to pkg_resources for Python 3.7 support
try:
from pkg_resources import DistributionNotFound
from pkg_resources import get_distribution
import importlib.metadata
except ImportError:
try:
from pkg_resources import DistributionNotFound
from pkg_resources import get_distribution
except ImportError: # pragma: no cover
pass
else:
try:
__version__ = get_distribution('GeoAlchemy2').version
except DistributionNotFound: # pragma: no cover
pass
else:
try:
__version__ = get_distribution('GeoAlchemy2').version
except DistributionNotFound: # pragma: no cover
pass # pragma: no cover
except ImportError: # pragma: no cover
pass # pragma: no cover
__version__ = importlib.metadata.version('GeoAlchemy2')
except importlib.metadata.PackageNotFoundError: # pragma: no cover
pass
4 changes: 2 additions & 2 deletions geoalchemy2/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"""
import shapely.wkb
import shapely.wkt
from pkg_resources import parse_version
from packaging import version

from .elements import WKBElement
from .elements import WKTElement

if parse_version(shapely.__version__) < parse_version("1.7"): # pragma: no cover
if version.parse(shapely.__version__) < version.parse('1.7'): # pragma: no cover
######################################################################
# Backport function from Shapely 1.7
from shapely.geometry.base import geom_factory
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ passenv=
setenv=
COVERAGE_FILE = {env:COVERAGE_FILE:.coverage-{envname}}
EXPECTED_COV = 91
pypy3: EXPECTED_COV = 78
pypy3: EXPECTED_COV = 77
deps=
alembic
sqla14: SQLAlchemy==1.4.*
Expand Down

0 comments on commit ca3cf55

Please sign in to comment.