Makefile: Remove usage of deprecated Python "has_key" method
PATCH 1/1 Makefile: Remove usage of deprecated Python "has_key" method
"has_key" is a deprecated dictionary method in Python 2.6+. Simplify the sys.path manipulation for installed scripts by passing a default value to os.getenv().
SCRIPT_PYTHON is currently empty but this future-proofs us. It also fixes things for users who maintain local git forks with their own SCRIPT_PYTHON additions.
--- Makefile | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
Makefile +2 -3
@@ -1609,9 +1609,8 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py -e '}' \ -e 's|^import sys.*|&; \\\ import os; \\\ - sys.path[0] = os.environ.has_key("GITPYTHONLIB") and \\\ - os.environ["GITPYTHONLIB"] or \\\ - "@@INSTLIBDIR@@"|' \ + sys.path.insert(0, os.getenv("GITPYTHONLIB",\ + "@@INSTLIBDIR@@"));|' \ -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \ [email protected] >$@+ && \ chmod +x $@+ && \
Signature · 1 line
1.7.0.3.291.g5e4f6
Quoted 3 lines · David Aguilar
"
has_key" is a deprecated dictionary method in Python 2.6+. Simplify the sys.path manipulation for installed scripts by passing a default value toos.getenv().
It looks like the old code was replacing sys.path[0] but you are prepending this. Doesn't that change also make a difference?
Quoted 27 lines
SCRIPT_PYTHONis currently empty but this future-proofs us. It also fixes things for users who maintain local git forks with their ownSCRIPT_PYTHONadditions.Signed-off-by David Aguilar <[email protected]>--- Makefile | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)Makefile +2
-3@@ -1609,9 +1609,8 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py -e '}' \ -e 's|^import sys.*|&; \\\ import os; \\\ - sys.path[0] = os.environ.has_key("GITPYTHONLIB") and \\\ - os.environ["GITPYTHONLIB"] or \\\ - "@@INSTLIBDIR@@"|' \ + sys.path.insert(0, os.getenv("GITPYTHONLIB",\ + "@@INSTLIBDIR@@"));|' \ -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \ [email protected] >$@+ && \ chmod +x $@+ && \Signature · 1 line
1.7.0.3.291.g5e4f6
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · David Aguilar
"
has_key" is a deprecated dictionary method in Python 2.6+. Simplify the sys.path manipulation for installed scripts by passing a default value toos.getenv().It looks like the old code was replacing sys.path[0] but you are prepending this. Doesn't that change also make a difference?
The original code replaced sys.path[0] which is '' (aka the current directory). It's a little odd to rely on the 0th element being something that is safe to remove.
By prepending the path we have the same intended effect without having to know that the 0th element is something that is safe to remove.
Does removing '' break relative imports? (It might...)
Due to the portability concerns with relative imports the recommendation is to always use absolute imports. Thus, this shouldn't hurt us in practice if we stick to absolute imports, but I figured I'd mention it as another reason why prepending might be preferred over replacing.
Signature · 1 line
David
Quoted 15 lines · David Aguilar
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · David Aguilar
"
has_key" is a deprecated dictionary method in Python 2.6+. Simplify the sys.path manipulation for installed scripts by passing a default value toos.getenv().It looks like the old code was replacing sys.path[0] but you are prepending this. Doesn't that change also make a difference?
The original code replaced sys.path[0] which is '' (aka the current directory). It's a little odd to rely on the 0th element being something that is safe to remove.
Quoted 5 lines
By prepending the path we have the same intended effect without having to know that the 0th element is something that is safe to remove.
Does removing '' break relative imports? (It might...)
That is exactly why I asked if it was an improvement that was not described in the log message.
I'll queue with Johan's Ack, perhaps rewording the message a bit. Thanks.
Hi,
Quoted 7 lines · David Aguilar
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · David Aguilar
"
has_key" is a deprecated dictionary method in Python 2.6+. Simplify the sys.path manipulation for installed scripts by passing a default value toos.getenv().
Quoted 7 lines
Quoted 2 lines
It looks like the old code was replacing sys.path[0] but you are prepending this. Doesn't that change also make a difference?
The original code replaced sys.path[0] which is '' (aka the current directory). It's a little odd to rely on the 0th element being something that is safe to remove.
more accurately, it's "directory containing the script that was used to invoke the Python interpreter":
http://docs.python.org/library/sys.html#sys.path
Signature · 2 lines
Cheers, Ray Chuan
Quoted 9 lines · David Aguilar
"
has_key" is a deprecated dictionary method in Python 2.6+. Simplify the sys.path manipulation for installed scripts by passing a default value toos.getenv().
SCRIPT_PYTHONis currently empty but this future-proofs us. It also fixes things for users who maintain local git forks with their ownSCRIPT_PYTHONadditions.Signed-off-by David Aguilar <[email protected]>
Signature · 2 lines
Johan Herland, <[email protected]> www.herland.net