Skip to content

Commit a5a359e

Browse files
ckunkiArBridgeman
andauthored
#580: Fixed Nox session release:prepare for multi-project repositories (#584)
* #580: Fixed Nox session release:prepare for multi-project repositories Co-authored-by: Ariel Schulz <43442541+ArBridgeman@users.noreply.github.com>
1 parent 6987180 commit a5a359e

File tree

4 files changed

+48
-43
lines changed

4 files changed

+48
-43
lines changed

doc/changes/unreleased.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Unreleased
22

3+
## Summary
4+
5+
This releases fixes Nox session `release:prepare` for multi-project repositories.
6+
7+
## Bugfixes
8+
9+
* #580: Fixed Nox session `release:prepare` for multi-project repositories
10+
311
## Features
412

513
* #485: Improved nox task `release:trigger`

exasol/toolbox/util/dependencies/poetry_dependencies.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Package,
1919
)
2020
from exasol.toolbox.util.git import Git
21+
from noxconfig import PROJECT_CONFIG
2122

2223

2324
class PoetryGroup(BaseModel):
@@ -82,6 +83,12 @@ def groups(self) -> tuple[PoetryGroup, ...]:
8283
return tuple(groups)
8384

8485

86+
def run_command(*args: str, cwd: Path | None = None) -> subprocess.CompletedProcess:
87+
return subprocess.run(
88+
args, capture_output=True, text=True, cwd=cwd, check=True
89+
) # nosec: B603 - risk of untrusted input for subprocess call is accepted
90+
91+
8592
class PoetryDependencies(BaseModel):
8693
groups: tuple[PoetryGroup, ...]
8794
working_directory: Path
@@ -111,44 +118,34 @@ def direct_dependencies(
111118
) -> OrderedDict[str, dict[NormalizedPackageStr, Package]]:
112119
dependencies = OrderedDict()
113120
for group in self.groups:
114-
command = (
121+
proc = run_command(
115122
"poetry",
116123
"show",
117124
"--top-level",
118125
f"--only={group.name}",
119126
"--no-truncate",
120-
)
121-
output = subprocess.run(
122-
command,
123-
capture_output=True,
124-
text=True,
125127
cwd=self.working_directory,
126-
check=True,
127128
)
128-
result = self._extract_from_poetry_show(output_text=output.stdout)
129+
result = self._extract_from_poetry_show(output_text=proc.stdout)
129130
dependencies[group.name] = result
130131
return dependencies
131132

132133
@property
133134
def all_dependencies(self) -> OrderedDict[str, dict[NormalizedPackageStr, Package]]:
134-
command = ("poetry", "show", "--no-truncate")
135-
output = subprocess.run(
136-
command,
137-
capture_output=True,
138-
text=True,
135+
proc = run_command(
136+
"poetry",
137+
"show",
138+
"--no-truncate",
139139
cwd=self.working_directory,
140-
check=True,
141140
)
142-
143141
direct_dependencies = self.direct_dependencies.copy()
144-
145142
transitive_dependencies = {}
146143
names_direct_dependencies = {
147144
package_name
148145
for group_list in direct_dependencies
149146
for package_name in group_list
150147
}
151-
for line in output.stdout.splitlines():
148+
for line in proc.stdout.splitlines():
152149
dep = self._extract_from_line(line=line)
153150
if dep and dep.name not in names_direct_dependencies:
154151
transitive_dependencies[dep.normalized_name] = dep
@@ -169,10 +166,9 @@ def get_dependencies_from_latest_tag() -> (
169166
OrderedDict[str, dict[NormalizedPackageStr, Package]]
170167
):
171168
latest_tag = Git.get_latest_tag()
172-
with tempfile.TemporaryDirectory() as path:
173-
tmpdir = Path(path)
174-
175-
Git.copy_remote_file_locally(latest_tag, "poetry.lock", tmpdir)
176-
Git.copy_remote_file_locally(latest_tag, PYPROJECT_TOML, tmpdir)
177-
169+
path = PROJECT_CONFIG.root.relative_to(Git.toplevel())
170+
with tempfile.TemporaryDirectory() as tmpdir_str:
171+
tmpdir = Path(tmpdir_str)
172+
for file in ("poetry.lock", PYPROJECT_TOML):
173+
Git.checkout(latest_tag, path / file, tmpdir / file)
178174
return get_dependencies(working_directory=tmpdir)

exasol/toolbox/util/git.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess # nosec
22
from functools import wraps
33
from pathlib import Path
4+
from typing import Union
45

56

67
def run_command(func):
@@ -26,25 +27,28 @@ def get_latest_tag():
2627

2728
@staticmethod
2829
@run_command
29-
def read_file_from_tag(tag: str, remote_file: str):
30+
def read_file_from_tag(tag: str, path: Union[Path, str]):
3031
"""
31-
Read the contents of the specified file `remote_file` at the point in time
32-
specified by git tag `tag`.
32+
Read the contents of the specified file `path` at the point in
33+
time specified by git tag `tag`.
3334
"""
34-
return ["git", "cat-file", "blob", f"{tag}:{remote_file}"]
35+
return ["git", "cat-file", "blob", f"{tag}:{path}"]
3536

3637
@staticmethod
37-
def copy_remote_file_locally(
38-
tag: str, remote_file: str, destination_directory: Path
39-
) -> None:
38+
def checkout(tag: str, source: Path, dest: Path) -> None:
4039
"""
41-
Copy the contents of the specified file `remote_file` at the point in time
42-
specified by git tag `tag` and copy it into the local `destination_directory/remote_file`.
40+
Copy the specified file `source` at the point in time specified by
41+
git tag `tag` to file `dest` within the local filesystem.
4342
"""
44-
contents = Git.read_file_from_tag(tag=tag, remote_file=remote_file)
45-
(destination_directory / remote_file).write_text(contents)
43+
contents = Git.read_file_from_tag(tag=tag, path=source)
44+
dest.write_text(contents)
4645

4746
@staticmethod
4847
@run_command
4948
def create_and_switch_to_branch(branch_name: str):
5049
return ["git", "switch", "-c", branch_name]
50+
51+
@staticmethod
52+
@run_command
53+
def toplevel():
54+
return ["git", "rev-parse", "--show-toplevel"]

test/unit/util/git_test.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def latest_tag() -> str:
1313

1414
@pytest.fixture(scope="module")
1515
def read_file_from_tag(latest_tag) -> str:
16-
return Git.read_file_from_tag(tag=latest_tag, remote_file=POETRY_LOCK)
16+
return Git.read_file_from_tag(tag=latest_tag, path=POETRY_LOCK)
1717

1818

1919
class TestGit:
@@ -28,12 +28,9 @@ def test_read_file_from_tag(read_file_from_tag):
2828
assert read_file_from_tag != ""
2929

3030
@staticmethod
31-
def test_copy_remote_file_locally(tmp_path, read_file_from_tag):
32-
latest_tag = Git.get_latest_tag()
33-
34-
Git.copy_remote_file_locally(
35-
tag=latest_tag, remote_file=POETRY_LOCK, destination_directory=tmp_path
36-
)
37-
38-
result = (tmp_path / POETRY_LOCK).read_text()
31+
def test_checkout(tmp_path, read_file_from_tag):
32+
tag = Git.get_latest_tag()
33+
dest = tmp_path / POETRY_LOCK
34+
Git.checkout(tag=tag, source=POETRY_LOCK, dest=dest)
35+
result = dest.read_text()
3936
assert result == read_file_from_tag

0 commit comments

Comments
 (0)