Skip to content

Commit d0744a7

Browse files
authored
Merge pull request #62 from ycexiao/move-get-packages-dir
chore: move function `get_package_dir`into `packsmanager.py`
2 parents 7659ba1 + 440d54b commit d0744a7

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

news/move-get-packages-dir.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Move function get_package_dir from __init__.py into packsmanager.py.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/cmi/__init__.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,9 @@
1515
"""Complex modeling infrastructure:
1616
a modular framework for multi-modal modeling of scientific data."""
1717

18-
from importlib.resources import as_file, files
19-
20-
21-
def get_package_dir(root_path=None):
22-
"""Get the package directory as a context manager.
23-
24-
Parameters
25-
----------
26-
root_path : str, optional
27-
Used for testing, overrides the files(__name__) call.
28-
29-
Returns
30-
-------
31-
context manager
32-
A context manager that yields a pathlib.Path to the package directory.
33-
"""
34-
if root_path is None:
35-
resource = files(__name__)
36-
else:
37-
resource = root_path
38-
return as_file(resource)
39-
4018

4119
__all__ = [
4220
"__version__",
43-
"get_package_dir",
4421
]
4522

4623
# package version

src/diffpy/cmi/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
from shutil import copytree
1919
from typing import Dict, List, Optional, Tuple
2020

21-
from diffpy.cmi import __version__, get_package_dir
21+
from diffpy.cmi import __version__
2222
from diffpy.cmi.conda import env_info
2323
from diffpy.cmi.log import plog, set_log_mode
24-
from diffpy.cmi.packsmanager import PacksManager
24+
from diffpy.cmi.packsmanager import PacksManager, get_package_dir
2525
from diffpy.cmi.profilesmanager import ProfilesManager
2626

2727

src/diffpy/cmi/packsmanager.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#
1414
##############################################################################
1515

16+
from importlib.resources import as_file
1617
from pathlib import Path
1718
from typing import List, Union
1819

19-
from diffpy.cmi import get_package_dir
2020
from diffpy.cmi.installer import (
2121
ParsedReq,
2222
install_requirements,
@@ -25,7 +25,27 @@
2525
)
2626
from diffpy.cmi.log import plog
2727

28-
__all__ = ["PacksManager"]
28+
__all__ = ["PacksManager", "get_package_dir"]
29+
30+
31+
def get_package_dir(root_path=None):
32+
"""Get the package directory as a context manager.
33+
34+
Parameters
35+
----------
36+
root_path : str, optional
37+
Used for testing, overrides the files(__name__) call.
38+
39+
Returns
40+
-------
41+
context manager
42+
A context manager that yields a pathlib.Path to the package directory.
43+
"""
44+
if root_path is None:
45+
resource = Path(__file__).parents[0]
46+
else:
47+
resource = root_path
48+
return as_file(resource)
2949

3050

3151
def _installed_packs_dir(root_path=None) -> Path:

0 commit comments

Comments
 (0)