From 493e2e231fbaf426dbf7dfa9dfff4f11e71efc74 Mon Sep 17 00:00:00 2001 From: Nicolas Graves Date: Thu, 18 Sep 2025 22:23:27 +0200 Subject: [PATCH] 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 --- guix/build/pyproject-build-system.scm | 39 ++++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/guix/build/pyproject-build-system.scm b/guix/build/pyproject-build-system.scm index bc9cccced6e..4230908ac8a 100644 --- a/guix/build/pyproject-build-system.scm +++ b/guix/build/pyproject-build-system.scm @@ -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 point’s NAME, MODULE and FUNCTION