Skip to content

Commit

Permalink
Add Support for Python 3.12 (#123)
Browse files Browse the repository at this point in the history
Using alternative to pkg_resources for getting the package version (python 3.12 does not have this module).
  • Loading branch information
bh2smith authored Apr 23, 2024
1 parent 604d505 commit 24af734
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.11"]
python-version: ["3.8", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
10 changes: 5 additions & 5 deletions dune_client/util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Utility methods for package."""

from datetime import datetime, timezone
import importlib
from typing import Optional

import pkg_resources

DUNE_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"


Expand All @@ -15,11 +14,12 @@ def postgres_date(date_str: str) -> datetime:

def get_package_version(package_name: str) -> Optional[str]:
"""
Returns the package version by `package_name`
Returns the package version by `package_name` using the importlib.metadata module
which is available in Python 3.8 and later.
"""
try:
return pkg_resources.get_distribution(package_name).version
except pkg_resources.DistributionNotFound:
return importlib.metadata.version(package_name)
except importlib.metadata.PackageNotFoundError:
return None


Expand Down

0 comments on commit 24af734

Please sign in to comment.