Skip to content

Commit

Permalink
Remove the use of the deprecated pkg_resources package (#13842)
Browse files Browse the repository at this point in the history
* Remove the use of the deprecated `pkg_resources` package

* pin

* Update LICENSE-3rdparty.csv

* fix test
  • Loading branch information
ofek authored Jan 31, 2023
1 parent 4ddb910 commit 029e00f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ futures,PyPI,PSF,Copyright (c) 2015 Brian Quinlan
gearman,PyPI,Apache-2.0,Copyright 2010 Yelp <[email protected]>
gssapi,PyPI,ISC,"Copyright (c) 2014, The Python GSSAPI Team"
immutables,PyPI,Apache-2.0,Copyright 2018-present Contributors to the immutables project.
importlib-metadata,PyPI,Apache-2.0,Copyright Jason R. Coombs
in-toto,PyPI,Apache-2.0,Copyright 2018 New York University
ipaddress,PyPI,PSF,Copyright (c) 2013 Philipp Hagemeister
jellyfish,PyPI,BSD-3-Clause,"Copyright (c) 2015, James Turk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gearman==2.0.2; sys_platform != 'win32' and python_version < '3.0'
gssapi==1.6.1; python_version < '3.0'
gssapi==1.8.2; python_version > '3.0'
immutables==0.19; python_version > '3.0'
importlib-metadata==2.1.3; python_version < '3.8'
in-toto==1.0.1; python_version > '3.0'
ipaddress==1.0.23; python_version < '3.0'
jaydebeapi==1.2.3
Expand Down
20 changes: 12 additions & 8 deletions datadog_checks_base/datadog_checks/base/utils/agent/packages.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# (C) Datadog, Inc. 2019-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import sys

import pkg_resources
if sys.version_info >= (3, 8):
from importlib.metadata import distributions
else:
from importlib_metadata import distributions

DATADOG_CHECK_PREFIX = "datadog-"
DATADOG_CHECK_PREFIX = 'datadog-'


def get_datadog_wheels():
packages = []
dist = list(pkg_resources.working_set)
for package in dist:
if package.project_name.startswith(DATADOG_CHECK_PREFIX):
name = package.project_name[len(DATADOG_CHECK_PREFIX) :].replace('-', '_')
packages.append(name)
packages = set()
for package in distributions():
project_name = package.metadata['Name']
if project_name.startswith(DATADOG_CHECK_PREFIX):
name = project_name[len(DATADOG_CHECK_PREFIX) :].replace('-', '_')
packages.add(name)

return sorted(packages)[::-1]
1 change: 1 addition & 0 deletions datadog_checks_base/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ deps = [
"ddtrace==0.32.2; sys_platform == 'win32' and python_version < '3.0'",
"ddtrace==0.53.2; sys_platform != 'win32' or python_version > '3.0'",
"enum34==1.1.10; python_version < '3.0'",
"importlib-metadata==2.1.3; python_version < '3.8'",
"immutables==0.19; python_version > '3.0'",
"ipaddress==1.0.23; python_version < '3.0'",
"jellyfish==0.9.0; python_version > '3.0'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def get_wheel_relpath(self, standard_distribution_name, version=None, ignore_pyt
raise MissingVersions(standard_distribution_name)

if not version:
# https://setuptools.readthedocs.io/en/latest/pkg_resources.html#parsing-utilities
# https://packaging.pypa.io/en/latest/version.html
version = str(max(parse_version(v) for v in wheels.keys()))

python_tags = wheels[version]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""
import os.path

from pkg_resources import safe_name
from packaging.utils import canonicalize_name

from .exceptions import NonDatadogPackage

Expand All @@ -28,7 +28,7 @@ def substitute(target_relpath):
if not wheel_distribution_name.startswith('datadog_'):
raise NonDatadogPackage(wheel_distribution_name)

standard_distribution_name = safe_name(wheel_distribution_name)
standard_distribution_name = canonicalize_name(wheel_distribution_name)

# These names are the exceptions. In this case, the wheel distribution name
# matches exactly the directory name of the check on GitHub.
Expand Down
5 changes: 0 additions & 5 deletions mcache/datadog_checks/mcache/mcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import division

import bmemcached
import pkg_resources
from six import iteritems, itervalues

from datadog_checks.base import AgentCheck, ConfigurationError
Expand Down Expand Up @@ -105,10 +104,6 @@ class Memcache(AgentCheck):

SERVICE_CHECK = 'memcache.can_connect'

@classmethod
def get_library_versions(cls):
return {"memcache": pkg_resources.get_distribution("python-binary-memcached").version}

def _process_response(self, response):
"""
Examine the response and raise an error is something is off
Expand Down

0 comments on commit 029e00f

Please sign in to comment.