From 24af7348d791e887c93a735e0de2046f210cbddb Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Tue, 23 Apr 2024 09:58:59 +0200 Subject: [PATCH] Add Support for Python 3.12 (#123) Using alternative to pkg_resources for getting the package version (python 3.12 does not have this module). --- .github/workflows/pull-request.yaml | 2 +- dune_client/util.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 523b83d..f34f28e 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -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 }} diff --git a/dune_client/util.py b/dune_client/util.py index 686bbf3..b678499 100644 --- a/dune_client/util.py +++ b/dune_client/util.py @@ -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" @@ -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