Migrate pkg_resources to importlib_resources (#2352)

This commit is contained in:
Cuong Duong 2023-01-25 16:00:03 +11:00 committed by GitHub
parent 0bf05baf3c
commit 3c5321681a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View file

@ -9,8 +9,7 @@ from abc import abstractmethod, ABC
from typing import Tuple
from collections import OrderedDict
from enum import Enum
from pathlib import Path
import pkg_resources
import importlib_resources
import platform
import logging
@ -59,11 +58,9 @@ class CmdStanPyBackend(IStanBackend):
def __init__(self):
import cmdstanpy
# this must be set before super.__init__() for load_model to work on Windows
local_cmdstan = pkg_resources.resource_filename(
"prophet", f"stan_model/cmdstan-{self.CMDSTAN_VERSION}"
)
if Path(local_cmdstan).exists():
cmdstanpy.set_cmdstan_path(local_cmdstan)
local_cmdstan = importlib_resources.files("prophet") / "stan_model" / f"cmdstan-{self.CMDSTAN_VERSION}"
if local_cmdstan.exists():
cmdstanpy.set_cmdstan_path(str(local_cmdstan))
super().__init__()
@staticmethod
@ -72,11 +69,8 @@ class CmdStanPyBackend(IStanBackend):
def load_model(self):
import cmdstanpy
model_file = pkg_resources.resource_filename(
'prophet',
'stan_model/prophet_model.bin',
)
return cmdstanpy.CmdStanModel(exe_file=model_file)
model_file = importlib_resources.files("prophet") / "stan_model" / "prophet_model.bin"
return cmdstanpy.CmdStanModel(exe_file=str(model_file))
def fit(self, stan_init, stan_data, **kwargs):
if 'inits' not in kwargs and 'init' in kwargs:

View file

@ -22,6 +22,7 @@ dependencies = [
"holidays>=0.14.2",
"python-dateutil>=2.8.0",
"tqdm>=4.36.1",
"importlib_resources",
]
authors = [
{name = "Sean J. Taylor", email = "sjtz@pm.me"},
@ -56,6 +57,6 @@ parallel = [
]
[project.urls]
homepage = "https://facebook.github.io/prophet/"
documentation = "https://facebook.github.io/prophet/"
repository = "https://github.com/facebook/prophet"
Homepage = "https://facebook.github.io/prophet/"
Documentation = "https://facebook.github.io/prophet/"
Repository = "https://github.com/facebook/prophet"