Skip to content

Commit dcb1269

Browse files
committed
Soften restrictions as handled later with the class Package which uses Version to validate the text
1 parent 31ded78 commit dcb1269

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

exasol/toolbox/util/dependencies/poetry_dependencies.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import re
44
import subprocess
5+
import sys
56
from pathlib import Path
67
from typing import Optional
78

89
import tomlkit
910
from pydantic import (
1011
BaseModel,
11-
model_validator,
1212
)
1313
from tomlkit import TOMLDocument
1414

@@ -84,19 +84,33 @@ class PoetryDependencies(BaseModel):
8484
working_directory: Path
8585

8686
@staticmethod
87-
def _extract_from_line(line: str) -> Package:
88-
pattern = r"\s+(\d+(?:\.\S+)*)"
89-
match = re.split(pattern, line)
90-
return Package(name=match[0], version=match[1])
87+
def _extract_from_line(line: str) -> Optional[Package]:
88+
# remove (!) from line as indicates not installed in environment,
89+
# which could occur for optional dependencies
90+
split_line = line.replace("(!)", "").strip().split(maxsplit=2)
91+
if len(split_line) < 2:
92+
print(f"Unable to parse dependency={line}")
93+
return None
94+
return Package(name=split_line[0], version=split_line[1])
9195

9296
def _extract_from_poetry_show(self, output_text: str) -> list[Package]:
93-
return [self._extract_from_line(line) for line in output_text.splitlines()]
97+
return [
98+
package
99+
for line in output_text.splitlines()
100+
if (package := self._extract_from_line(line))
101+
]
94102

95103
@property
96104
def direct_dependencies(self) -> dict[str, list[Package]]:
97105
dependencies = {}
98106
for group in self.groups:
99-
command = ("poetry", "show", "--top-level", f"--only={group.name}")
107+
command = (
108+
"poetry",
109+
"show",
110+
"--top-level",
111+
f"--only={group.name}",
112+
"--no-truncate",
113+
)
100114
output = subprocess.run(
101115
command,
102116
capture_output=True,
@@ -110,7 +124,7 @@ def direct_dependencies(self) -> dict[str, list[Package]]:
110124

111125
@property
112126
def all_dependencies(self) -> dict[str, list[Package]]:
113-
command = ("poetry", "show")
127+
command = ("poetry", "show", "--no-truncate")
114128
output = subprocess.run(
115129
command,
116130
capture_output=True,
@@ -128,7 +142,7 @@ def all_dependencies(self) -> dict[str, list[Package]]:
128142
}
129143
for line in output.stdout.splitlines():
130144
dep = self._extract_from_line(line=line)
131-
if dep.name not in names_direct_dependencies:
145+
if dep and dep.name not in names_direct_dependencies:
132146
transitive_dependencies.append(dep)
133147

134148
return direct_dependencies | {TRANSITIVE_GROUP.name: transitive_dependencies}

0 commit comments

Comments
 (0)