Skip to content

Commit 7525a87

Browse files
pylint
1 parent 32d578d commit 7525a87

16 files changed

Lines changed: 73 additions & 56 deletions

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
pylint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: '3.11'
16+
17+
- name: Install dev requirements
18+
run: pip install -r requirements-dev.txt
19+
20+
- name: Run pylint
21+
run: pylint main.py core/ stratums/ utils/ scripts/

.pylintrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[MAIN]
2+
py-version = 3.11
3+
4+
[MESSAGES CONTROL]
5+
disable =
6+
missing-module-docstring,
7+
missing-class-docstring,
8+
missing-function-docstring,
9+
broad-exception-caught,
10+
logging-fstring-interpolation,
11+
duplicate-code,
12+
cyclic-import,
13+
too-few-public-methods,
14+
too-many-instance-attributes,
15+
too-many-arguments,
16+
too-many-positional-arguments,
17+
too-many-nested-blocks
18+
19+
[FORMAT]
20+
max-line-length = 120
21+
22+
[BASIC]
23+
good-names = i,j,k,_

core/pool.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def __init__(self, algo: str, hostname: str, port: int,
2222
self.algo = str(algo)
2323
self.hostname = str(hostname)
2424
self.port = int(port)
25-
self.__clients = dict()
25+
self.__clients = {}
2626
self.__socket = None
2727
self.alive = False
28-
self.threadAccept = None
28+
self.thread_accept = None
2929
self.stratum = None
3030

3131
if algo == ALGORITHM.SMART_MINING:
@@ -57,8 +57,8 @@ def bind(self) -> None:
5757
self.__socket.bind((self.hostname, self.port))
5858
self.__socket.listen(1)
5959

60-
self.threadAccept = threading.Thread(target=self.__accept, args=())
61-
self.threadAccept.start()
60+
self.thread_accept = threading.Thread(target=self.__accept, args=())
61+
self.thread_accept.start()
6262

6363
def __accept(self) -> None:
6464
try:
@@ -74,8 +74,8 @@ def __accept(self) -> None:
7474
args=(addr[1], sock))
7575
thread_loop.start()
7676

77-
self.threadAccept = threading.Thread(target=self.__accept, args=())
78-
self.threadAccept.start()
77+
self.thread_accept = threading.Thread(target=self.__accept, args=())
78+
self.thread_accept.start()
7979

8080
def remove_client(self, by: str, addr: int) -> None:
8181
logging.warning(f'Remove client {addr} - {by}')
@@ -112,11 +112,9 @@ def __on_client(self, addr, sock) -> None:
112112
self.stratum.on_message(sock, data)
113113
except TimeoutError:
114114
pass
115-
except socket.timeout:
116-
pass
117115
except ConnectionAbortedError:
118116
self.remove_client('ConnectionAbortedError', addr)
119117
return
120-
except Exception as e:
121-
self.remove_client(f'Exception[{e}]', addr)
118+
except Exception as exc:
119+
self.remove_client(f'Exception[{exc}]', addr)
122120
return

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from core import Pool
88

99

10-
log_level = logging.DEBUG
10+
LOG_LEVEL = logging.DEBUG
1111
logging.basicConfig(
1212
format='[%(levelname)s][%(asctime)s]: %(message)s',
1313
datefmt='%m/%d/%Y %I:%M:%S %p',
1414
encoding='utf-8',
15-
level=log_level)
15+
level=LOG_LEVEL)
1616

1717

1818
parser = argparse.ArgumentParser(description='')

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pylint

scripts/test_workflow_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def wait_for_server(timeout: int) -> None:
1313
deadline = time.monotonic() + timeout
1414
while time.monotonic() < deadline:
1515
try:
16-
s = socket.create_connection((HOST, PORT), timeout=1)
17-
s.close()
16+
sock = socket.create_connection((HOST, PORT), timeout=1)
17+
sock.close()
1818
return
1919
except OSError:
2020
time.sleep(0.2)

stratums/autolykos_v2.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66

77
class StratumAutolykosv2(Stratum):
88

9-
def __init__(self):
10-
super(StratumAutolykosv2, self).__init__()
11-
129
def on_message(self, sock, data: dict):
1310
if 'method' in data:
1411
self.__on_method(sock, data)
1512
else:
1613
self.__on_response(sock, data)
1714

18-
def __on_response(self, sock, data: dict):
15+
def __on_response(self, _sock, data: dict):
1916
logging.info(f'response => {data}')
2017

2118
def __on_method(self, sock, data: dict):
@@ -36,7 +33,7 @@ def __on_mining_subscribe(self, sock, request_id: Union[int, str]):
3633
size = 6
3734

3835
key_id = f'"id":{request_id}'
39-
if type(request_id) is str:
36+
if isinstance(request_id, str):
4037
key_id = f'"id":"{request_id}"'
4138

4239
body = '{' \
@@ -48,7 +45,7 @@ def __on_mining_subscribe(self, sock, request_id: Union[int, str]):
4845

4946
def __on_mining_authorize(self, sock, request_id: Union[int, str]):
5047
key_id = f'"id":{request_id}'
51-
if type(request_id) is str:
48+
if isinstance(request_id, str):
5249
key_id = f'"id":"{request_id}"'
5350

5451
body = '{' \
@@ -84,7 +81,7 @@ def __on_mining_authorize(self, sock, request_id: Union[int, str]):
8481

8582
def __on_mining_submit(self, sock, request_id: Union[int, str], params: list):
8683
key_id = request_id
87-
if type(request_id) is str:
84+
if isinstance(request_id, str):
8885
key_id = f'"{request_id}"'
8986

9087
logging.info(f'Nonce: {params}')

stratums/blake3.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1+
# pylint: disable=line-too-long
12
import logging
23

34
from stratums import Stratum
45

56

67
class StratumBlake3(Stratum):
78

8-
def __init__(self):
9-
super(StratumBlake3, self).__init__()
10-
119
def on_message(self, sock, data: dict):
1210
if 'method' in data:
1311
self.__on_method(sock, data)
1412
else:
1513
self.__on_response(sock, data)
1614

17-
def __on_response(self, sock, data: dict):
15+
def __on_response(self, _sock, data: dict):
1816
logging.info(f'response => {data}')
1917

2018
def __on_method(self, sock, data: dict):

stratums/ethash.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
class StratumEthash(Stratum):
77

8-
def __init__(self):
9-
super(StratumEthash, self).__init__()
10-
118
def on_message(self, sock, data: dict):
129
if 'method' in data:
1310
self.__on_method(sock, data)
1411
else:
1512
self.__on_response(sock, data)
1613

17-
def __on_response(self, sock, data: dict):
14+
def __on_response(self, _sock, data: dict):
1815
logging.info(f'response => {data}')
1916

2017
def __on_method(self, sock, data: dict):

stratums/kawpow.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
class StratumKawpow(Stratum):
77

8-
def __init__(self):
9-
super(StratumKawpow, self).__init__()
10-
118
def on_message(self, sock, data: dict):
129
if 'method' in data:
1310
self.__on_method(sock, data)
1411
else:
1512
self.__on_response(sock, data)
1613

17-
def __on_response(self, sock, data: dict):
14+
def __on_response(self, _sock, data: dict):
1815
logging.info(f'response => {data}')
1916

2017
def __on_method(self, sock, data: dict):

0 commit comments

Comments
 (0)