Skip to content

Commit

Permalink
Python: Replace deprecated pkg_resources usage with importlib_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Nov 19, 2024
1 parent e0d62dd commit 7b95825
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions glean-core/python/glean/_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
This module loads the built-in metrics and pings.
"""

from pkg_resources import resource_filename
import sys


from ._loader import load_metrics, load_pings
if sys.version_info >= (3, 9):
import importlib.resources as importlib_resources
else:
import importlib_resources


metrics = load_metrics(resource_filename(__name__, "metrics.yaml"), config={"allow_reserved": True})
from ._loader import load_metrics, load_pings

ref = importlib_resources.files(__name__) / "metrics.yaml"
with importlib_resources.as_file(ref) as path:
metrics = load_metrics(path, config={"allow_reserved": True})

pings = load_pings(resource_filename(__name__, "pings.yaml"), config={"allow_reserved": True})
ref = importlib_resources.files(__name__) / "pings.yaml"
with importlib_resources.as_file(ref) as path:
pings = load_pings(path, config={"allow_reserved": True})


__all__ = ["metrics", "pings"]
1 change: 0 additions & 1 deletion glean-core/python/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ruff==0.7.2
semver==2.13.0
setuptools-git==1.2
twine==5.0.0
types-pkg_resources==0.1.3
wheel==0.45.0
maturin==1.7.4
patchelf>=0.17; sys_platform == "linux"
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ maintainers = [
dependencies = [
"semver>=2.13.0",
"glean_parser~=15.2",
"importlib_resources>=1.3; python_version=='3.8'"
]

[project.urls]
Expand Down

0 comments on commit 7b95825

Please sign in to comment.