git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Makefile: Avoid multi-line sed when building python scripts

From
David Aguilar <davvid@gmail.com>
Date
Apr 9, 2010, 08:42 UTC
Message-ID
<1270802559-14791-1-git-send-email-davvid@gmail.com>
In-Reply-To
<20100409080256.GA12527@gmail.com>

Instead of requiring scripts to start with "import sys", install the sys.path initialization code immediately after each script's new shebang line.

This works around portability issues with multi-line sed and simplifies the work for contributors. There is no longer the requirement that every script must "import sys" before importing git-provided modules.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 Makefile |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 956e781..b763947 100644
--- a/Makefile
+++ b/Makefile
@@ -1608,12 +1608,10 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py
 		--no-print-directory prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' \
 		instlibdir` && \
 	sed -e '1{' \
-	    -e '	s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
+	    -e '	s|#!.*python|#!$(PYTHON_PATH_SQ)\n@@STARTUP@@|' \
 	    -e '}' \
-	    -e 's|^import sys.*|&; \\\
-	           import os; \\\
-	           sys.path.insert(0, os.getenv("GITPYTHONLIB",\
-	                                        "@@INSTLIBDIR@@"));|' \
+	    -e 's|@@STARTUP@@|import os, sys; sys.path.insert(0, @@ENV@@)|' \
+	    -e 's|@@ENV@@|os.getenv("GITPYTHONLIB", "@@INSTLIBDIR@@")|' \
 	    -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
 	    $@.py >$@+ && \
 	chmod +x $@+ && \
-- 
1.7.0.3.313.g87b3c
Previous: David AguilarNext: Brian Gernhardt
Message 4 of 8 in “Makefile: Remove excess backslashes from sed”
  1. Makefile: Remove excess backslashes from sedBrian Gernhardt, Apr 9, 2010
  2. Junio C HamanoApr 9, 2010
  3. David AguilarApr 9, 2010
  4. Makefile: Avoid multi-line sed when building python scriptsDavid Aguilar, Apr 9, 2010
  5. Brian GernhardtApr 9, 2010
  6. Sverre RabbelierApr 9, 2010
  7. Makefile: Simplify handling of python scriptsBrian Gernhardt, Apr 9, 2010
  8. David AguilarApr 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.