Skip to content

Commit 0f1f443

Browse files
ref: factor out our remaining pkg_resources usages (#62084)
this requires python 3.9+ <!-- Describe your PR here. -->
1 parent 52f5fa3 commit 0f1f443

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/sentry/runner/settings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.resources
12
import os
23
import warnings
34

@@ -16,10 +17,8 @@ def generate_secret_key():
1617
return get_random_string(50, chars)
1718

1819

19-
def load_config_template(path, version="default"):
20-
from pkg_resources import resource_string
21-
22-
return resource_string("sentry", f"data/config/{path}.{version}").decode("utf8")
20+
def load_config_template(path: str, version: str = "default") -> str:
21+
return importlib.resources.files("sentry").joinpath(f"data/config/{path}.{version}").read_text()
2322

2423

2524
def generate_settings(dev=False):

src/sentry/tsdb/redis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.resources
12
import itertools
23
import logging
34
import random
@@ -9,7 +10,6 @@
910

1011
from django.utils import timezone
1112
from django.utils.encoding import force_bytes
12-
from pkg_resources import resource_string
1313

1414
from sentry.tsdb.base import BaseTSDB
1515
from sentry.utils.compat import crc32
@@ -23,7 +23,9 @@
2323

2424
SketchParameters = namedtuple("SketchParameters", "depth width capacity")
2525

26-
CountMinScript = SentryScript(None, resource_string("sentry", "scripts/tsdb/cmsketch.lua"))
26+
CountMinScript = SentryScript(
27+
None, importlib.resources.files("sentry").joinpath("scripts/tsdb/cmsketch.lua").read_bytes()
28+
)
2729

2830

2931
class SuppressionWrapper:

src/sentry/utils/redis.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from __future__ import annotations
22

33
import functools
4+
import importlib.resources
45
import logging
5-
import posixpath
66
from copy import deepcopy
77
from threading import Lock
88
from typing import Any, Generic, TypeVar, overload
99

1010
import rb
1111
from django.utils.functional import SimpleLazyObject
12-
from pkg_resources import resource_string
1312
from redis.client import Script
1413
from redis.connection import ConnectionPool, Encoder
1514
from redis.exceptions import BusyLoadingError, ConnectionError
@@ -304,7 +303,10 @@ def call_script(client, keys, args):
304303
# XXX: Script is a list here. We're doing this to work around the lack of
305304
# `nonlocal` in python 3, so that we only instantiate the script once.
306305
script.append(
307-
Script(client, resource_string("sentry", posixpath.join("scripts", path)))
306+
Script(
307+
client,
308+
importlib.resources.files("sentry").joinpath("scripts", path).read_bytes(),
309+
)
308310
)
309311
# Unset the client here to keep things as close to how they worked before
310312
# as possible. It will always be overridden on `__call__` anyway.

0 commit comments

Comments
 (0)