Skip to content

Commit 58b3c5f

Browse files
authored
Fix dependency:licenses to correctly parse exceptional names (#464)
* Fix dependency:licenses to correctly parse exceptional names * Soften restrictions as handled later with the class Package which uses Version to validate the text
1 parent d7c33bb commit 58b3c5f

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

doc/changes/unreleased.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
## ✨ Features
66

77
* #426: Allowed configuring the python version used for coverage
8+
9+
## Bugfixes
10+
11+
* #463: Fixed dependency:licenses to correctly parse exceptional names

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+(?:\.\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}

test/unit/util/dependencies/poetry_dependencies_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ class TestPoetryDependencies:
9595
"import-linter 2.3 Enforces rules for the imports within and between Python packages.",
9696
Package(name="import-linter", version="2.3"),
9797
),
98+
(
99+
"python-dateutil 2.9.0.post0 Extensions to the standard Python datetime module",
100+
Package(name="python-dateutil", version="2.9.0.post0"),
101+
),
102+
(
103+
"types-requests 2.32.0.20250602",
104+
Package(name="types-requests", version="2.32.0.20250602"),
105+
),
98106
],
99107
)
100108
def test_extract_from_line(line, expected):

0 commit comments

Comments
 (0)