|
26 | 26 | presence_check, |
27 | 27 | ) |
28 | 28 | from diffpy.cmi.log import plog |
29 | | -from diffpy.cmi.packsmanager import PacksManager |
| 29 | +from diffpy.cmi.packsmanager import PacksManager, get_package_dir |
30 | 30 |
|
31 | 31 | __all__ = ["Profile", "ProfilesManager"] |
32 | 32 |
|
33 | 33 |
|
| 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 | + |
34 | 49 | @dataclass |
35 | 50 | class Profile: |
36 | 51 | """Container for a resolved profile. |
@@ -78,9 +93,14 @@ class ProfilesManager: |
78 | 93 | Defaults to `requirements/profiles` under the installed package. |
79 | 94 | """ |
80 | 95 |
|
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) |
84 | 104 |
|
85 | 105 | # Resolution & loading |
86 | 106 | def _resolve_profile_file(self, identifier: Union[str, Path]) -> Path: |
|
0 commit comments