public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-python] [PATCHES] Use bash built-ins rather than external tools
@ 2013-04-23  5:46 Michał Górny
  2013-04-23  5:46 ` [gentoo-python] [PATCH 1/2] Replace sed call with variable substitution Michał Górny
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michał Górny @ 2013-04-23  5:46 UTC (permalink / raw
  To: gentoo-python; +Cc: python

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

Hi,

Two quick patches. They switch our eclasses to use bash built-ins
whenever possible to avoid the whole overhead of calling external tools
and piping variables to them to perform simple tasks.

First replaces the 'sed' call in _python_rewrite_shebang() with local
variable substitution to remove the CR.

Second replaces both uses of 'head -n 1' with simple 'read' call to
obtain the first line.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gentoo-python] [PATCH 1/2] Replace sed call with variable substitution.
  2013-04-23  5:46 [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
@ 2013-04-23  5:46 ` Michał Górny
  2013-04-23  5:46 ` [gentoo-python] [PATCH 2/2] Replace 'head -n 1' calls with 'read' built-in Michał Górny
  2013-04-30  5:37 ` [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2013-04-23  5:46 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

Bash variable substitution is simpler and faster. It will also allow us
to spare the pipes in the next commit.
---
 gx86/eclass/python-utils-r1.eclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
index 81e6d59..1ab8366 100644
--- a/gx86/eclass/python-utils-r1.eclass
+++ b/gx86/eclass/python-utils-r1.eclass
@@ -493,8 +493,9 @@ _python_rewrite_shebang() {
 
 	local f
 	for f; do
-		local shebang=$(head -n 1 "${f}" | sed 's/\r$//')
+		local shebang=$(head -n 1 "${f}")
 		local from
+		shebang=${shebang%$'\r'}
 		debug-print "${FUNCNAME}: path = ${f}"
 		debug-print "${FUNCNAME}: shebang = ${shebang}"
 
-- 
1.8.1.5



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-python] [PATCH 2/2] Replace 'head -n 1' calls with 'read' built-in.
  2013-04-23  5:46 [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
  2013-04-23  5:46 ` [gentoo-python] [PATCH 1/2] Replace sed call with variable substitution Michał Górny
@ 2013-04-23  5:46 ` Michał Górny
  2013-04-30  5:37 ` [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2013-04-23  5:46 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

The read built-in is simpler than forking and using pipes to relay
the first line of the file.
---
 gx86/eclass/distutils-r1.eclass    | 6 ++++--
 gx86/eclass/python-utils-r1.eclass | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
index 991d0a1..dd19440 100644
--- a/gx86/eclass/distutils-r1.eclass
+++ b/gx86/eclass/distutils-r1.eclass
@@ -394,9 +394,11 @@ _distutils-r1_rename_scripts() {
 	while IFS= read -r -d '' f; do
 		debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
 
-		if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
+		local shebang
+		read -r shebang < "${f}"
+		if [[ ${shebang} == '#!'*${EPYTHON}* ]]
 		then
-			debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
+			debug-print "${FUNCNAME}: matching shebang: ${shebang}"
 
 			local newf=${f}-${EPYTHON}
 			debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
index 1ab8366..cd229f3 100644
--- a/gx86/eclass/python-utils-r1.eclass
+++ b/gx86/eclass/python-utils-r1.eclass
@@ -493,8 +493,8 @@ _python_rewrite_shebang() {
 
 	local f
 	for f; do
-		local shebang=$(head -n 1 "${f}")
-		local from
+		local from shebang
+		read -r shebang < "${f}"
 		shebang=${shebang%$'\r'}
 		debug-print "${FUNCNAME}: path = ${f}"
 		debug-print "${FUNCNAME}: shebang = ${shebang}"
-- 
1.8.1.5



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-python] [PATCHES] Use bash built-ins rather than external tools
  2013-04-23  5:46 [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
  2013-04-23  5:46 ` [gentoo-python] [PATCH 1/2] Replace sed call with variable substitution Michał Górny
  2013-04-23  5:46 ` [gentoo-python] [PATCH 2/2] Replace 'head -n 1' calls with 'read' built-in Michał Górny
@ 2013-04-30  5:37 ` Michał Górny
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2013-04-30  5:37 UTC (permalink / raw
  To: Michał Górny; +Cc: gentoo-python, python

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

Committed.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-30  5:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-23  5:46 [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
2013-04-23  5:46 ` [gentoo-python] [PATCH 1/2] Replace sed call with variable substitution Michał Górny
2013-04-23  5:46 ` [gentoo-python] [PATCH 2/2] Replace 'head -n 1' calls with 'read' built-in Michał Górny
2013-04-30  5:37 ` [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox