Skip to content

Commit d5493af

Browse files
committed
#580: Fixed Nox session release:prepare for multi-project repositories
1 parent 7946592 commit d5493af

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

doc/changes/unreleased.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
# Unreleased
2+
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

exasol/toolbox/util/dependencies/poetry_dependencies.py

Lines changed: 15 additions & 21 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,10 @@ 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(args, capture_output=True, text=True, cwd=cwd, check=True)
88+
89+
8590
class PoetryDependencies(BaseModel):
8691
groups: tuple[PoetryGroup, ...]
8792
working_directory: Path
@@ -111,44 +116,34 @@ def direct_dependencies(
111116
) -> OrderedDict[str, dict[NormalizedPackageStr, Package]]:
112117
dependencies = OrderedDict()
113118
for group in self.groups:
114-
command = (
119+
proc = run_command(
115120
"poetry",
116121
"show",
117122
"--top-level",
118123
f"--only={group.name}",
119124
"--no-truncate",
120-
)
121-
output = subprocess.run(
122-
command,
123-
capture_output=True,
124-
text=True,
125125
cwd=self.working_directory,
126-
check=True,
127126
)
128-
result = self._extract_from_poetry_show(output_text=output.stdout)
127+
result = self._extract_from_poetry_show(output_text=proc.stdout)
129128
dependencies[group.name] = result
130129
return dependencies
131130

132131
@property
133132
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,
133+
proc = run_command(
134+
"poetry",
135+
"show",
136+
"--no-truncate",
139137
cwd=self.working_directory,
140-
check=True,
141138
)
142-
143139
direct_dependencies = self.direct_dependencies.copy()
144-
145140
transitive_dependencies = {}
146141
names_direct_dependencies = {
147142
package_name
148143
for group_list in direct_dependencies
149144
for package_name in group_list
150145
}
151-
for line in output.stdout.splitlines():
146+
for line in proc.stdout.splitlines():
152147
dep = self._extract_from_line(line=line)
153148
if dep and dep.name not in names_direct_dependencies:
154149
transitive_dependencies[dep.normalized_name] = dep
@@ -169,10 +164,9 @@ def get_dependencies_from_latest_tag() -> (
169164
OrderedDict[str, dict[NormalizedPackageStr, Package]]
170165
):
171166
latest_tag = Git.get_latest_tag()
167+
dir = PROJECT_CONFIG.root.relative_to(Git.toplevel())
172168
with tempfile.TemporaryDirectory() as path:
173169
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-
170+
for file in ("poetry.lock", PYPROJECT_TOML):
171+
Git.checkout(latest_tag, dir / file, tmpdir / file)
178172
return get_dependencies(working_directory=tmpdir)

exasol/toolbox/util/git.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ def read_file_from_tag(tag: str, remote_file: str):
3434
return ["git", "cat-file", "blob", f"{tag}:{remote_file}"]
3535

3636
@staticmethod
37-
def copy_remote_file_locally(
38-
tag: str, remote_file: str, destination_directory: Path
39-
) -> None:
37+
def checkout(tag: str, source: Path, dest: Path) -> None:
4038
"""
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`.
39+
Copy the specified file `source` at the point in time specified by
40+
git tag `tag` to file `dest` within the local filesystem.
4341
"""
44-
contents = Git.read_file_from_tag(tag=tag, remote_file=remote_file)
45-
(destination_directory / remote_file).write_text(contents)
42+
contents = Git.read_file_from_tag(tag=tag, remote_file=source)
43+
dest.write_text(contents)
4644

4745
@staticmethod
4846
@run_command
4947
def create_and_switch_to_branch(branch_name: str):
5048
return ["git", "switch", "-c", branch_name]
49+
50+
@staticmethod
51+
@run_command
52+
def toplevel() -> str:
53+
return ["git", "rev-parse", "--show-toplevel"]

test/unit/util/git_test.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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)