-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_paths.py
More file actions
35 lines (31 loc) · 854 Bytes
/
Copy path_paths.py
File metadata and controls
35 lines (31 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
def get_package_dir() -> str:
"""Return the package directory where mc_test_app files live.
Robust fallback order:
- dirname(__file__) if available and not empty
- pkgutil loader filename (if available)
- current working directory
"""
# 1) try __file__
try:
dp = os.path.dirname(__file__)
if dp:
return dp
except Exception:
pass
# 2) try pkgutil
try:
import pkgutil
spec = pkgutil.get_loader("mc_test_app")
if spec and hasattr(spec, "get_filename"):
try:
fn = spec.get_filename()
dp = os.path.dirname(fn)
if dp:
return dp
except Exception:
pass
except Exception:
pass
# 3) fallback to cwd
return os.getcwd()