Github messages for voidlinux
 help / color / mirror / Atom feed
From: voidlinux-github@inbox.vuxu.org
To: ml@inbox.vuxu.org
Subject: [PR PATCH] hook: python-shebang: check for shebang in the first line only
Date: Sat, 28 Dec 2019 05:58:05 +0100	[thread overview]
Message-ID: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-17837@inbox.vuxu.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

There is a new pull request by sgn against master on the void-packages repository

https://github.com/sgn/void-packages python3-shebang-rewrite-fix
https://github.com/void-linux/void-packages/pull/17837

hook: python-shebang: check for shebang in the first line only
- Grepping whole files is inefficient
- git-instaweb (in git package) has the code to generate python file in
  a here doc in the middle of its code, old hook generates false
  positive with this package

A patch file from https://github.com/void-linux/void-packages/pull/17837.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-python3-shebang-rewrite-fix-17837.patch --]
[-- Type: text/x-diff, Size: 1584 bytes --]

From 352322c0c1cc5591ec326d3325364b2087b39b69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
 <congdanhqx@gmail.com>
Date: Sat, 28 Dec 2019 11:50:24 +0700
Subject: [PATCH] hook: python-shebang: check for shebang in the first line
 only

- Grepping whole files is inefficient
- git-instaweb (in git package) has the code to generate python file in
  a here doc in the middle of its code, old hook generates false
  positive with this package
---
 common/hooks/pre-pkg/03-rewrite-python-shebang.sh | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh
index 81e45b9821f..4de75da2a76 100644
--- a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh
+++ b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh
@@ -20,9 +20,10 @@ hook() {
 
 	shebang="#!/usr/bin/python${pyver%.*}"
 	find "${PKGDESTDIR}" -type f -print0 | \
-		xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([0-9]\.[0-9]\)\?\([[:space:]]\+\|$\)" -- | while IFS=: read -r f off _; do
-		[ -z "$off" ] && continue
-		echo "   Shebang converted to '$shebang': ${f#$PKGDESTDIR}"
-		sed -i "1s@.*python.*@${shebang}@" -- "$f"
-	done
+		while IFS= read -r -d '' file; do
+			[ ! -s "$file" ] && continue
+			[ -z "$(sed -n -E -e 2q -e '/^#!.*([[:space:]]|\/)python([0-9]\.[0-9])?([[:space:]]+|$)/p' "$file")" ] && continue
+			echo "   Shebang converted to '$shebang': ${file#$PKGDESTDIR}"
+			sed -i "1s@.*python.*@${shebang}@" -- "$file"
+		done
 }

             reply	other threads:[~2019-12-28  4:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-28  4:58 voidlinux-github [this message]
2019-12-28 16:59 ` voidlinux-github
2019-12-28 17:02 ` [PR PATCH] [Merged]: " voidlinux-github

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-17837@inbox.vuxu.org \
    --to=voidlinux-github@inbox.vuxu.org \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).