Skip to content

Commit 23ba5c3

Browse files
author
Joel Collins
committed
Merge branch 'master' of https://github.com/labthings/python-labthings into master
2 parents 5a59ce7 + e1ebe1f commit 23ba5c3

File tree

25 files changed

+79
-133
lines changed

25 files changed

+79
-133
lines changed

.deepsource.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: Analyse with MyPy
3838
run: poetry run mypy src
3939

40+
- name: Lint with PyLint
41+
run: poetry run pylint src/labthings/
42+
4043
- name: Test with pytest
4144
run: poetry run pytest
4245

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Analyse with MyPy
4040
run: poetry run mypy src
4141

42+
- name: Lint with PyLint
43+
run: poetry run pylint src/labthings/
44+
4245
- name: Test with pytest
4346
run: poetry run pytest
4447

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sphinx-rtd-theme = "^0.5.0"
3535
mypy = "^0.790"
3636

3737
[tool.black]
38-
exclude = '(\.eggs|\.git|\.venv)'
38+
exclude = '(\.eggs|\.git|\.venv|node_modules/)'
3939

4040
[tool.isort]
4141
multi_line_output = 3
@@ -45,6 +45,13 @@ use_parentheses = true
4545
ensure_newline_before_comments = true
4646
line_length = 88
4747

48+
[tool.pylint.'MESSAGES CONTROL']
49+
disable = "fixme,C,R"
50+
max-line-length = 88
51+
52+
[tool.pylint.'MASTER']
53+
ignore = "marshmallow_jsonschema"
54+
4855
[build-system]
4956
requires = ["poetry-core>=1.0.0"]
5057
build-backend = "poetry.core.masonry.api"

src/labthings/actions/thread.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(
7070

7171
# copy_current_request_context allows threads to access flask current_app
7272
if has_request_context():
73-
logging.debug(f"Copying request context to {self._target}")
73+
logging.debug("Copying request context to %s", self._target)
7474
self._target = copy_current_request_context(self._target)
7575
try:
7676
self.input = request.json
@@ -298,7 +298,7 @@ def terminate(self, exception=ActionKilledException) -> bool:
298298
:raises which: should cause the thread to exit silently
299299
300300
"""
301-
_LOG.warning(f"Terminating thread {self}")
301+
_LOG.warning("Terminating thread %s", self)
302302
if not (self.is_alive() or self._is_thread_proc_running()):
303303
logging.debug("Cannot kill thread that is no longer running.")
304304
return False
@@ -336,7 +336,7 @@ def stop(self, timeout=None, exception=ActionKilledException) -> bool:
336336
self._status = "cancelled"
337337
return True
338338
# If the timeout tracker stopped before the thread died, kill it
339-
logging.warning(f"Forcefully terminating thread {self}")
339+
logging.warning("Forcefully terminating thread %s", self)
340340
return self.terminate(exception=exception)
341341

342342

@@ -346,7 +346,6 @@ def __init__(
346346
thread: ActionThread,
347347
dest: LockableDeque,
348348
level=logging.INFO,
349-
default_log_len: int = 100,
350349
):
351350
"""Set up a log handler that appends messages to a list.
352351
@@ -371,7 +370,7 @@ def __init__(
371370
self.dest = dest
372371
self.addFilter(self.check_thread)
373372

374-
def check_thread(self, record):
373+
def check_thread(self, *_):
375374
"""Determine if a thread matches the desired record
376375
377376
:param record:

src/labthings/apispec/plugins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ def init_attribute_functions(self, *args, **kwargs):
2525
OpenAPIConverter.init_attribute_functions(self, *args, **kwargs)
2626
self.attribute_functions.append(self.jsonschema_type_mapping)
2727

28-
def jsonschema_type_mapping(self, field, **kwargs):
28+
def jsonschema_type_mapping(self, field, **_):
2929
"""
3030
:param field:
3131
:param **kwargs:
3232
"""
3333
ret = {}
3434
if hasattr(field, "_jsonschema_type_mapping"):
35+
# pylint: disable=protected-access
3536
schema = field._jsonschema_type_mapping()
3637
ret.update(schema)
3738
return ret
@@ -246,6 +247,7 @@ def spec_for_event(cls, event):
246247
)
247248
return d
248249

250+
# pylint: disable=signature-differs
249251
def operation_helper(self, path, operations, **kwargs):
250252
"""Path helper that allows passing a Flask view function."""
251253
# rule = self._rule_for_view(interaction.dispatch_request, app=app)

src/labthings/default_views/events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from .. import fields
21
from ..schema import LogRecordSchema
32
from ..views import EventView
43

src/labthings/extensions.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from flask import url_for
99

10-
from typing import List, Dict, Callable
10+
from typing import List, Dict, Callable, Union
1111

1212
from .utilities import camel_to_snake, get_docstring, snake_to_spine
1313
from .views.builder import static_from
@@ -36,11 +36,11 @@ def __init__(
3636
self._meta: dict = {} # Extra metadata to add to the extension description
3737

3838
self._on_registers: List[
39-
Dict
39+
Union[Dict, Callable]
4040
] = [] # List of dictionaries of functions to run on registration
4141

4242
self._on_components: List[
43-
Dict
43+
Union[Dict, Callable]
4444
] = [] # List of dictionaries of functions to run as components are added
4545

4646
self._cls = str(self) # String description of extension instance
@@ -64,6 +64,14 @@ def views(self):
6464
""" """
6565
return self._views
6666

67+
@property
68+
def on_components(self):
69+
return self._on_components
70+
71+
@property
72+
def on_registers(self):
73+
return self._on_registers
74+
6775
def add_view(self, view_class, *urls, endpoint=None, **kwargs):
6876
"""
6977
@@ -217,7 +225,7 @@ def find_instances_in_module(module, class_to_find):
217225
for attribute in dir(module):
218226
if not attribute.startswith("__"):
219227
if isinstance(getattr(module, attribute), class_to_find):
220-
logging.debug(f"Found extension {getattr(module, attribute).name}")
228+
logging.debug("Found extension %s", getattr(module, attribute).name)
221229
objs.append(getattr(module, attribute))
222230
return objs
223231

@@ -235,17 +243,19 @@ def find_extensions_in_file(extension_path: str, module_name="extensions") -> li
235243
:rtype: list
236244
237245
"""
238-
logging.debug(f"Loading extensions from {extension_path}")
246+
logging.debug("Loading extensions from %s", extension_path)
239247

240248
spec = util.spec_from_file_location(module_name, extension_path)
241249
mod = util.module_from_spec(spec)
242250
sys.modules[spec.name] = mod
243251

244252
try:
245253
spec.loader.exec_module(mod) # type: ignore
246-
except Exception: # skipcq: PYL-W0703
254+
except Exception: # pylint: disable=broad-except
247255
logging.error(
248-
f"Exception in extension path {extension_path}: \n{traceback.format_exc()}"
256+
"Exception in extension path %s: \n%s",
257+
extension_path,
258+
traceback.format_exc(),
249259
)
250260
return []
251261
else:
@@ -270,7 +280,7 @@ def find_extensions(extension_dir: str, module_name="extensions") -> list:
270280
:rtype: list
271281
272282
"""
273-
logging.debug(f"Loading extensions from {extension_dir}")
283+
logging.debug("Loading extensions from %s", extension_dir)
274284

275285
extensions = []
276286
extension_paths = glob.glob(os.path.join(extension_dir, "*.py"))

src/labthings/find.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def current_labthing(app=None):
2727
# reach the Flask app object. Just using current_app returns
2828
# a wrapper, which breaks it's use in Task threads
2929
try:
30-
app = current_app._get_current_object() # skipcq: PYL-W0212
30+
app = current_app._get_current_object() # pylint: disable=protected-access
3131
except RuntimeError:
3232
return None
3333
ext = app.extensions.get(EXTENSION_NAME, None)

0 commit comments

Comments
 (0)