cmds.projects.CmdCreatePkgConfig: Fix Requires lines
__cleanup_requires() replaces every run of whitespace with ", " before re-pairing the version constraints, so input that is already comma-separated, e.g. "jw-core >= 1.0, jw-base", comes out with a double comma, "jw-core >= 1.0,, jw-base". And the Requires line is appended without a trailing newline, so a following Requires.private line runs straight into it. Split the input on commas and whitespace, treating the version constraint operators as delimiters that are re-paired with the preceding name and the following version, so that comma- and space-separated input alike comes out as a clean ", "-joined list. Add the missing newline after the Requires line. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
6fe8f5dc65
commit
dd2fff17a5
3 changed files with 58 additions and 10 deletions
|
|
@ -23,16 +23,25 @@ class CmdCreatePkgConfig(Cmd): # export
|
|||
def __cleanup_requires(string: str) -> str:
|
||||
import re
|
||||
|
||||
regexes = [
|
||||
(r'^ +', ''),
|
||||
(r'([ \t]|$)+', ', '),
|
||||
(r', $', ''),
|
||||
(r', $', ''),
|
||||
(r' *,* *([<>=]+) *,* *', r' \1 '),
|
||||
]
|
||||
for patt, replacement in regexes:
|
||||
string = re.sub(patt, replacement, string)
|
||||
return string
|
||||
rx_op = r'(!=|<=|>=|==|[<>=])'
|
||||
ret: list[str] = []
|
||||
for element in string.split(','):
|
||||
# -- Separate the version constraints from their operands,
|
||||
# which turns every package name, operator, and version into
|
||||
# its own whitespace-separated token
|
||||
element = re.sub(rx_op, r' \1 ', element)
|
||||
tokens = element.split()
|
||||
i = 0
|
||||
while i < len(tokens):
|
||||
if (i + 2 < len(tokens)
|
||||
and re.fullmatch(rx_op, tokens[i + 1]) is not None):
|
||||
# -- Merge the name, operator, and version back together
|
||||
ret.append(' '.join(tokens[i:i + 3]))
|
||||
i += 3
|
||||
continue
|
||||
ret.append(tokens[i])
|
||||
i += 1
|
||||
return ', '.join(ret)
|
||||
|
||||
@override
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue