Skip to content

Commit

Permalink
Change from pkg_resources to importlib metadata (#329)
Browse files Browse the repository at this point in the history
* Change from pkg_resources to importlib metadata
  • Loading branch information
shenxiangzhuang authored Nov 7, 2023
1 parent f8c5063 commit ed6aa87
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fixes:
- Fix unexpected 'No active span' IllegalStateError (#311)
- **Tentative**: Set upper bound <=5.9.5 for psutil package due to test failure. (#326)
- Remove `DeprecationWarning` from `pkg_resources` by replace it with `importlib_metadata` (#329)

### 1.0.1

Expand Down
21 changes: 18 additions & 3 deletions skywalking/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@
import re
import traceback

import pkg_resources
import sys

if sys.version_info < (3, 8):
import pkg_resources
PackageNotFoundException = pkg_resources.DistributionNotFound

def get_pkg_version(pkg_name):
return pkg_resources.get_distribution(pkg_name).version

else:
import importlib.metadata
PackageNotFoundException = importlib.metadata.PackageNotFoundError

def get_pkg_version(pkg_name):
return importlib.metadata.version(pkg_name)

from packaging import version

import skywalking
Expand Down Expand Up @@ -78,8 +93,8 @@ def pkg_version_check(plugin):
rules = plugin.version_rule.get('rules')

try:
current_pkg_version = pkg_resources.get_distribution(pkg_name).version
except pkg_resources.DistributionNotFound:
current_pkg_version = get_pkg_version(pkg_name)
except PackageNotFoundException:
# when failed to get the version, we consider it as supported.
return supported

Expand Down
11 changes: 9 additions & 2 deletions tools/grpc_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@
import os
import re

import pkg_resources
from grpc_tools import protoc
from packaging import version
import sys

if sys.version_info < (3, 8):
import pkg_resources
grpc_tools_version = pkg_resources.get_distribution('grpcio-tools').version

else:
import importlib.metadata
grpc_tools_version = importlib.metadata.version('grpcio-tools')

grpc_tools_version = pkg_resources.get_distribution('grpcio-tools').version
dest_dir = 'skywalking/protocol'
src_dir = 'protocol'

Expand Down

0 comments on commit ed6aa87

Please sign in to comment.