Skip to content

Remove pkg_resources.resource_filename #9590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlflow/_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import platform

import click
import pkg_resources
import pkg_resources # noqa: TID251
import yaml

import mlflow
Expand Down
7 changes: 3 additions & 4 deletions mlflow/models/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import shutil
import signal
import sys
from pathlib import Path
from subprocess import Popen, check_call

from pkg_resources import resource_filename

import mlflow
import mlflow.version
from mlflow import mleap, pyfunc
Expand Down Expand Up @@ -162,8 +161,8 @@ def _serve_pyfunc(model, env_manager):
start_nginx = False

if start_nginx:
nginx_conf = resource_filename(
mlflow.models.__name__, "container/scoring_server/nginx.conf"
nginx_conf = Path(mlflow.models.__file__).parent.joinpath(
"container", "scoring_server", "nginx.conf"
)

nginx = Popen(["nginx", "-c", nginx_conf]) if start_nginx else None
Expand Down
5 changes: 2 additions & 3 deletions mlflow/utils/requirements_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import NamedTuple, Optional

import importlib_metadata
import pkg_resources
import pkg_resources # noqa: TID251
from packaging.requirements import Requirement
from packaging.version import InvalidVersion, Version

Expand Down Expand Up @@ -375,8 +375,7 @@ def _init_packages_to_modules_map():


def _load_pypi_package_index():
pypi_index_path = pkg_resources.resource_filename(mlflow.__name__, "pypi_package_index.json")
with open(pypi_index_path) as f:
with Path(mlflow.__file__).parent.joinpath("pypi_package_index.json").open() as f:
index_dict = json.load(f)

return _PyPIPackageIndex(
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ select = [
"SIM101",
"T20",
"TID252",
"TID251",
]
force-exclude = true
ignore = [
Expand Down Expand Up @@ -86,3 +87,6 @@ ban-relative-imports = "all"

[tool.ruff.isort]
forced-separate = ["tests"]

[tool.ruff.flake8-tidy-imports.banned-api]
"pkg_resources".msg = "We're migrating away from pkg_resources. Please use importlib.resources or importlib.metadata instead."