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:
|
def __cleanup_requires(string: str) -> str:
|
||||||
import re
|
import re
|
||||||
|
|
||||||
regexes = [
|
rx_op = r'(!=|<=|>=|==|[<>=])'
|
||||||
(r'^ +', ''),
|
ret: list[str] = []
|
||||||
(r'([ \t]|$)+', ', '),
|
for element in string.split(','):
|
||||||
(r', $', ''),
|
# -- Separate the version constraints from their operands,
|
||||||
(r', $', ''),
|
# which turns every package name, operator, and version into
|
||||||
(r' *,* *([<>=]+) *,* *', r' \1 '),
|
# its own whitespace-separated token
|
||||||
]
|
element = re.sub(rx_op, r' \1 ', element)
|
||||||
for patt, replacement in regexes:
|
tokens = element.split()
|
||||||
string = re.sub(patt, replacement, string)
|
i = 0
|
||||||
return string
|
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
|
@override
|
||||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
TOPDIR = ../../../../../../../..
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/py-run.mk
|
||||||
|
|
||||||
|
all:
|
||||||
|
|
||||||
|
test: run
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
from jw.pkg.cmds.projects.CmdCreatePkgConfig import CmdCreatePkgConfig
|
||||||
|
|
||||||
|
# __cleanup_requires() is a private staticmethod; reach it via getattr
|
||||||
|
cleanup = getattr(CmdCreatePkgConfig, '_CmdCreatePkgConfig__cleanup_requires')
|
||||||
|
|
||||||
|
# -- __cleanup_requires --
|
||||||
|
|
||||||
|
# Comma- and space-separated input alike comes out as a clean ", "-joined list
|
||||||
|
assert cleanup('jw-core >= 1.0, jw-base') == 'jw-core >= 1.0, jw-base'
|
||||||
|
assert cleanup('jw-core >= 1.0 jw-base') == 'jw-core >= 1.0, jw-base'
|
||||||
|
assert cleanup('jw-core >= 1.0, jw-base') == 'jw-core >= 1.0, jw-base'
|
||||||
|
|
||||||
|
# Plain names without version constraints are joined the same way
|
||||||
|
assert cleanup('a b c') == 'a, b, c'
|
||||||
|
|
||||||
|
# A single element is unchanged
|
||||||
|
assert cleanup('jw-core >= 1.0') == 'jw-core >= 1.0'
|
||||||
|
|
||||||
|
# The empty input yields the empty output
|
||||||
|
assert cleanup('') == ''
|
||||||
|
|
||||||
|
# Every constraint operator is re-paired with its name and version
|
||||||
|
assert (
|
||||||
|
cleanup('x <= 2, y != 3, z == 4, w > 5, v < 6, u = 7') ==
|
||||||
|
'x <= 2, y != 3, z == 4, w > 5, v < 6, u = 7'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Whitespace around a separator collapses to a single ", "
|
||||||
|
assert cleanup('jw-a = 1.0 , jw-b = 2.0') == 'jw-a = 1.0, jw-b = 2.0'
|
||||||
|
|
||||||
|
print('All CmdCreatePkgConfig tests passed')
|
||||||
Loading…
Reference in a new issue