Skip to content

Commit 3ce0331

Browse files
krassowskijtpio
andauthored
Backport PR #15499: Adopt ruff format (#15564)
(cherry picked from commit 5ec3aa4) Co-authored-by: Jeremy Tuloup <[email protected]>
1 parent dd68b9c commit 3ce0331

File tree

13 files changed

+32
-44
lines changed

13 files changed

+32
-44
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@ repos:
3131
hooks:
3232
- id: check-github-workflows
3333

34-
- repo: https://github.com/psf/black
35-
rev: 23.10.1
36-
hooks:
37-
- id: black
38-
3934
# Check ruff version is aligned with the one in pyproject.toml
4035
- repo: https://github.com/astral-sh/ruff-pre-commit
41-
rev: v0.1.4
36+
rev: v0.1.6
4237
hooks:
4338
- id: ruff
4439
args: ["--fix"]
40+
- id: ruff-format
4541

4642
- repo: local
4743
hooks:

binder/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ dependencies:
3939
- requests-cache
4040
- virtualenv
4141
# dev
42-
- black-jupyter
4342
- bump2version
4443
- hatch
4544
- pre-commit

clean.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
for root, dnames, _ in os.walk(here):
1313
if "node_modules" in dnames:
1414
subprocess.check_call(
15-
["rmdir", "/s", "/q", "node_modules"], cwd=root, shell=True # noqa S602 S607
15+
["rmdir", "/s", "/q", "node_modules"], # noqa S602 S607
16+
cwd=root,
17+
shell=True, # noqa S602 S607
1618
)
1719
dnames.remove("node_modules")
1820

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def document_plugins_tokens_list(list_path: Path, output_path: Path) -> None:
394394

395395

396396
# Example configuration for intersphinx: refer to the Python standard library.
397-
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
397+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
398398

399399

400400
def setup(app):

docs/source/developer/contributing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ All source code is written in
9797
`TypeScript <https://www.typescriptlang.org/Handbook>`__. See the `Style
9898
Guide <https://github.com/jupyterlab/jupyterlab/wiki/TypeScript-Style-Guide>`__.
9999

100-
All non-python source code is formatted using `prettier <https://prettier.io>`__, and python source code is formatted using `black <https://github.com/psf/black>`__.
100+
All non-python source code is formatted using `prettier <https://prettier.io>`__, and python source code is formatted using `ruff <https://docs.astral.sh/ruff>`__.
101101
When code is modified and committed, all staged files will be
102102
automatically formatted using pre-commit git hooks (with help from
103103
`pre-commit <https://github.com/pre-commit/pre-commit>`__). The benefit of
104-
using a code formatters like ``prettier`` and ``black`` is that it removes the topic of
104+
using a code formatters like ``prettier`` and ``ruff`` is that it removes the topic of
105105
code style from the conversation when reviewing pull requests, thereby
106106
speeding up the review process.
107107

@@ -121,7 +121,7 @@ You can invoke the pre-commit hook by hand at any time with::
121121

122122
which should run any autoformatting on your code
123123
and tell you about any errors it couldn't fix automatically.
124-
You may also install `black integration <https://github.com/psf/black#editor-integration>`__
124+
You may also install `ruff integration <https://docs.astral.sh/ruff/integrations>`__
125125
into your text editor to format code automatically.
126126

127127
If you have already committed files before setting up the pre-commit

examples/example_check.py

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

2222
here = Path(__file__).parent.resolve()
2323
TEST_FILE = here / "example.spec.ts"
24-
REF_SNAPSHOT = Path(TEST_FILE.with_suffix('.ts-snapshots').name) / "example-linux.png"
24+
REF_SNAPSHOT = Path(TEST_FILE.with_suffix(".ts-snapshots").name) / "example-linux.png"
2525

2626

2727
def main():
@@ -96,7 +96,7 @@ async def run_browser(url):
9696

9797
current_env = os.environ.copy()
9898
current_env["BASE_URL"] = url
99-
current_env["TEST_SNAPSHOT"] = '1' if has_snapshot else '0'
99+
current_env["TEST_SNAPSHOT"] = "1" if has_snapshot else "0"
100100
try:
101101
await run_async_process(["npx", "playwright", "test"], env=current_env, cwd=str(target))
102102
finally:

jupyterlab/commands.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,9 @@ def _yarn_config(logger):
19941994

19951995
try:
19961996
output_binary = subprocess.check_output(
1997-
[node, YARN_PATH, "config", "--json"], stderr=subprocess.PIPE, cwd=HERE # noqa S603
1997+
[node, YARN_PATH, "config", "--json"], # noqa S603
1998+
stderr=subprocess.PIPE,
1999+
cwd=HERE,
19982000
)
19992001
output = output_binary.decode("utf-8")
20002002
lines = iter(output.splitlines())
@@ -2328,7 +2330,7 @@ def _log_multiple_compat_errors(logger, errors_map):
23282330
[
23292331
"\n The following extensions are outdated:",
23302332
*outdated,
2331-
'\n Consider checking if an update is available for these packages.\n',
2333+
"\n Consider checking if an update is available for these packages.\n",
23322334
]
23332335
)
23342336
)

jupyterlab/federated_labextensions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ def _get_labextension_metadata(module): # noqa
442442
try:
443443
package = (
444444
subprocess.check_output(
445-
[sys.executable, "setup.py", "--name"], cwd=mod_path # noqa S603
445+
[sys.executable, "setup.py", "--name"], # noqa S603
446+
cwd=mod_path,
446447
)
447448
.decode("utf8")
448449
.strip()

jupyterlab/handlers/announcements.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,18 @@ def get_xml_text(attr: str, default: Optional[str] = None) -> str:
238238
return default
239239
else:
240240
error_m = (
241-
f'atom feed entry does not contain a required attribute: {attr}'
241+
f"atom feed entry does not contain a required attribute: {attr}"
242242
)
243243
raise KeyError(error_m)
244244

245245
entry_title = get_xml_text("title")
246246
entry_id = get_xml_text("id")
247247
entry_updated = get_xml_text("updated")
248248
entry_published = get_xml_text("published", entry_updated)
249-
entry_summary = get_xml_text("summary", default='')
249+
entry_summary = get_xml_text("summary", default="")
250250
links = node.findall("atom:link", xml_namespaces)
251251
if len(links) > 1:
252-
alternate = list(filter(lambda elem: elem.get('rel') == 'alternate', links))
252+
alternate = list(filter(lambda elem: elem.get("rel") == "alternate", links))
253253
link_node = alternate[0] if alternate else links[0]
254254
else:
255255
link_node = links[0] if len(links) == 1 else None

jupyterlab/tests/test_extensions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ async def mock_pkg_metadata(n, l, b): # noqa
239239
"nbformat",
240240
"packaging",
241241
"pexpect",
242-
"black ; extra == 'dev'",
243242
"coverage ; extra == 'dev'",
244243
"jupyter-packaging (~=0.7.9) ; extra == 'dev'",
245244
"jupyterlab (~=3.0) ; extra == 'dev'",
@@ -248,7 +247,6 @@ async def mock_pkg_metadata(n, l, b): # noqa
248247
"pytest-asyncio ; extra == 'dev'",
249248
"pytest-cov ; extra == 'dev'",
250249
"pytest-tornasync ; extra == 'dev'",
251-
"black ; extra == 'tests'",
252250
"coverage ; extra == 'tests'",
253251
"jupyter-packaging (~=0.7.9) ; extra == 'tests'",
254252
"jupyterlab (~=3.0) ; extra == 'tests'",

0 commit comments

Comments
 (0)