-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
93 lines (74 loc) · 1.72 KB
/
config.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Package: Qtools
Module: config
(C) 2020-2022 Andreas H. Nielsen
See README.md for further details.
"""
# Configuration parameters
version = '3.2'
# Note to self: remember to also update version in the following files:
# ./README.md
# Decorator
def set_module(module):
"""
Decorator for overriding __module__ on a function or class.
Example usage::
@set_module('numpy')
def example():
pass
assert example.__module__ == 'numpy'
"""
def decorator(func):
if module is not None:
func.__module__ = module
return func
return decorator
# Define a class that holds global information setttings
@set_module('qtools')
class Info:
"""
Provides output from Qtools.
Notes
-----
Use ``Info.setLevel`` to set the level of output. For example::
>>> qt.Info.setLevel(1)
The following output levels are recognised:
0. No output (silent mode)
1. Warnings only
2. Warnings and general information (default)
3. All of the above and debug information
"""
# Set default level
level = 2
@classmethod
def setLevel(cls, lv):
"""Sets the output level.
"""
cls.level = lv
@classmethod
def getLevel(cls):
"""Returns the current output level."""
return cls.level
@classmethod
def warn(cls, warning, prepend=True):
if cls.level >= 1:
if prepend:
warning = 'WARNING: ' + warning
print(warning)
@classmethod
def note(cls, info):
if cls.level >= 2:
print(info)
@classmethod
def deb(cls, info, prepend=True):
if cls.level >= 3:
if prepend:
info = 'DEBUG: ' + info
print(info)
@classmethod
def end(cls):
if cls.level >= 2:
print('------------------------------------------')
# Predecessor to the Info class
# verbose = True
# vprint = print if verbose else lambda *a, **k: None