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

Replace pkg_resources usage with packaging + importlib.metadata #392

Merged
merged 5 commits into from
Jul 28, 2022
Merged
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
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