-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
65 lines (54 loc) · 1.98 KB
/
init.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
60
61
62
63
64
65
from cmdstanpy import CmdStanModel
import numpy as np
import pandas as pd
import arviz as az
import utils as utils
import scipy.stats as stats
import matplotlib.pyplot as plt
import seaborn as sns
# ---
__all__ = ['CmdStanModel', 'np', 'pd', 'az', 'utils', 'stats', 'plt', 'sns']
# Print imports / aliases
with open(__file__) as f:
lines = f.readlines()
from colorama import Fore
import re
def print_import(import_line):
import_line = import_line.strip()
if not import_line or not (import_line.startswith("import") or import_line.startswith("from")):
return # Skip non-import lines
# Regular expressions for parsing imports
import_regex = re.compile(r"import\s+([\w.]+)(?:\s+as\s+(\w+))?")
from_import_regex = re.compile(r"from\s+([\w.]+)\s+import\s+([\w.*]+)(?:\s+as\s+(\w+))?")
# Match `import` statements
match_import = import_regex.match(import_line)
if match_import:
module, alias = match_import.groups()
msg = Fore.GREEN + "import " + Fore.BLUE + module
if alias:
msg += Fore.GREEN + " as " + Fore.BLUE + alias
print(msg)
return
# Match `from ... import` statements
match_from_import = from_import_regex.match(import_line)
if match_from_import:
module, submodule, alias = match_from_import.groups()
msg = Fore.GREEN + "from " + Fore.BLUE + module + Fore.GREEN + " import " + Fore.BLUE + submodule
if alias:
msg += Fore.GREEN + " as " + Fore.BLUE + alias
print(msg)
print(Fore.RED + f"Module aliases imported by init_notebook.py:\n{'-'*44}")
for l in lines:
if "# ---" in l:
break
print_import(l)
from watermark import watermark # noqa: E402
print()
print(Fore.RED + f"Watermark:\n{'-'* 10}")
print(Fore.BLUE + watermark())
print(Fore.BLUE + watermark(iversions=True, globals_=globals()))
import warnings # noqa: E402
warnings.filterwarnings("ignore")
from matplotlib import style # noqa: E402
STYLE = "PlottingStyle.mplstyle"
style.use(STYLE)