Skip to content

Commit a88173e

Browse files
authored
Add flake8 and handle warnings in tests (#259)
1 parent 1b0e257 commit a88173e

21 files changed

+63
-47
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ repos:
4949
- id: doc8
5050
args: [--max-line-length=200]
5151

52-
# - repo: https://github.com/pycqa/flake8
53-
# rev: 4.0.1
54-
# hooks:
55-
# - id: flake8
56-
# additional_dependencies:
57-
# [
58-
# "flake8-bugbear==20.1.4",
59-
# "flake8-logging-format==0.6.0",
60-
# "flake8-implicit-str-concat==0.2.0",
61-
# ]
52+
- repo: https://github.com/pycqa/flake8
53+
rev: 4.0.1
54+
hooks:
55+
- id: flake8
56+
additional_dependencies:
57+
[
58+
"flake8-bugbear==20.1.4",
59+
"flake8-logging-format==0.6.0",
60+
"flake8-implicit-str-concat==0.2.0",
61+
]
6262

6363
- repo: https://github.com/sirosen/check-jsonschema
6464
rev: 0.14.1

jupyterlab_server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .app import LabServerApp
66
from .handlers import LabConfig, LabHandler, add_handlers
77
from .licenses_app import LicensesApp
8-
from .spec import get_openapi_spec, get_openapi_spec_dict
8+
from .spec import get_openapi_spec, get_openapi_spec_dict # noqa
99
from .translation_utils import translator
1010
from .workspaces_app import WorkspaceExportApp, WorkspaceImportApp, WorkspaceListApp
1111
from .workspaces_handler import WORKSPACE_EXTENSION, slugify

jupyterlab_server/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def app_namespace(self):
2727
# Should your extension expose other server extensions when launched directly?
2828
load_other_extensions = True
2929

30-
app_version = Unicode("", help="The version of the application.", default=__version__)
30+
app_version = Unicode("", help="The version of the application.").tag(default=__version__)
3131

3232
blacklist_uris = Unicode(
3333
"", config=True, help="Deprecated, use `LabServerApp.blocked_extensions_uris`"

jupyterlab_server/config.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ def get_page_config(labextensions_path, app_settings_dir=None, logger=None):
113113
# Ensure there is a disabled key
114114
page_config.setdefault(disabled_key, {})
115115

116-
for (ext, ext_data) in federated_exts.items():
117-
if not "_build" in ext_data["jupyterlab"]:
118-
logger.warn("%s is not a valid extension" % ext_data["name"])
116+
for (_, ext_data) in federated_exts.items():
117+
if "_build" not in ext_data["jupyterlab"]:
118+
logger.warning("%s is not a valid extension" % ext_data["name"])
119119
continue
120120
extbuild = ext_data["jupyterlab"]["_build"]
121121
extension = {"name": ext_data["name"], "load": extbuild["load"]}
@@ -152,7 +152,7 @@ def get_page_config(labextensions_path, app_settings_dir=None, logger=None):
152152
disabled_by_extensions = {}
153153
for name in sorted(disabled_by_extensions_all):
154154
# skip if the extension itself is disabled by other config
155-
if page_config[disabled_key].get(name) == True:
155+
if page_config[disabled_key].get(name) is True:
156156
continue
157157

158158
disabled_list = disabled_by_extensions_all[name]
@@ -217,7 +217,7 @@ class LabConfig(HasTraits):
217217
settings_url = Unicode(help="The url path of the settings handler.").tag(config=True)
218218

219219
user_settings_dir = Unicode(
220-
"", help=("The optional location of the user " "settings directory.")
220+
"", help=("The optional location of the user settings directory.")
221221
).tag(config=True)
222222

223223
schemas_dir = Unicode(
@@ -263,7 +263,7 @@ class LabConfig(HasTraits):
263263

264264
cache_files = Bool(
265265
True,
266-
help=("Whether to cache files on the server. " "This should be `True` except in dev mode."),
266+
help=("Whether to cache files on the server. This should be `True` except in dev mode."),
267267
).tag(config=True)
268268

269269
notebook_starts_kernel = Bool(
@@ -314,10 +314,6 @@ def _default_tree_url(self):
314314
def _default_translations_api_url(self):
315315
return ujoin(self.app_url, "api", "translations/")
316316

317-
@default("tree_url")
318-
def _default_tree_url(self):
319-
return ujoin(self.app_url, "tree/")
320-
321317

322318
def _get_config_manager(level):
323319
"""Get the location of config files for the current context

jupyterlab_server/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def add_handlers(handlers, extension_app):
224224
handlers.append((setting_path, SettingsHandler, settings_config))
225225

226226
# Handle translations.
227-
## Translations requires settings as the locale source of truth is stored in it
227+
# Translations requires settings as the locale source of truth is stored in it
228228
if extension_app.translations_api_url:
229229
# Handle requests for the list of language packs available.
230230
# Make slash optional.

jupyterlab_server/licenses_app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def initialize(self, *args, **kwargs):
7676

7777
def init_licenses_manager(self):
7878
self.licenses_manager = LicensesManager(
79-
labextensions_path=sum([self.labextensions_path + self.extra_labextensions_path], []),
8079
parent=self,
8180
)
8281

jupyterlab_server/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self, cmd, logger=None, cwd=None, kill_event=None, env=None, quiet=
9595
self.logger = logger = logger or logging.getLogger("jupyterlab")
9696
self._last_line = ""
9797
if not quiet:
98-
self.logger.info("> " + list2cmdline(cmd))
98+
self.logger.info(f"> {list2cmdline(cmd)}")
9999
self.cmd = cmd
100100

101101
kwargs = {}

jupyterlab_server/pytest_plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pytest
88

99
from jupyterlab_server import LabServerApp
10-
from jupyterlab_server.app import LabServerApp
1110

1211
pytest_plugins = ["jupyter_server.pytest_plugin"]
1312

jupyterlab_server/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from jupyter_server import _tz as tz
1+
from jupyter_server import _tz as tz # noqa
22
from jupyter_server.base.handlers import ( # noqa
33
APIHandler,
44
FileFindHandler,

jupyterlab_server/settings_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tornado import web
1313

1414
from .settings_utils import SchemaHandler, get_settings, save_settings
15-
from .translation_utils import DEFAULT_LOCALE, translator
15+
from .translation_utils import translator
1616

1717

1818
class SettingsHandler(ExtensionHandlerMixin, ExtensionHandlerJinjaMixin, SchemaHandler):
@@ -45,7 +45,7 @@ def get(self, schema_name=""):
4545
# Print all warnings.
4646
for w in warnings:
4747
if w:
48-
self.log.warn(w)
48+
self.log.warning(w)
4949

5050
return self.finish(json.dumps(result))
5151

@@ -78,7 +78,7 @@ def put(self, schema_name):
7878
)
7979
except json.decoder.JSONDecodeError as e:
8080
raise web.HTTPError(400, invalid_json_error % str(e))
81-
except (KeyError, TypeError) as e:
81+
except (KeyError, TypeError):
8282
raise web.HTTPError(400, invalid_payload_format_error)
8383
except ValidationError as e:
8484
raise web.HTTPError(400, validation_error % str(e))

0 commit comments

Comments
 (0)