Skip to content

Commit 6282b08

Browse files
refactor(core): remove unused git isolation code (#2876)
1 parent be7e138 commit 6282b08

File tree

4 files changed

+36
-81
lines changed

4 files changed

+36
-81
lines changed

renku/command/git.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from renku.core import errors
2525

2626
GIT_KEY = "renku.git"
27-
GIT_ISOLATION = "renku.worktree"
2827

2928

3029
def set_git_home(value: Path):
@@ -57,25 +56,3 @@ def get_git_home(path=".") -> Path:
5756
return Repository(path, search_parent_directories=True).path
5857
except errors.GitError:
5958
raise ValueError(f"Cannot find a git repository at '{path}'")
60-
61-
62-
def set_git_isolation(value):
63-
"""Set Git isolation.
64-
65-
Args:
66-
value: Git isolation level.
67-
68-
Returns:
69-
The value passed.
70-
"""
71-
ctx = click.get_current_context()
72-
ctx.meta[GIT_ISOLATION] = value
73-
74-
return value
75-
76-
77-
def get_git_isolation():
78-
"""Get Git isolation from the current context."""
79-
ctx = click.get_current_context(silent=True)
80-
if ctx and GIT_ISOLATION in ctx.meta:
81-
return ctx.meta[GIT_ISOLATION]

renku/command/options.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@
1919

2020
import click
2121

22-
from .git import set_git_isolation
23-
24-
option_isolation = click.option(
25-
"--isolation",
26-
is_flag=True,
27-
default=False,
28-
callback=lambda ctx, param, value: set_git_isolation(value),
29-
help="Set up the isolation for invoking of the given command.",
30-
)
31-
32-
3322
option_external_storage_requested = click.option(
3423
"external_storage_requested",
3524
"--external-storage/--no-external-storage",

renku/ui/cli/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@
254254

255255
import click
256256

257-
from renku.command.options import option_isolation
258257
from renku.ui.cli.utils.callback import ClickCallback
259258

260259

@@ -276,7 +275,7 @@
276275
callback=lambda _, __, values: [int(value) % 256 for value in values],
277276
help="Allowed command exit-code.",
278277
)
279-
@option_isolation
278+
@click.option("--isolation", is_flag=True, default=False, help="Invoke the given command in isolation.")
280279
@click.argument("command_line", nargs=-1, required=True, type=click.UNPROCESSED)
281280
@click.option("--verbose", is_flag=True, default=False, help="Print generated plan after the execution.")
282281
def run(

tests/cli/test_isolation.py

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
# limitations under the License.
1818
"""Test execution of commands in parallel."""
1919

20-
import os
2120
import subprocess
2221
import sys
22+
import textwrap
2323
import time
2424
from pathlib import Path
2525

26-
import pytest
26+
from tests.utils import write_and_commit_file
2727

2828

2929
def test_run_in_isolation(runner, project, client, run, subdirectory):
@@ -51,61 +51,51 @@ def test_run_in_isolation(runner, project, client, run, subdirectory):
5151
assert client.repository.head.commit.hexsha != head
5252

5353

54-
@pytest.mark.skip(reason="FIXME: Isolation requires merging the database metadata.")
55-
def test_file_modification_during_run(
56-
tmpdir, runner, project, client, run, subdirectory, no_lfs_size_limit, no_lfs_warning
57-
):
54+
def test_file_modification_during_run(tmp_path, runner, client, subdirectory, no_lfs_size_limit, no_lfs_warning):
5855
"""Test run in isolation."""
5956
script = client.path / "script.py"
6057
output = client.path / "output"
61-
lock = Path(str(tmpdir.join("lock")))
62-
63-
with client.commit():
64-
script.write_text(
65-
"import os, time, sys\n"
66-
'open("{lock}", "a")\n'
67-
'while os.path.exists("{lock}"):\n'
68-
" time.sleep(1)\n"
69-
"sys.stdout.write(sys.stdin.read())\n"
70-
"sys.stdout.flush()\n".format(lock=str(lock))
71-
)
72-
73-
prefix = [
74-
sys.executable,
75-
"-m",
76-
"renku.ui.cli",
77-
"run",
78-
"--isolation",
79-
]
80-
cmd = ["python", os.path.relpath(script, os.getcwd())]
81-
82-
previous = client.repository.head.commit
58+
lock_file = tmp_path / "lock"
59+
60+
write_and_commit_file(
61+
client.repository,
62+
script,
63+
textwrap.dedent(
64+
f"""
65+
import os, time, sys
66+
open("{lock_file}", "a")
67+
while os.path.exists("{lock_file}"):
68+
time.sleep(0.1)
69+
sys.stdout.write(sys.stdin.read())
70+
sys.stdout.flush()
71+
"""
72+
),
73+
)
8374

8475
with output.open("wb") as stdout:
85-
process = subprocess.Popen(prefix + cmd, stdin=subprocess.PIPE, stdout=stdout)
76+
command = [sys.executable, "-m", "renku.ui.cli", "run", "--isolation", "--", "python", script]
77+
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=stdout)
8678

87-
while not lock.exists() and process.poll() is None:
88-
time.sleep(1)
79+
while not lock_file.exists() and process.poll() is None:
80+
time.sleep(0.1)
8981

9082
assert process.poll() is None, "Subprocess exited prematurely"
9183

92-
with script.open("w") as fp:
93-
fp.write('print("edited")')
84+
# NOTE: Modify ``script.py`` in the current worktree
85+
script.write_text("print('edited')")
9486

95-
lock.unlink()
87+
# NOTE: Signal the isolated run to continue
88+
lock_file.unlink()
9689

9790
process.communicate(input=b"test")
9891
assert 0 == process.wait()
9992

100-
with output.open("r") as fp:
101-
assert "test" == fp.read().strip()
93+
# NOTE: ``script.py`` is modified in the current worktree
94+
assert {"script.py"} == {c.a_path for c in client.repository.unstaged_changes}
10295

103-
# TODO: Make sure that this test fails before fixing it
104-
# NOTE: Calculate the diff between HEAD and previous commit; this is not the exact same diff but should be ok
105-
diff = [
106-
c
107-
for commit in client.repository.iterate_commits(revision=f"{previous.hexsha}..HEAD")
108-
for c in commit.get_changes()
109-
]
110-
modifications = [modification for modification in diff if modification.change_type == "M"]
111-
assert 0 == len(modifications), f"{[(f.a_path, f.change_type) for f in diff]}"
96+
# NOTE: Isolated run finished with the expected result
97+
assert "test" == output.read_text().strip()
98+
# NOTE: Isolated run committed its results
99+
committed_changed_files_in_run = {c.a_path for c in client.repository.head.commit.get_changes()}
100+
assert "output" in committed_changed_files_in_run
101+
assert "script.py" not in committed_changed_files_in_run

0 commit comments

Comments
 (0)