Skip to content

Commit 6878bc1

Browse files
committed
📝 Improve docs
1 parent 1e8a60b commit 6878bc1

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

docs/02_config.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ Settings.toml
7474
.. literalinclude:: ../examples/example.env
7575
:linenos:
7676

77+
78+
Config
79+
=======
80+
81+
.. automodule:: tt.config
82+
:members:
83+
:undoc-members:

examples/example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# TELEGRAM BOT #
1414
# on Binance #
1515
########################################
16+
# TT_LOGLEVEL = 'INFO'
1617
# TT_PLATFORM__MAIN__BOT_TOKEN = '121212121'
1718
# TT_PLATFORM__MAIN__BOT_CHANNEL_ID = '-1122121'
1819
# TT_PLATFORM__MAIN__BOT_API_ID = '1212912'

tt/config.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
### ㊙️ Secrets ###
2222
#######################################
2323

24+
"""
25+
In case, you use 1Password to store your settings, you can use :file:`.secrets.toml`
26+
to retrieve and store your settings from a notesPlain item.
27+
more info: https://support.1password.com/command-line-getting-started/
28+
29+
in order to use 1Password, you need to add the following to your :file:`.env` file:
30+
- OP_SERVICE_ACCOUNT_TOKEN: your 1Password service account token
31+
- OP_VAULT: your 1Password vault
32+
- OP_ITEM: your 1Password item
33+
- OP_PATH: your one 1Password path (optional and default value `/usr/bin/op`)
34+
35+
The :file:`.secrets.toml` will be located in :file:`/tt/.secrets.toml` and
36+
be created by the OP client via `op read op://vault/item/notesPlain > .secrets.toml`
37+
38+
"""
39+
2440
if os.getenv("OP_SERVICE_ACCOUNT_TOKEN") and os.path.exists(os.getenv("OP_PATH")):
2541
loguru_logger.debug("Using OnePassword")
2642
command = [
@@ -39,6 +55,34 @@
3955
### ⚙️ Settings ###
4056
#######################################
4157

58+
"""
59+
Settings are loaded via dynaconf
60+
Dynaconf is a powerful and easy-to-use
61+
management library for Python.
62+
It supports TOML settings file, .env file or environment variable, and other types.
63+
Refer to https://github.com/dynaconf/dynaconf for more information.
64+
65+
More than 100 settings customizable via settings.toml or .env.
66+
Most of them are predefined and you only need to
67+
update the credentials related to your exchange and chat platform
68+
69+
Config will load:
70+
- talky default: talky_settings.toml
71+
- default from library if the library support it: default_settings.toml
72+
- user settings: settings.toml
73+
- user secrets: .secrets.toml
74+
75+
Your settings should be setup in
76+
settings.toml,
77+
.secrets.toml,
78+
.env or
79+
environment variable.
80+
Settings.toml or .env can be located in :file:`/app/settings.toml`
81+
or :file:`/app/.env` for docker.
82+
If deployed locally, place your file in :file:`/tt/` folder.
83+
84+
"""
85+
4286
ROOT = os.path.dirname(__file__)
4387

4488
settings = Dynaconf(
@@ -67,16 +111,45 @@
67111
### ⏱️ Scheduling ###
68112
########################################
69113

114+
"""
115+
Scheduling is managed via asyncz lib
116+
More info: https://github.com/tarsil/asyncz
117+
118+
It allows you to schedule tasks at plugin level.
119+
Refer to the plugin documentation
120+
:file:`tt.plugins.plugin_manager`
121+
122+
"""
123+
70124
scheduler = AsyncIOScheduler()
71125

72126

73127
########################################
74128
### 🧐 Logging ###
75129
########################################
76130

131+
"""
132+
Logging is managed via loguru
133+
"""
134+
77135

78136
class InterceptHandler(logging.Handler):
137+
"""
138+
InterceptHandler is a loguru handler
139+
that intercepts all log records.
140+
It can be used as a replacement for logging.basicConfig()
141+
"""
142+
79143
def emit(self, record):
144+
"""
145+
Emit a log record.
146+
147+
Args:
148+
record (logging.LogRecord): The log record to emit.
149+
150+
Returns:
151+
None
152+
"""
80153
# Get corresponding Loguru level if it exists.
81154
try:
82155
level = logger.level(record.levelname).name
@@ -95,6 +168,12 @@ def emit(self, record):
95168

96169

97170
def loguru_setup():
171+
"""
172+
Set up the loguru logger with custom configurations.
173+
174+
Returns:
175+
loguru.logger: The configured loguru logger instance.
176+
"""
98177
loguru_logger.remove()
99178
log_filters = {
100179
"discord": settings.thirdparty_lib_loglevel,
@@ -113,7 +192,14 @@ def loguru_setup():
113192
filter=log_filters,
114193
)
115194
if settings.loglevel == "DEBUG":
116-
loguru_logger.warning("DEBUG ENABLED")
195+
loguru_logger.warning(
196+
"""
197+
DEBUG ENABLED,
198+
You can disable it
199+
loglevel='INFO' in settings.toml
200+
TT_LOGLEVEL=INFO in your .env or vars.
201+
"""
202+
)
117203
return loguru_logger
118204

119205

0 commit comments

Comments
 (0)