* [PR PATCH] hook: python-shebang: check for shebang in the first line only
@ 2019-12-28 4:58 voidlinux-github
2019-12-28 16:59 ` voidlinux-github
2019-12-28 17:02 ` [PR PATCH] [Merged]: " voidlinux-github
0 siblings, 2 replies; 3+ messages in thread
From: voidlinux-github @ 2019-12-28 4:58 UTC (permalink / raw)
To: ml
[-- 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
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-28 17:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-28 4:58 [PR PATCH] hook: python-shebang: check for shebang in the first line only voidlinux-github
2019-12-28 16:59 ` voidlinux-github
2019-12-28 17:02 ` [PR PATCH] [Merged]: " voidlinux-github
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).