Skip to content

Commit 2ab0101

Browse files
committed
update profilesmanager to take root_path
1 parent 7d5a371 commit 2ab0101

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/diffpy/cmi/profilesmanager.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,26 @@
2626
presence_check,
2727
)
2828
from diffpy.cmi.log import plog
29-
from diffpy.cmi.packsmanager import PacksManager
29+
from diffpy.cmi.packsmanager import PacksManager, get_package_dir
3030

3131
__all__ = ["Profile", "ProfilesManager"]
3232

3333

34+
def _installed_profiles_dir(root_path=None) -> Path:
35+
"""Locate requirements/profiles/ for the installed package."""
36+
with get_package_dir(root_path) as pkgdir:
37+
pkg = Path(pkgdir).resolve()
38+
for c in (
39+
pkg / "requirements" / "profiles",
40+
pkg.parents[2] / "requirements" / "profiles",
41+
):
42+
if c.is_dir():
43+
return c
44+
raise FileNotFoundError(
45+
"Could not locate requirements/profiles. Check your installation."
46+
)
47+
48+
3449
@dataclass
3550
class Profile:
3651
"""Container for a resolved profile.
@@ -78,9 +93,14 @@ class ProfilesManager:
7893
Defaults to `requirements/profiles` under the installed package.
7994
"""
8095

81-
def __init__(self, packs_mgr: Optional[PacksManager] = None) -> None:
82-
self.packs_mgr = packs_mgr or PacksManager()
83-
self.profiles_dir = self.packs_mgr.packs_dir.parent / "profiles"
96+
def __init__(
97+
self,
98+
packs_mgr: Optional[PacksManager] = None,
99+
root_path=None,
100+
) -> None:
101+
102+
self.packs_mgr = packs_mgr or PacksManager(root_path=root_path)
103+
self.profiles_dir = _installed_profiles_dir(root_path)
84104

85105
# Resolution & loading
86106
def _resolve_profile_file(self, identifier: Union[str, Path]) -> Path:

0 commit comments

Comments
 (0)