Skip to content

Commit ba7aaf4

Browse files
committed
Fix pre-commit issues, get removesuffix from str
Signed-off-by: Fabrice Normandin <[email protected]>
1 parent b7775b2 commit ba7aaf4

File tree

8 files changed

+9
-27
lines changed

8 files changed

+9
-27
lines changed

milatools/cli/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import asyncio
44
import shutil
5+
from collections.abc import Awaitable
56
from logging import getLogger as get_logger
67
from pathlib import PurePosixPath
7-
from typing import Awaitable
88

99
from milatools.cli import console
1010
from milatools.cli.init_command import DRAC_CLUSTERS

milatools/cli/utils.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,6 @@ def stripped_lines_of(text: str) -> list[str]:
366366
return [line.strip() for line in text.splitlines()]
367367

368368

369-
if sys.version_info < (3, 9):
370-
371-
def removesuffix(s: str, suffix: str) -> str:
372-
"""Backport of `str.removesuffix` for Python<3.9."""
373-
if s.endswith(suffix):
374-
return s[: -len(suffix)]
375-
else:
376-
return s
377-
else:
378-
removesuffix = str.removesuffix
379-
380-
381369
class AllocationFlagsAction(argparse._StoreAction):
382370
def __call__(
383371
self,

milatools/utils/parallel_progress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import asyncio
44
import functools
5+
from collections.abc import Coroutine
56
from logging import getLogger as get_logger
67
from typing import (
7-
Coroutine,
88
Protocol,
99
TypedDict,
1010
TypeVar,

milatools/utils/vscode_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import subprocess
88
import sys
99
import textwrap
10+
from collections.abc import Sequence
1011
from logging import getLogger as get_logger
1112
from pathlib import Path
12-
from typing import Sequence
1313

1414
from milatools.cli.utils import (
1515
CommandNotFoundError,

tests/cli/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pytest_regressions.file_regression import FileRegressionFixture
1818
from typing_extensions import ParamSpec
1919

20-
from milatools.cli.utils import SSH_CACHE_DIR, SSH_CONFIG_FILE, removesuffix
20+
from milatools.cli.utils import SSH_CACHE_DIR, SSH_CONFIG_FILE
2121
from milatools.utils.remote_v2 import RemoteV2, get_controlpath_for
2222

2323
if typing.TYPE_CHECKING:
@@ -208,4 +208,4 @@ def _lambda_to_str(lambda_: Callable) -> str:
208208
# lambda x: x + 1,
209209
# ]
210210
# a trailing comma is returned by `inspect.getsource`, which we want to remove.
211-
return removesuffix(lambda_body, ",")
211+
return lambda_body.removesuffix(",")

tests/integration/test_code.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
CommandNotFoundError,
2121
MilatoolsUserError,
2222
get_hostname_to_use_for_compute_node,
23-
removesuffix,
2423
)
2524
from milatools.utils import disk_quota
2625
from milatools.utils.compute_node import (
@@ -324,7 +323,7 @@ async def test_code_with_existing_job(
324323
hostname = existing_job.hostname
325324
# We actually need to pass `cn-a001` (node name) as --node, not the entire
326325
# hostname!
327-
node = removesuffix(hostname, ".server.mila.quebec")
326+
node = hostname.removesuffix(".server.mila.quebec")
328327

329328
if not use_v1:
330329

@@ -368,7 +367,7 @@ def _mock_close():
368367
hostname = existing_job.hostname
369368
# We actually need to pass `cn-a001` (node name) as --node, not the entire
370369
# hostname!
371-
node = removesuffix(hostname, ".server.mila.quebec")
370+
node = hostname.removesuffix(".server.mila.quebec")
372371

373372
code_v1(
374373
path=path,

tests/utils/test_compute_node.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import pytest
1313
import pytest_asyncio
1414

15-
from milatools.cli.utils import removesuffix
1615
from milatools.utils.compute_node import (
1716
ComputeNode,
1817
JobNotRunningError,
@@ -251,10 +250,7 @@ async def test_connect_with_node_name(self, runner: ComputeNode):
251250
# squeue expects the node name, so we have to truncate it manually for now.
252251
login_node = runner.login_node
253252
node_hostname = runner.hostname
254-
if node_hostname.endswith(".server.mila.quebec"):
255-
node_name = removesuffix(node_hostname, ".server.mila.quebec")
256-
else:
257-
node_name = node_hostname
253+
node_name = node_hostname.removesuffix(".server.mila.quebec")
258254

259255
# Connect with the node name:
260256
compute_node_with_node_name = await ComputeNode.connect(

tests/utils/test_parallel_progress.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pytest_regressions.file_regression import FileRegressionFixture
1111

1212
from milatools.cli import console
13-
from milatools.cli.utils import removesuffix
1413
from milatools.utils.parallel_progress import (
1514
AsyncTaskFn,
1615
ReportProgressFn,
@@ -71,7 +70,7 @@ async def test_async_progress_bar(file_regression: FileRegressionFixture):
7170
all_output = capture.get()
7271
# Remove the elapsed column since its values can vary a little bit between runs.
7372
all_output_without_elapsed = "\n".join(
74-
removesuffix(line, last_part).rstrip()
73+
line.removesuffix(last_part).rstrip()
7574
if (parts := line.split()) and (last_part := parts[-1]).count(":") == 2
7675
else line
7776
for line in all_output.splitlines()

0 commit comments

Comments
 (0)