build-system: pyproject: Improve entry-point parser.

* guix/build/pyproject-build-system.scm (create-entrypoints): Add
procedures parse-entry-points and parse-line.

Change-Id: Ifd208df6a912431f8d996c5dab2b39987dcc3532
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
This commit is contained in:
Nicolas Graves 2025-09-18 22:23:27 +02:00 committed by Andreas Enge
parent c7cd112166
commit 1f84186cd3
No known key found for this signature in database
GPG key ID: F7D5C9BF765C61E3

View file

@ -401,6 +401,21 @@ which creates runnable scripts in bin/ from entry point specification
file entry_points.txt. This is necessary, because wheels do not contain
these binaries and installers are expected to create them."
(define (parse-entry-point item-match)
"Parse an entry point. Return a list of script, module and function."
(list (match:substring item-match 1)
(match:substring item-match 2)
(match:substring item-match 3)))
(define (parse-line inside line)
(cond
((string-match "^\\[(console|gui)_scripts\\]$" line)
#t)
((and inside (string-match "^([^ =]+)\\s*=\\s*([^:]+):(.+)$" line))
=> parse-entry-point)
(else
#f)))
(define (entry-points.txt->entry-points file)
"Specialized parser for Python configfile-like files, in particular
entry_points.txt. Returns a list of console_script and gui_scripts
@ -412,25 +427,11 @@ entry points."
(result '()))
(if (eof-object? line)
result
(let* ((group-match (string-match "^\\[(.+)\\]$" line))
(group-name (if group-match
(match:substring group-match 1)
#f))
(next-inside (if (not group-name)
inside
(or (string=? group-name
"console_scripts")
(string=? group-name "gui_scripts"))))
(item-match (string-match
"^([^ =]+)\\s*=\\s*([^:]+):(.+)$" line)))
(if (and inside item-match)
(loop (read-line in)
next-inside
(cons (list (match:substring item-match 1)
(match:substring item-match 2)
(match:substring item-match 3))
result))
(loop (read-line in) next-inside result))))))))
(match (parse-line inside line)
((? list? entry)
(loop (read-line in) #t (cons entry result)))
(next-inside
(loop (read-line in) next-inside result))))))))
(define (create-script path name module function)
"Create a Python script from an entry points NAME, MODULE and FUNCTION