Skip to content

Commit

Permalink
feat: replace pkg_resource for importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo-Novas authored and ocelotl committed Sep 4, 2024
1 parent 9cced97 commit 070d566
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from logging import getLogger
from typing import Collection, Optional

from pkg_resources import (
Distribution,
DistributionNotFound,
RequirementParseError,
VersionConflict,
get_distribution,
)
from importlib.metadata import distribution, PackageNotFoundError, Distribution

logger = getLogger(__name__)

Expand Down Expand Up @@ -47,16 +41,7 @@ def get_dependency_conflicts(
) -> Optional[DependencyConflict]:
for dep in deps:
try:
get_distribution(dep)
except VersionConflict as exc:
return DependencyConflict(dep, exc.dist)
except DistributionNotFound:
return DependencyConflict(dep)
except RequirementParseError as exc:
logger.warning(
'error parsing dependency, reporting as a conflict: "%s" - %s',
dep,
exc,
)
distribution(dep)
except PackageNotFoundError:
return DependencyConflict(dep)
return None
8 changes: 3 additions & 5 deletions opentelemetry-instrumentation/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# pylint: disable=protected-access

import pkg_resources
from importlib.metadata import Distribution, requires
import pytest

from opentelemetry.instrumentation.dependencies import (
Expand Down Expand Up @@ -53,14 +53,12 @@ def test_get_dependency_conflicts_mismatched_version(self):
def test_get_dist_dependency_conflicts(self):
def mock_requires(extras=()):
if "instruments" in extras:
return [
pkg_resources.Requirement(
return requires(
'test-pkg ~= 1.0; extra == "instruments"'
)
]
return []

dist = pkg_resources.Distribution(
dist = Distribution(
project_name="test-instrumentation", version="1.0"
)
dist.requires = mock_requires
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-instrumentation/tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from unittest import TestCase

from pkg_resources import EntryPoint
from importlib.metadata import EntryPoint

from opentelemetry.instrumentation.distro import BaseDistro
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
Expand Down

0 comments on commit 070d566

Please sign in to comment.