-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_utils.py
59 lines (48 loc) · 1.36 KB
/
_utils.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os, sys
from typing import Tuple, Union, Callable
def cmdSupport(
name: str,
package: str,
fn: str,
) -> Tuple[str, str, bool]:
"""
Advanced support for command line execution of package components. Fixes import
from sibling scripts within the package even if invoked from command line.
Parameters
----------
name
Name of the script to be referenced during import.
package
Parent package of the script.
fn
File name of the script.
Returns
-------
name
Name of the script to be referenced during import.
package
Parent package of the script.
invoked_directly
If the script was invoke via command line or imported from another script.
"""
invoked_directly = False
if name == "__main__":
invoked_directly = True
dir_path = os.path.dirname(os.path.realpath(fn))
sys.path.append(os.path.dirname(dir_path))
package = os.path.basename(dir_path)
name = package + "." + fn[:-3]
return name, package, invoked_directly
def hint(verbose: bool, *vargs) -> None:
"""
Print only if verbosity is desired.
Parameters
----------
verbose
If the following inputs need to be printed.
args
Strings that need to be printed
"""
if verbose:
print("\n", *vargs)
return