{"thread":{"id":"23207","subject":"[PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","startedAt":"2010-03-28T00:45:12Z","lastAt":"2010-03-29T04:08:23Z","messageCount":6,"participants":["David Aguilar","Junio C Hamano","Tay Ray Chuan","Johan Herland"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"137985","messageId":"1269737112-21631-1-git-send-email-davvid@gmail.com","threadId":"23207","inReplyTo":null,"subject":"[PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-03-28T00:45:12Z","receivedAt":"2010-03-28T00:45:12Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"\"has_key\" is a deprecated dictionary method in Python 2.6+.\nSimplify the sys.path manipulation for installed scripts by\npassing a default value to os.getenv().\n\nSCRIPT_PYTHON is currently empty but this future-proofs us.\nIt also fixes things for users who maintain local git forks\nwith their own SCRIPT_PYTHON additions.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n Makefile |    5 ++---\n 1 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 3a6c6ea..806ccdf 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1609,9 +1609,8 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py\n \t    -e '}' \\\n \t    -e 's|^import sys.*|&; \\\\\\\n \t           import os; \\\\\\\n-\t           sys.path[0] = os.environ.has_key(\"GITPYTHONLIB\") and \\\\\\\n-\t                         os.environ[\"GITPYTHONLIB\"] or \\\\\\\n-\t                         \"@@INSTLIBDIR@@\"|' \\\n+\t           sys.path.insert(0, os.getenv(\"GITPYTHONLIB\",\\\n+\t                                        \"@@INSTLIBDIR@@\"));|' \\\n \t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n \t    $@.py >$@+ && \\\n \tchmod +x $@+ && \\\n-- \n1.7.0.3.291.g5e4f6\n"},{"id":"138015","messageId":"7vy6hc4d0h.fsf@alter.siamese.dyndns.org","threadId":"23207","inReplyTo":"1269737112-21631-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-28T16:38:54Z","receivedAt":"2010-03-28T16:38:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> \"has_key\" is a deprecated dictionary method in Python 2.6+.\n> Simplify the sys.path manipulation for installed scripts by\n> passing a default value to os.getenv().\n\nIt looks like the old code was replacing sys.path[0] but you are\nprepending this.  Doesn't that change also make a difference?\n\n> SCRIPT_PYTHON is currently empty but this future-proofs us.\n> It also fixes things for users who maintain local git forks\n> with their own SCRIPT_PYTHON additions.\n>\n> Signed-off-by: David Aguilar <davvid@gmail.com>\n> ---\n>  Makefile |    5 ++---\n>  1 files changed, 2 insertions(+), 3 deletions(-)\n>\n> diff --git a/Makefile b/Makefile\n> index 3a6c6ea..806ccdf 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1609,9 +1609,8 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py\n>  \t    -e '}' \\\n>  \t    -e 's|^import sys.*|&; \\\\\\\n>  \t           import os; \\\\\\\n> -\t           sys.path[0] = os.environ.has_key(\"GITPYTHONLIB\") and \\\\\\\n> -\t                         os.environ[\"GITPYTHONLIB\"] or \\\\\\\n> -\t                         \"@@INSTLIBDIR@@\"|' \\\n> +\t           sys.path.insert(0, os.getenv(\"GITPYTHONLIB\",\\\n> +\t                                        \"@@INSTLIBDIR@@\"));|' \\\n>  \t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n>  \t    $@.py >$@+ && \\\n>  \tchmod +x $@+ && \\\n> -- \n> 1.7.0.3.291.g5e4f6\n"},{"id":"138035","messageId":"20100328215442.GA31195@gmail.com","threadId":"23207","inReplyTo":"7vy6hc4d0h.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-03-28T21:54:43Z","receivedAt":"2010-03-28T21:54:43Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Sun, Mar 28, 2010 at 09:38:54AM -0700, Junio C Hamano wrote:\n> David Aguilar <davvid@gmail.com> writes:\n> \n> > \"has_key\" is a deprecated dictionary method in Python 2.6+.\n> > Simplify the sys.path manipulation for installed scripts by\n> > passing a default value to os.getenv().\n> \n> It looks like the old code was replacing sys.path[0] but you are\n> prepending this.  Doesn't that change also make a difference?\n\nThe original code replaced sys.path[0] which is ''\n(aka the current directory).  It's a little odd to\nrely on the 0th element being something that is safe\nto remove.\n\nBy prepending the path we have the same intended effect without\nhaving to know that the 0th element is something that is\nsafe to remove.\n\nDoes removing '' break relative imports? (It might...)\n\nDue to the portability concerns with relative imports the\nrecommendation is to always use absolute imports.  Thus, this\nshouldn't hurt us in practice if we stick to absolute imports,\nbut I figured I'd mention it as another reason why prepending\nmight be preferred over replacing.\n\n-- \n\t\tDavid\n"},{"id":"138038","messageId":"be6fef0d1003281723h4f8788bdi3c5baa3f92724c11@mail.gmail.com","threadId":"23207","inReplyTo":"20100328215442.GA31195@gmail.com","subject":"Re: [PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-03-29T00:23:41Z","receivedAt":"2010-03-29T00:23:41Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Mon, Mar 29, 2010 at 5:54 AM, David Aguilar <davvid@gmail.com> wrote:\n> On Sun, Mar 28, 2010 at 09:38:54AM -0700, Junio C Hamano wrote:\n>> David Aguilar <davvid@gmail.com> writes:\n>>\n>> > \"has_key\" is a deprecated dictionary method in Python 2.6+.\n>> > Simplify the sys.path manipulation for installed scripts by\n>> > passing a default value to os.getenv().\n>>\n>> It looks like the old code was replacing sys.path[0] but you are\n>> prepending this.  Doesn't that change also make a difference?\n>\n> The original code replaced sys.path[0] which is ''\n> (aka the current directory).  It's a little odd to\n> rely on the 0th element being something that is safe\n> to remove.\n\nmore accurately, it's \"directory containing the script that was used\nto invoke the Python interpreter\":\n\n  http://docs.python.org/library/sys.html#sys.path\n\n-- \nCheers,\nRay Chuan\n"},{"id":"138041","messageId":"201003290416.40774.johan@herland.net","threadId":"23207","inReplyTo":"1269737112-21631-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2010-03-29T02:16:40Z","receivedAt":"2010-03-29T02:16:40Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Sunday 28 March 2010, David Aguilar wrote:\n> \"has_key\" is a deprecated dictionary method in Python 2.6+.\n> Simplify the sys.path manipulation for installed scripts by\n> passing a default value to os.getenv().\n> \n> SCRIPT_PYTHON is currently empty but this future-proofs us.\n> It also fixes things for users who maintain local git forks\n> with their own SCRIPT_PYTHON additions.\n> \n> Signed-off-by: David Aguilar <davvid@gmail.com>\n\nAcked-by: Johan Herland <johan@herland.net>\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"138047","messageId":"7v8w9bkbwo.fsf@alter.siamese.dyndns.org","threadId":"23207","inReplyTo":"20100328215442.GA31195@gmail.com","subject":"Re: [PATCH] Makefile: Remove usage of deprecated Python \"has_key\" method","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-29T04:08:23Z","receivedAt":"2010-03-29T04:08:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> On Sun, Mar 28, 2010 at 09:38:54AM -0700, Junio C Hamano wrote:\n>> David Aguilar <davvid@gmail.com> writes:\n>> \n>> > \"has_key\" is a deprecated dictionary method in Python 2.6+.\n>> > Simplify the sys.path manipulation for installed scripts by\n>> > passing a default value to os.getenv().\n>> \n>> It looks like the old code was replacing sys.path[0] but you are\n>> prepending this.  Doesn't that change also make a difference?\n>\n> The original code replaced sys.path[0] which is ''\n> (aka the current directory).  It's a little odd to\n> rely on the 0th element being something that is safe\n> to remove.\n>\n> By prepending the path we have the same intended effect without\n> having to know that the 0th element is something that is\n> safe to remove.\n>\n> Does removing '' break relative imports? (It might...)\n\nThat is exactly why I asked if it was an improvement that was not\ndescribed in the log message.\n\nI'll queue with Johan's Ack, perhaps rewording the message a bit.\nThanks.\n"}]}