Skip to content

Commit 1ab9626

Browse files
authored
Merge pull request #504 from yungwine/lint
add ruff check for the whole project
2 parents 5822802 + 077514a commit 1ab9626

32 files changed

+151
-385
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
3636
- name: Run Ruff
3737
run: |
38-
ruff check mytonctrl # wip adding ruff linting across the whole project
38+
ruff check
3939
4040
- name: Build project
4141
run: |

modules/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from modules.collator import CollatorModule
55
from modules.module import MtcModule
6-
from modules.pool import PoolModule
76
from modules.nominator_pool import NominatorPoolModule
87
from modules.single_pool import SingleNominatorModule
98
from modules.validator import ValidatorModule

modules/alert_bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from modules.module import MtcModule
66
from mypylib.mypylib import get_timestamp, print_table, color_print
7-
from mytoncore import get_hostname, signed_int_to_hex64
7+
from mytoncore.utils import get_hostname, signed_int_to_hex64
88
from mytonctrl.console_cmd import add_command, check_usage_one_arg, check_usage_two_args
99
from mytonctrl.utils import timestamp2utcdatetime
1010

@@ -374,7 +374,7 @@ def setup_alert_bot(self, args):
374374
color_print("setup_alert_bot - {green}OK{endc}")
375375
except Exception as e:
376376
self.local.add_log(f"Error while sending welcome message: {e}", "error")
377-
self.local.add_log(f"If you want the bot to write to a multi-person chat group, make sure the bot is added to that chat group. If it is not - do it and run the command `setup_alert_bot <bot_token> <chat_id>` again.", "info")
377+
self.local.add_log("If you want the bot to write to a multi-person chat group, make sure the bot is added to that chat group. If it is not - do it and run the command `setup_alert_bot <bot_token> <chat_id>` again.", "info")
378378
color_print("setup_alert_bot - {red}Error{endc}")
379379

380380
def send_welcome_message(self):

modules/backups.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
import shutil
33
import subprocess
44
import time
5-
import typing
65
from typing import Optional
76

87
from modules.module import MtcModule
9-
from mytonctrl.console_cmd import add_command, check_usage_two_args, check_usage_args_min_max_len
8+
from mytonctrl.console_cmd import add_command, check_usage_args_min_max_len
109
from mypylib.mypylib import color_print, ip2int, run_as_root, parse
1110
from mytoncore.utils import get_package_resource_path
1211
from mytonctrl.utils import get_current_user, pop_user_from_args
@@ -69,7 +68,7 @@ def restore_backup(self, args):
6968
user = pop_user_from_args(args)
7069
if '-y' not in args:
7170
res = input(
72-
f'This action will overwrite existing configuration with contents of backup archive, please make sure that donor node is not in operation prior to this action. Proceed [y/n]')
71+
'This action will overwrite existing configuration with contents of backup archive, please make sure that donor node is not in operation prior to this action. Proceed [y/n]')
7372
if res.lower() != 'y':
7473
print('aborted.')
7574
return
@@ -81,8 +80,8 @@ def restore_backup(self, args):
8180
print('Before proceeding, mtc will create a backup of current configuration.')
8281
try:
8382
self.create_backup([])
84-
except:
85-
color_print("{red}Could not create backup{endc}")
83+
except Exception as e:
84+
color_print(f"{{red}}Could not create backup: {e}{{endc}}")
8685

8786
ip = str(ip2int(get_own_ip()))
8887
command_args = ["-m", self.ton.local.buffer.my_work_dir, "-n", args[0], "-i", ip]

modules/collator.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from modules.module import MtcModule
22
from mypylib import color_print, print_table
3-
from mytoncore import b642hex, signed_int_to_hex64, shard_prefix_len, hex_shard_to_int, shard_prefix, shard_is_ancestor
3+
from mytoncore.utils import b642hex, signed_int_to_hex64, shard_prefix_len, hex_shard_to_int, shard_prefix, shard_is_ancestor
44
from mytonctrl.console_cmd import check_usage_args_min_len, add_command, check_usage_no_args, check_usage_args_lens
55
from mytonctrl.utils import pop_arg_from_args
66

7+
from typing import TYPE_CHECKING
8+
if TYPE_CHECKING:
9+
from mytoncore import MyTonCore
10+
711

812
class CollatorModule(MtcModule):
913

@@ -83,7 +87,7 @@ def stop_collator(self, args: list):
8387
if not check_usage_args_lens("stop_collator", args, [0, 2]):
8488
return
8589
if not args:
86-
text = f"{{red}}WARNING: This action will stop and delete all local collation broadcasts from this node for all shards.{{endc}}\n"
90+
text = "{red}WARNING: This action will stop and delete all local collation broadcasts from this node for all shards.{endc}\n"
8791
color_print(text)
8892
if input("Continue anyway? [Y/n]\n").strip().lower() not in ('y', ''):
8993
print('aborted.')
@@ -134,7 +138,7 @@ def print_collators(self, args: list = None):
134138
def add_validator_to_collation_wl(self, args: list):
135139
if not check_usage_args_min_len("add_validator_to_collation_wl", args, 1):
136140
return
137-
self.ton.validatorConsole.Run(f"collator-whitelist-enable 1")
141+
self.ton.validatorConsole.Run("collator-whitelist-enable 1")
138142
self.local.add_log("Collation whitelist enabled")
139143
for adnl_addr in args:
140144
result = self.ton.validatorConsole.Run(f"collator-whitelist-add {adnl_addr}")
@@ -154,7 +158,7 @@ def delete_validator_from_collation_wl(self, args: list):
154158
def disable_collation_validator_wl(self, args: list):
155159
if not check_usage_no_args("disable_collation_wl", args):
156160
return
157-
result = self.ton.validatorConsole.Run(f"collator-whitelist-enable 0")
161+
result = self.ton.validatorConsole.Run("collator-whitelist-enable 0")
158162
if 'success' not in result:
159163
raise Exception(f'Failed to disable collation validator whitelist: {result}')
160164
color_print("disable_collation_validator_wl - {green}OK{endc}")
@@ -167,8 +171,8 @@ def print_collation_validators_whitelist(self, args: list = None):
167171
@classmethod
168172
def check_enable(cls, ton: "MyTonCore"):
169173
if ton.using_validator():
170-
raise Exception(f'Cannot enable collator mode while validator mode is enabled. '
171-
f'Use `disable_mode validator` first.')
174+
raise Exception('Cannot enable collator mode while validator mode is enabled. '
175+
'Use `disable_mode validator` first.')
172176

173177
def check_disable(self):
174178
have_collators_text = 'has active collator working and ' if self.get_collators() else ''

modules/collator_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def get_config(path):
3636
else:
3737
config = CollatorConfigModule.check_config_file(path)
3838
if config is None:
39-
raise Exception(f'Failed to get config')
39+
raise Exception('Failed to get config')
4040
return config
4141

4242
def add_collator_config_to_vc(self, config: dict):
43-
self.local.add_log(f"Adding collator options config to validator console", "debug")
44-
path = self.ton.tempDir + f'/collator_config.json'
43+
self.local.add_log("Adding collator options config to validator console", "debug")
44+
path = self.ton.tempDir + '/collator_config.json'
4545
with open(path, 'w') as f:
4646
json.dump(config, f)
4747
result = self.ton.validatorConsole.Run(f"setcollatoroptionsjson {path}")
@@ -63,15 +63,15 @@ def set_collator_config(self, args):
6363
def get_collator_config(self, args):
6464
location = self.ton.get_collator_config_location()
6565
print(f'Collator config location: {location}')
66-
path = self.ton.tempDir + f'/current_collator_config.json'
66+
path = self.ton.tempDir + '/current_collator_config.json'
6767
output = self.ton.validatorConsole.Run(f'getcollatoroptionsjson {path}')
6868
if 'saved config to' not in output:
6969
print(f'Failed to get collator config: {output}')
7070
color_print("get_collator_config - {red}ERROR{endc}")
7171
return
7272
with open(path, 'r') as f:
7373
config = json.load(f)
74-
print(f'Collator config:')
74+
print('Collator config:')
7575
print(json.dumps(config, indent=4))
7676
color_print("get_collator_config - {green}OK{endc}")
7777

modules/controller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from mytonctrl.utils import GetItemFromList
99
from modules.module import MtcModule
1010

11+
from typing import TYPE_CHECKING
12+
if TYPE_CHECKING:
13+
from mytoncore import MyTonCore
14+
1115

1216
class ControllerModule(MtcModule):
1317

modules/liteserver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import psutil
2-
31
from modules.module import MtcModule
42

53

4+
from typing import TYPE_CHECKING
5+
if TYPE_CHECKING:
6+
from mytoncore import MyTonCore
7+
8+
69
class LiteserverModule(MtcModule):
710

811
description = 'For liteserver usage only without validator.'
@@ -11,8 +14,8 @@ class LiteserverModule(MtcModule):
1114
@classmethod
1215
def check_enable(cls, ton: "MyTonCore"):
1316
if ton.using_validator():
14-
raise Exception(f'Cannot enable liteserver mode while validator mode is enabled. '
15-
f'Use `disable_mode validator` first.')
17+
raise Exception('Cannot enable liteserver mode while validator mode is enabled. '
18+
'Use `disable_mode validator` first.')
1619

1720
def add_console_commands(self, console):
1821
...

modules/module.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
from mypylib.mypylib import MyPyClass
44

5+
from typing import TYPE_CHECKING
6+
if TYPE_CHECKING:
7+
from mytoncore import MyTonCore
8+
59

610
class MtcModule(ABC):
711

modules/nominator_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def do_deposit_to_pool(self, pool_addr, amount):
8888
bocPath = self.ton.local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc"
8989
fiftScript = self.ton.contractsDir + "nominator-pool/func/validator-deposit.fif"
9090
args = [fiftScript, bocPath]
91-
result = self.ton.fift.Run(args)
91+
self.ton.fift.Run(args)
9292
resultFilePath = self.ton.SignBocWithWallet(wallet, bocPath, pool_addr, amount)
9393
self.ton.SendFile(resultFilePath, wallet)
9494

0 commit comments

Comments
 (0)