Skip to content

Commit be08aa8

Browse files
Replace pylint disable comments with ruff noqa and remove others
Co-authored-by: AlexeyKozhevin <[email protected]>
1 parent 1d5331e commit be08aa8

File tree

10 files changed

+17
-30
lines changed

10 files changed

+17
-30
lines changed

nbtools/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" Init file. """
2-
#pylint: disable=wildcard-import
32
from .core import *
43
from .exec_notebook import exec_notebook, run_notebook
54
from .pylint_notebook import pylint_notebook

nbtools/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" Core utility functions to work with Jupyter Notebooks. """
2-
#pylint: disable=import-outside-toplevel
32
import os
43
import sys
54
import re
@@ -34,7 +33,6 @@ def get_notebook_path():
3433
3534
If run outside Jupyter notebook, returns None.
3635
"""
37-
#pylint: disable=missing-timeout
3836
if not in_notebook():
3937
return None
4038

@@ -74,7 +72,7 @@ def get_notebook_name():
7472

7573
def notebook_to_script(path_script, path_notebook=None, ignore_markdown=True, return_info=False):
7674
""" Convert a notebook to a script. """
77-
import nbformat #pylint: disable=import-outside-toplevel
75+
import nbformat
7876
path_notebook = path_notebook or get_notebook_path()
7977
if path_notebook is None:
8078
raise ValueError('Provide path to Jupyter Notebook or run `notebook_to_script` inside of it!')
@@ -267,7 +265,6 @@ def set_gpus(n=1, min_free_memory=0.9, max_processes=2, verbose=False, raise_err
267265
devices : list
268266
Indices of selected and reserved GPUs.
269267
"""
270-
#pylint: disable=consider-iterating-dictionary
271268
if 'CUDA_VISIBLE_DEVICES' in os.environ.keys():
272269
str_devices = os.environ["CUDA_VISIBLE_DEVICES"]
273270
warnings.warn(f'`CUDA_VISIBLE_DEVICES` is already set to "{str_devices}"!')

nbtools/exec_notebook.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" Functions for running Jupyter Notebooks programmatically."""
2-
#pylint: disable=import-outside-toplevel
32
import os
43
import time
54
import json
@@ -10,7 +9,7 @@
109
import psutil
1110

1211

13-
TMP_DIR = '/tmp/nbtools_exec_notebook'
12+
TMP_DIR = '/tmp/nbtools_exec_notebook' # noqa: S108
1413
os.makedirs(TMP_DIR, exist_ok=True)
1514

1615

@@ -19,7 +18,6 @@ def run_in_process(func):
1918
""" Decorator to run the ``func`` in a separate process for terminating all related processes properly. """
2019
@wraps(func)
2120
def _wrapper(*args, **kwargs):
22-
# pylint: disable=broad-exception-caught, broad-exception-raised
2321
_output_queue = Queue()
2422
kwargs = {**kwargs, '_output_queue': _output_queue}
2523

@@ -39,7 +37,7 @@ def _wrapper(*args, **kwargs):
3937

4038
output = _output_queue.get()
4139
process.join()
42-
except (KeyboardInterrupt, Exception) as e:
40+
except (KeyboardInterrupt, Exception) as e: # noqa: BLE001
4341
output = {'failed': True, 'traceback': e}
4442

4543
# Terminate all relevant processes when something went wrong, e.g. Keyboard Interrupt
@@ -245,7 +243,6 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
245243
- ``'notebook'`` : :class:`nbformat.notebooknode.NotebookNode`, optional
246244
Executed notebook object. Note that this output is provided only if ``return_notebook`` is ``True``.
247245
"""
248-
# pylint: disable=bare-except, lost-exception, return-in-finally
249246
import nbformat
250247
from jupyter_client.manager import KernelManager
251248
from nbconvert.preprocessors import ExecutePreprocessor
@@ -321,7 +318,7 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
321318
exec_failed = False
322319
try:
323320
executor.preprocess(notebook, {'metadata': {'path': working_dir}}, km=kernel_manager)
324-
except:
321+
except: # noqa: E722
325322
exec_failed = True
326323

327324
# Save notebook outputs in the shelve db
@@ -359,7 +356,7 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
359356
# Re-raise exception if needed
360357
if raise_exception:
361358
_output_queue.put(exec_res)
362-
return None
359+
return None # noqa: RET501
363360
else:
364361
exec_res = {'failed': failed, 'failed cell number': None, 'traceback': ''}
365362

@@ -397,7 +394,7 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
397394
exec_res['notebook'] = notebook
398395

399396
_output_queue.put(exec_res) # return for parent process
400-
return None
397+
return None # noqa: RET501
401398

402399
# Functions for database operations cells masking
403400
def _display_inputs_reading(notebook, pos):

nbtools/nbstat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" NBstat module: monitoring running Python processes and Notebooks. """
2-
#pylint: disable=wildcard-import
32
from .resource import Resource
43
from .resource_entry import ResourceEntry
54
from .resource_table import ResourceTable

nbtools/nbstat/cli.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
""" Command line interface of `nbstat`.
22
Also provides `nbwatch`, `devicestat` and `devicewatch` functions.
33
"""
4-
#pylint: disable=redefined-outer-name, too-many-nested-blocks
54
import sys
65
import traceback
76
from inspect import cleandoc
@@ -21,9 +20,9 @@ def main(name, interval=None):
2120
""" Run command `name`. If `interval` is given, continuously output it to a terminal in fullscreen mode. """
2221
# Attach SIGPIPE handler to properly handle broken pipe
2322
try: # sigpipe not available under windows. just ignore in this case
24-
import signal # pylint: disable=import-outside-toplevel
23+
import signal # noqa: E402
2524
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
26-
except Exception: # pylint: disable=broad-except
25+
except Exception: # noqa: BLE001, S110
2726
pass
2827

2928
# Make parameters for requested view
@@ -54,15 +53,14 @@ def output_once(inspector, name, formatter, view_args):
5453
try:
5554
view = inspector.get_view(name=name, formatter=formatter, **view_args)
5655
print(view)
57-
except Exception as e: # pylint: disable=broad-except
56+
except Exception as e:
5857
_ = e
5958
print('Error on getting system information!' + str(e))
6059
raise e
6160

6261
def output_looped(inspector, name, formatter, view_args,
6362
other_name, other_formatter, other_view_args, interval=0.5):
6463
""" Output visualization to a stdout once each `interval` seconds in a fullscreen mode. """
65-
#pylint: disable=too-many-statements
6664
terminal = Terminal()
6765

6866
initial_view_args = dict(view_args)
@@ -194,7 +192,7 @@ def output_looped(inspector, name, formatter, view_args,
194192
else:
195193
print(f'\nUnrecognized key={inkey}, code={inkey.code}.')
196194

197-
except Exception as e: # pylint: disable=broad-except
195+
except Exception as e: # noqa: BLE001
198196
sys.stderr.write(traceback.format_exc())
199197
sys.stderr.write('Error on getting system information!')
200198
sys.stderr.write(str(e))

nbtools/nbstat/resource_entry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def to_format_data(self, resource, terminal, **kwargs):
3939
kwargs : dict
4040
Other parameters for string creation like memory format, width, etc.
4141
"""
42-
#pylint: disable=too-many-statements
4342
resource = Resource.parse_alias(resource)
4443
default_string = '-'
4544
style, string = None, None

nbtools/nbstat/resource_inspector.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
KERNEL_ID_SEARCHER = re.compile('kernel-(.*).json').search
2323
VSCODE_KEY_SEARCHER = re.compile('key=b"(.*)"').search
2424
SCRIPT_NAME_SEARCHER = re.compile('python.* (.*).py').search
25-
RUN_NOTEBOOK_PATH_SEARCHER = re.compile('/tmp/.*.json.*--HistoryManager.hist_file=:memory:.*').search
25+
RUN_NOTEBOOK_PATH_SEARCHER = re.compile('/tmp/.*.json.*--HistoryManager.hist_file=:memory:.*').search # noqa: S108
2626

2727

2828
class ResourceInspector:
@@ -159,7 +159,6 @@ def get_notebook_table(self, formatter=None):
159159
160160
TODO: once VSCode has stable standard and doc for ipykernel launches, add its parsing here.
161161
"""
162-
#pylint: disable=import-outside-toplevel, missing-timeout
163162
servers = []
164163
try:
165164
from notebook.notebookapp import list_running_servers as list_running_servers_v2
@@ -628,7 +627,7 @@ def make_terminal(self, force_styling, separator):
628627
""" Create terminal instance. """
629628
terminal = Terminal(kind=os.getenv('TERM'), force_styling=force_styling if force_styling else None)
630629
terminal.separator_symbol = separator
631-
terminal._normal = '\x1b[0;10m' # pylint: disable=protected-access
630+
terminal._normal = '\x1b[0;10m' # noqa: SLF001
632631

633632
# Change some methods to a faster versions
634633
# TODO: better measurements and tests for the same outputs

nbtools/nbstat/resource_table.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ResourceTable:
3232
# TODO: can require `index` and/or `columns` at table creation, should we want so, for consistency
3333
# TODO: can create a `PandasResourceTable` with the same API, but `pandas.DataFrame` under the hood
3434
"""
35-
#pylint: disable=self-cls-assignment
3635
def __init__(self, data=None):
3736
self._data = [] if data is None else [ResourceEntry(entry) for entry in data]
3837

@@ -468,7 +467,7 @@ def format(self, terminal, formatter, hide_similar=True,
468467
if hide_similar and hidable and i > 0:
469468
style, string = '', ''
470469

471-
if False and i: # pylint: disable=condition-evals-to-constant
470+
if False and i:
472471
# TODO: aggregate info by using `aggregate` method
473472
# for a given resource and create a ResourceEntry out of it to make style/string
474473
remaining_table = subtable[1:]
@@ -536,5 +535,5 @@ def format(self, terminal, formatter, hide_similar=True,
536535
# Pandas compatibility
537536
def to_pd(self):
538537
""" Convert the table to a `pandas.DataFrame`. """
539-
import pandas as pd #pylint: disable=import-outside-toplevel
538+
import pandas as pd
540539
return pd.DataFrame(self.data)

nbtools/nbstat/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" Utility functions. """
2-
#pylint: disable=redefined-builtin
32
import re
43
import platform
54
import linecache
@@ -25,7 +24,7 @@ def pid_to_name_linux(pid):
2524
try:
2625
line = linecache.getline(f'/proc/{pid}/status', 1)
2726
name = line.strip().split()[1]
28-
except Exception: #pylint: disable=broad-except
27+
except Exception: # noqa: BLE001
2928
name = ''
3029
return name
3130

@@ -42,7 +41,7 @@ def pid_to_ngid_linux(pid):
4241
line = linecache.getline(f'/proc/{pid}/status', 5)
4342
ngid = line.strip().split()[1]
4443
ngid = int(ngid)
45-
except Exception: #pylint: disable=broad-except
44+
except Exception: # noqa: BLE001
4645
ngid = pid
4746
return ngid or pid
4847

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ignore = [
3636
"S101",
3737
"S301",
3838
"S102",
39+
"S113", # requests-call-without-timeout
3940
]
4041

4142
[lint.per-file-ignores]

0 commit comments

Comments
 (0)