guix_mirror_bot pushed a commit to branch python-team
in repository guix.

commit 816b73fa212665d8b39b7c2417864f99c3826833
Author: Nicolas Graves <[email protected]>
AuthorDate: Thu Sep 18 22:23:27 2025 +0200

    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 <[email protected]>
---
 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 ce39a9fe77..dea6699f76 100644
--- a/guix/build/pyproject-build-system.scm
+++ b/guix/build/pyproject-build-system.scm
@@ -400,6 +400,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
@@ -411,25 +426,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

Reply via email to