{"thread":{"id":"24058","subject":"[PATCH next 1/2] Makefile: add PYTHON_PATH to GIT-BUILD-OPTIONS","startedAt":"2010-06-09T21:23:59Z","lastAt":"2010-06-11T13:28:48Z","messageCount":12,"participants":["Brandon Casey","Sverre Rabbelier","Johan Herland","Michael J Gruber","David Ripton"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"143381","messageId":"nduJYSHPH3U3cC4hTqPaVi-iLDqB7pemU3zevJMNRmyDsRKmtq_gVu-G9W-She7bPSFG9LafRk0@cipher.nrlssc.navy.mil","threadId":"24058","inReplyTo":null,"subject":"[PATCH next 1/2] Makefile: add PYTHON_PATH to GIT-BUILD-OPTIONS","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2010-06-09T21:23:59Z","receivedAt":"2010-06-09T21:23:59Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nThe PYTHON_PATH environment variable is not set when running test scripts\nmanually i.e. when not using 'make test'.  Scripts which attempt to use\nthis variable will fail.  So add it to the list of variables written to\nthe GIT-BUILD-OPTIONS file so that the test suite will import it when\nrunning the test scripts.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n Makefile |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 34b7dd5..b529340 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1949,6 +1949,7 @@ GIT-CFLAGS: FORCE\n GIT-BUILD-OPTIONS: FORCE\n \t@echo SHELL_PATH=\\''$(subst ','\\'',$(SHELL_PATH_SQ))'\\' >$@\n \t@echo PERL_PATH=\\''$(subst ','\\'',$(PERL_PATH_SQ))'\\' >>$@\n+\t@echo PYTHON_PATH=\\''$(subst ','\\'',$(PYTHON_PATH_SQ))'\\' >>$@\n \t@echo DIFF=\\''$(subst ','\\'',$(subst ','\\'',$(DIFF)))'\\' >>$@\n \t@echo TAR=\\''$(subst ','\\'',$(subst ','\\'',$(TAR)))'\\' >>$@\n \t@echo NO_CURL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_CURL)))'\\' >>$@\n-- \n1.6.6.2\n"},{"id":"143382","messageId":"nduJYSHPH3U3cC4hTqPaVieVkcHeedXMjA92T_KB9XTSNMZ0NeKHomHE5LPZ65BzOnHb--wYKXY@cipher.nrlssc.navy.mil","threadId":"24058","inReplyTo":"nduJYSHPH3U3cC4hTqPaVi-iLDqB7pemU3zevJMNRmyDsRKmtq_gVu-G9W-She7bPSFG9LafRk0@cipher.nrlssc.navy.mil","subject":"[PATCH next 2/2] Remove python 2.5'isms","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2010-06-09T21:24:00Z","receivedAt":"2010-06-09T21:24:00Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nThe following python 2.5 features were worked around:\n\n    * the hashlib module was replaced with the sha module\n    * the 'any' built-in method was replaced with a 'for' loop\n    * a conditional expression was replaced with an 'if' statement\n    * the subprocess.check_call method was replaced by a call to\n      subprocess.Popen followed by a call to subprocess.wait with a\n      check of its return status\n\nThese changes allow the python infrastructure to be used with python 2.4\nwhich is distributed with RedHat's RHEL 5, for example.\n\nt5800 was updated to check for python >= 2.4 to reflect these changes.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n git-remote-testgit.py               |    9 ++++++---\n git_remote_helpers/git/exporter.py  |    4 +++-\n git_remote_helpers/git/importer.py  |    4 +++-\n git_remote_helpers/git/non_local.py |   16 ++++++++++++----\n git_remote_helpers/git/repo.py      |    9 +++++++--\n t/t5800-remote-helpers.sh           |    4 ++--\n 6 files changed, 33 insertions(+), 13 deletions(-)\n\ndiff --git a/git-remote-testgit.py b/git-remote-testgit.py\nindex 9253922..6356d48 100644\n--- a/git-remote-testgit.py\n+++ b/git-remote-testgit.py\n@@ -1,6 +1,6 @@\n #!/usr/bin/env python\n \n-import hashlib\n+import sha\n import sys\n import os\n sys.path.insert(0, os.getenv(\"GITPYTHONLIB\",\".\"))\n@@ -19,7 +19,7 @@ def get_repo(alias, url):\n     repo.get_revs()\n     repo.get_head()\n \n-    hasher = hashlib.sha1()\n+    hasher = sha.new()\n     hasher.update(repo.path)\n     repo.hash = hasher.hexdigest()\n \n@@ -133,7 +133,10 @@ def do_export(repo, args):\n \n     path = os.path.join(dirname, 'testgit.marks')\n     print path\n-    print path if os.path.exists(path) else \"\"\n+    if os.path.exists(path):\n+        print path\n+    else:\n+        print \"\"\n     sys.stdout.flush()\n \n     update_local_repo(repo)\ndiff --git a/git_remote_helpers/git/exporter.py b/git_remote_helpers/git/exporter.py\nindex dfaab00..f40f9d6 100644\n--- a/git_remote_helpers/git/exporter.py\n+++ b/git_remote_helpers/git/exporter.py\n@@ -48,4 +48,6 @@ class GitExporter(object):\n \n         args = [\"sed\", \"s_refs/heads/_\" + self.repo.prefix + \"_g\"]\n \n-        subprocess.check_call(args, stdin=p1.stdout)\n+        child = subprocess.Popen(args, stdin=p1.stdout)\n+        if child.wait() != 0:\n+            raise CalledProcessError\ndiff --git a/git_remote_helpers/git/importer.py b/git_remote_helpers/git/importer.py\nindex af2919d..70a7127 100644\n--- a/git_remote_helpers/git/importer.py\n+++ b/git_remote_helpers/git/importer.py\n@@ -35,4 +35,6 @@ class GitImporter(object):\n         if os.path.exists(path):\n             args.append(\"--import-marks=\" + path)\n \n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\ndiff --git a/git_remote_helpers/git/non_local.py b/git_remote_helpers/git/non_local.py\nindex d75ef8f..f27389b 100644\n--- a/git_remote_helpers/git/non_local.py\n+++ b/git_remote_helpers/git/non_local.py\n@@ -29,7 +29,9 @@ class NonLocalGit(object):\n         os.makedirs(path)\n         args = [\"git\", \"clone\", \"--bare\", \"--quiet\", self.repo.gitpath, path]\n \n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n \n         return path\n \n@@ -43,10 +45,14 @@ class NonLocalGit(object):\n             die(\"could not find repo at %s\", path)\n \n         args = [\"git\", \"--git-dir=\" + path, \"fetch\", \"--quiet\", self.repo.gitpath]\n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n \n         args = [\"git\", \"--git-dir=\" + path, \"update-ref\", \"refs/heads/master\", \"FETCH_HEAD\"]\n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n \n     def push(self, base):\n         \"\"\"Pushes from the non-local repo to base.\n@@ -58,4 +64,6 @@ class NonLocalGit(object):\n             die(\"could not find repo at %s\", path)\n \n         args = [\"git\", \"--git-dir=\" + path, \"push\", \"--quiet\", self.repo.gitpath]\n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\ndiff --git a/git_remote_helpers/git/repo.py b/git_remote_helpers/git/repo.py\nindex 82d5f78..58e1cdb 100644\n--- a/git_remote_helpers/git/repo.py\n+++ b/git_remote_helpers/git/repo.py\n@@ -19,7 +19,10 @@ def is_remote(url):\n \n     prefixes = [\"http\", \"file\", \"git\"]\n \n-    return any(url.startswith(i) for i in prefixes)\n+    for prefix in prefixes:\n+        if url.startswith(prefix):\n+            return True\n+    return False\n \n class GitRepo(object):\n     \"\"\"Repo object representing a repo.\n@@ -50,7 +53,9 @@ class GitRepo(object):\n         path = \".cached_revs\"\n         ofile = open(path, \"w\")\n \n-        subprocess.check_call(args, stdout=ofile)\n+        child = subprocess.Popen(args, stdout=ofile)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n         output = open(path).readlines()\n         self.revmap = dict(sanitize(i) for i in output)\n         if \"HEAD\" in self.revmap:\ndiff --git a/t/t5800-remote-helpers.sh b/t/t5800-remote-helpers.sh\nindex 22c7df4..4ee7b65 100755\n--- a/t/t5800-remote-helpers.sh\n+++ b/t/t5800-remote-helpers.sh\n@@ -9,13 +9,13 @@ test_description='Test remote-helper import and export commands'\n \n if test_have_prereq PYTHON && \"$PYTHON_PATH\" -c '\n import sys\n-if sys.hexversion < 0x02050000:\n+if sys.hexversion < 0x02040000:\n     sys.exit(1)\n '\n then\n \t:\n else\n-\tsay 'skipping git remote-testgit tests: requires Python 2.5 or newer'\n+\tsay 'skipping git remote-testgit tests: requires Python 2.4 or newer'\n \ttest_done\n fi\n \n-- \n1.6.6.2\n"},{"id":"143383","messageId":"AANLkTikmdsJwy06WuRwpLEKzZE45VZcvPDDxnW1OCb8K@mail.gmail.com","threadId":"24058","inReplyTo":"nduJYSHPH3U3cC4hTqPaVieVkcHeedXMjA92T_KB9XTSNMZ0NeKHomHE5LPZ65BzOnHb--wYKXY@cipher.nrlssc.navy.mil","subject":"Re: [PATCH next 2/2] Remove python 2.5'isms","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-06-09T21:28:27Z","receivedAt":"2010-06-09T21:28:27Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Jun 9, 2010 at 23:24, Brandon Casey <casey@nrlssc.navy.mil> wrote:\n> The following python 2.5 features were worked around:\n\nThanks for fixing this, although it makes me sad to see the code\nuglify the way it has :P. I guess that's the pain of backwards\ncompatibility.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"143385","messageId":"201006100040.54375.johan@herland.net","threadId":"24058","inReplyTo":"AANLkTikmdsJwy06WuRwpLEKzZE45VZcvPDDxnW1OCb8K@mail.gmail.com","subject":"Re: [PATCH next 2/2] Remove python 2.5'isms","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2010-06-09T22:40:54Z","receivedAt":"2010-06-09T22:40:54Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Wednesday 09 June 2010, Sverre Rabbelier wrote:\n> On Wed, Jun 9, 2010 at 23:24, Brandon Casey <casey@nrlssc.navy.mil> wrote:\n> > The following python 2.5 features were worked around:\n>\n> Thanks for fixing this, although it makes me sad to see the code\n> uglify the way it has :P. I guess that's the pain of backwards\n> compatibility.\n\nI agree with Sverre's painful acceptance, but I believe something must be \ndone with the s/hashlib/sha/ changes.\n\nOn my Python v2.6.5. I get the following:\n\n>>> import sha\n__main__:1: DeprecationWarning: the sha module is deprecated; use the \nhashlib module instead\n\nThis is added to the output of every python program that imports sha. I \nbelieve we should really try to use the hashlib module when available, and \nonly fall back to sha when necessary. Please use something like this \ninstead:\n\n  # hashlib is only available in python >= 2.5 \n  try: \n      import hashlib \n      _digest = hashlib.sha1 \n  except ImportError: \n      import sha\n      _digest = sha.sha \n\nso that we don't get the hideous DeprecationWarning.\n\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"143386","messageId":"AANLkTilCVoLJQaGroSFWx46KclPj_PBfNYH6-ghoY0N_@mail.gmail.com","threadId":"24058","inReplyTo":"201006100040.54375.johan@herland.net","subject":"Re: [PATCH next 2/2] Remove python 2.5'isms","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-06-09T22:46:20Z","receivedAt":"2010-06-09T22:46:20Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Jun 10, 2010 at 00:40, Johan Herland <johan@herland.net> wrote:\n>  # hashlib is only available in python >= 2.5\n>  try:\n>      import hashlib\n>      _digest = hashlib.sha1\n>  except ImportError:\n>      import sha\n>      _digest = sha.sha\n>\n> so that we don't get the hideous DeprecationWarning.\n\nThis is exactly what I meant to suggest earlier, but I didn't know the\nappropriate routine in python 2.4, thanks Johan.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"143388","messageId":"5ep6Hc9Nl3QLKwV46xET5ZLhqo2uNlnUL1-nNsG9p2IWyX-odykArvT4ontRdeBUA9ouCPQGFwQ@cipher.nrlssc.navy.mil","threadId":"24058","inReplyTo":"201006100040.54375.johan@herland.net","subject":"[PATCH next 2/2 v2] Remove python 2.5'isms","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2010-06-10T00:24:54Z","receivedAt":"2010-06-10T00:24:54Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nThe following python 2.5 features were worked around:\n\n    * the sha module is used as a fallback when the hashlib module is\n      not available\n    * the 'any' built-in method was replaced with a 'for' loop\n    * a conditional expression was replaced with an 'if' statement\n    * the subprocess.check_call method was replaced by a call to\n      subprocess.Popen followed by a call to subprocess.wait with a\n      check of its return status\n\nThese changes allow the python infrastructure to be used with python 2.4\nwhich is distributed with RedHat's RHEL 5, for example.\n\nt5800 was updated to check for python >= 2.4 to reflect these changes.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n\n\nOn 06/09/2010 05:40 PM, Johan Herland wrote:\n\n> On my Python v2.6.5. I get the following:\n> \n>>>> import sha\n> __main__:1: DeprecationWarning: the sha module is deprecated; use the \n> hashlib module instead\n> \n> This is added to the output of every python program that imports sha. I \n> believe we should really try to use the hashlib module when available, and \n> only fall back to sha when necessary. Please use something like this \n> instead:\n> \n>   # hashlib is only available in python >= 2.5 \n>   try: \n>       import hashlib \n>       _digest = hashlib.sha1 \n>   except ImportError: \n>       import sha\n>       _digest = sha.sha \n> \n> so that we don't get the hideous DeprecationWarning.\n\nLike this? ...\n\n\n git-remote-testgit.py               |   15 ++++++++++++---\n git_remote_helpers/git/exporter.py  |    4 +++-\n git_remote_helpers/git/importer.py  |    4 +++-\n git_remote_helpers/git/non_local.py |   16 ++++++++++++----\n git_remote_helpers/git/repo.py      |    9 +++++++--\n t/t5800-remote-helpers.sh           |    4 ++--\n 6 files changed, 39 insertions(+), 13 deletions(-)\n\ndiff --git a/git-remote-testgit.py b/git-remote-testgit.py\nindex 9253922..df9d512 100644\n--- a/git-remote-testgit.py\n+++ b/git-remote-testgit.py\n@@ -1,6 +1,12 @@\n #!/usr/bin/env python\n \n-import hashlib\n+# hashlib is only available in python >= 2.5\n+try:\n+    import hashlib\n+    _digest = hashlib.sha1\n+except ImportError:\n+    import sha\n+    _digest = sha.new\n import sys\n import os\n sys.path.insert(0, os.getenv(\"GITPYTHONLIB\",\".\"))\n@@ -19,7 +25,7 @@ def get_repo(alias, url):\n     repo.get_revs()\n     repo.get_head()\n \n-    hasher = hashlib.sha1()\n+    hasher = _digest()\n     hasher.update(repo.path)\n     repo.hash = hasher.hexdigest()\n \n@@ -133,7 +139,10 @@ def do_export(repo, args):\n \n     path = os.path.join(dirname, 'testgit.marks')\n     print path\n-    print path if os.path.exists(path) else \"\"\n+    if os.path.exists(path):\n+        print path\n+    else:\n+        print \"\"\n     sys.stdout.flush()\n \n     update_local_repo(repo)\ndiff --git a/git_remote_helpers/git/exporter.py b/git_remote_helpers/git/exporter.py\nindex dfaab00..f40f9d6 100644\n--- a/git_remote_helpers/git/exporter.py\n+++ b/git_remote_helpers/git/exporter.py\n@@ -48,4 +48,6 @@ class GitExporter(object):\n \n         args = [\"sed\", \"s_refs/heads/_\" + self.repo.prefix + \"_g\"]\n \n-        subprocess.check_call(args, stdin=p1.stdout)\n+        child = subprocess.Popen(args, stdin=p1.stdout)\n+        if child.wait() != 0:\n+            raise CalledProcessError\ndiff --git a/git_remote_helpers/git/importer.py b/git_remote_helpers/git/importer.py\nindex af2919d..70a7127 100644\n--- a/git_remote_helpers/git/importer.py\n+++ b/git_remote_helpers/git/importer.py\n@@ -35,4 +35,6 @@ class GitImporter(object):\n         if os.path.exists(path):\n             args.append(\"--import-marks=\" + path)\n \n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\ndiff --git a/git_remote_helpers/git/non_local.py b/git_remote_helpers/git/non_local.py\nindex d75ef8f..f27389b 100644\n--- a/git_remote_helpers/git/non_local.py\n+++ b/git_remote_helpers/git/non_local.py\n@@ -29,7 +29,9 @@ class NonLocalGit(object):\n         os.makedirs(path)\n         args = [\"git\", \"clone\", \"--bare\", \"--quiet\", self.repo.gitpath, path]\n \n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n \n         return path\n \n@@ -43,10 +45,14 @@ class NonLocalGit(object):\n             die(\"could not find repo at %s\", path)\n \n         args = [\"git\", \"--git-dir=\" + path, \"fetch\", \"--quiet\", self.repo.gitpath]\n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n \n         args = [\"git\", \"--git-dir=\" + path, \"update-ref\", \"refs/heads/master\", \"FETCH_HEAD\"]\n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n \n     def push(self, base):\n         \"\"\"Pushes from the non-local repo to base.\n@@ -58,4 +64,6 @@ class NonLocalGit(object):\n             die(\"could not find repo at %s\", path)\n \n         args = [\"git\", \"--git-dir=\" + path, \"push\", \"--quiet\", self.repo.gitpath]\n-        subprocess.check_call(args)\n+        child = subprocess.Popen(args)\n+        if child.wait() != 0:\n+            raise CalledProcessError\ndiff --git a/git_remote_helpers/git/repo.py b/git_remote_helpers/git/repo.py\nindex 82d5f78..58e1cdb 100644\n--- a/git_remote_helpers/git/repo.py\n+++ b/git_remote_helpers/git/repo.py\n@@ -19,7 +19,10 @@ def is_remote(url):\n \n     prefixes = [\"http\", \"file\", \"git\"]\n \n-    return any(url.startswith(i) for i in prefixes)\n+    for prefix in prefixes:\n+        if url.startswith(prefix):\n+            return True\n+    return False\n \n class GitRepo(object):\n     \"\"\"Repo object representing a repo.\n@@ -50,7 +53,9 @@ class GitRepo(object):\n         path = \".cached_revs\"\n         ofile = open(path, \"w\")\n \n-        subprocess.check_call(args, stdout=ofile)\n+        child = subprocess.Popen(args, stdout=ofile)\n+        if child.wait() != 0:\n+            raise CalledProcessError\n         output = open(path).readlines()\n         self.revmap = dict(sanitize(i) for i in output)\n         if \"HEAD\" in self.revmap:\ndiff --git a/t/t5800-remote-helpers.sh b/t/t5800-remote-helpers.sh\nindex 22c7df4..4ee7b65 100755\n--- a/t/t5800-remote-helpers.sh\n+++ b/t/t5800-remote-helpers.sh\n@@ -9,13 +9,13 @@ test_description='Test remote-helper import and export commands'\n \n if test_have_prereq PYTHON && \"$PYTHON_PATH\" -c '\n import sys\n-if sys.hexversion < 0x02050000:\n+if sys.hexversion < 0x02040000:\n     sys.exit(1)\n '\n then\n \t:\n else\n-\tsay 'skipping git remote-testgit tests: requires Python 2.5 or newer'\n+\tsay 'skipping git remote-testgit tests: requires Python 2.4 or newer'\n \ttest_done\n fi\n \n-- \n1.6.6.2\n"},{"id":"143395","messageId":"AANLkTimY0lMz32ZfxKMRF1YW0SFDNnDFUE3_dA5-Ki-6@mail.gmail.com","threadId":"24058","inReplyTo":"5ep6Hc9Nl3QLKwV46xET5ZLhqo2uNlnUL1-nNsG9p2IWyX-odykArvT4ontRdeBUA9ouCPQGFwQ@cipher.nrlssc.navy.mil","subject":"Re: [PATCH next 2/2 v2] Remove python 2.5'isms","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-06-10T07:13:02Z","receivedAt":"2010-06-10T07:13:02Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Jun 10, 2010 at 02:24, Brandon Casey <casey@nrlssc.navy.mil> wrote:\n> Like this? ...\n\nAssuming it does the right thing (can't test right now), yes :).\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"143397","messageId":"4C1094BF.5070907@drmicha.warpmail.net","threadId":"24058","inReplyTo":"AANLkTikmdsJwy06WuRwpLEKzZE45VZcvPDDxnW1OCb8K@mail.gmail.com","subject":"Re: [PATCH next 2/2] Remove python 2.5'isms","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-06-10T07:31:11Z","receivedAt":"2010-06-10T07:31:11Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Sverre Rabbelier venit, vidit, dixit 09.06.2010 23:28:\n> Heya,\n> \n> On Wed, Jun 9, 2010 at 23:24, Brandon Casey <casey@nrlssc.navy.mil> wrote:\n>> The following python 2.5 features were worked around:\n> \n> Thanks for fixing this, although it makes me sad to see the code\n> uglify the way it has :P. I guess that's the pain of backwards\n> compatibility.\n> \n\nI doesn't need to be ugly. Why not put the Popen thing in a def\nsomewhere? Is there any remaining uglyness besides this:\n\n-    return any(url.startswith(i) for i in prefixes)\n+    for prefix in prefixes:\n+        if url.startswith(prefix):\n+            return True\n+    return False\n\nPythonish version:\n-    return any(url.startswith(i) for i in prefixes)\n+    return True in (url.startswith(i) for i in prefixes)\n\nNote that due to the use of an iterator (which P2.4 has) rather than a\nlist or set, the expression is just as efficient, i.e. calls\nstartswith() only as often as necessary.\n\nMichael\n"},{"id":"143398","messageId":"AANLkTimLiLfGAMLp0n86eCIQFViu4veu0aTL6yuA_8f1@mail.gmail.com","threadId":"24058","inReplyTo":"4C1094BF.5070907@drmicha.warpmail.net","subject":"Re: [PATCH next 2/2] Remove python 2.5'isms","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-06-10T07:35:48Z","receivedAt":"2010-06-10T07:35:48Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Jun 10, 2010 at 09:31, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n> Note that due to the use of an iterator (which P2.4 has) rather than a\n> list or set, the expression is just as efficient, i.e. calls\n> startswith() only as often as necessary.\n\nI like that version a lot better, thanks. And I agree, the check_call\nreplacement code should just be put into it's own function in a\nsimilar way, and we should use subprocess if it is available.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"143409","messageId":"4C10B02F.9050107@drmicha.warpmail.net","threadId":"24058","inReplyTo":"5ep6Hc9Nl3QLKwV46xET5ZLhqo2uNlnUL1-nNsG9p2IWyX-odykArvT4ontRdeBUA9ouCPQGFwQ@cipher.nrlssc.navy.mil","subject":"Re: [PATCH next 2/2 v2] Remove python 2.5'isms","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-06-10T09:28:15Z","receivedAt":"2010-06-10T09:28:15Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Brandon Casey venit, vidit, dixit 10.06.2010 02:24:\n> From: Brandon Casey <drafnel@gmail.com>\n> \n> The following python 2.5 features were worked around:\n> \n>     * the sha module is used as a fallback when the hashlib module is\n>       not available\n>     * the 'any' built-in method was replaced with a 'for' loop\n>     * a conditional expression was replaced with an 'if' statement\n>     * the subprocess.check_call method was replaced by a call to\n>       subprocess.Popen followed by a call to subprocess.wait with a\n>       check of its return status\n> \n> These changes allow the python infrastructure to be used with python 2.4\n> which is distributed with RedHat's RHEL 5, for example.\n> \n> t5800 was updated to check for python >= 2.4 to reflect these changes.\n> \n> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n> ---\n> \n> \n> On 06/09/2010 05:40 PM, Johan Herland wrote:\n> \n>> On my Python v2.6.5. I get the following:\n>>\n>>>>> import sha\n>> __main__:1: DeprecationWarning: the sha module is deprecated; use the \n>> hashlib module instead\n>>\n>> This is added to the output of every python program that imports sha. I \n>> believe we should really try to use the hashlib module when available, and \n>> only fall back to sha when necessary. Please use something like this \n>> instead:\n>>\n>>   # hashlib is only available in python >= 2.5 \n>>   try: \n>>       import hashlib \n>>       _digest = hashlib.sha1 \n>>   except ImportError: \n>>       import sha\n>>       _digest = sha.sha \n>>\n>> so that we don't get the hideous DeprecationWarning.\n> \n> Like this? ...\n> \n> \n>  git-remote-testgit.py               |   15 ++++++++++++---\n>  git_remote_helpers/git/exporter.py  |    4 +++-\n>  git_remote_helpers/git/importer.py  |    4 +++-\n>  git_remote_helpers/git/non_local.py |   16 ++++++++++++----\n>  git_remote_helpers/git/repo.py      |    9 +++++++--\n>  t/t5800-remote-helpers.sh           |    4 ++--\n>  6 files changed, 39 insertions(+), 13 deletions(-)\n> \n> diff --git a/git-remote-testgit.py b/git-remote-testgit.py\n> index 9253922..df9d512 100644\n> --- a/git-remote-testgit.py\n> +++ b/git-remote-testgit.py\n> @@ -1,6 +1,12 @@\n>  #!/usr/bin/env python\n>  \n> -import hashlib\n> +# hashlib is only available in python >= 2.5\n> +try:\n> +    import hashlib\n> +    _digest = hashlib.sha1\n> +except ImportError:\n> +    import sha\n> +    _digest = sha.new\n>  import sys\n>  import os\n>  sys.path.insert(0, os.getenv(\"GITPYTHONLIB\",\".\"))\n\nDoesn't P2.4 have\n\n\tfrom hashlib import sha1 as _digest\n\netc.? I haven't checked for \"as\".\n\nMichael\n"},{"id":"143447","messageId":"20100610154114.GC31213@vidar.dreamhost.com","threadId":"24058","inReplyTo":"4C10B02F.9050107@drmicha.warpmail.net","subject":"Re: [PATCH next 2/2 v2] Remove python 2.5'isms","fromName":"David Ripton","fromEmail":"dripton@ripton.net","sentAt":"2010-06-10T15:41:14Z","receivedAt":"2010-06-10T15:41:14Z","isPatch":true,"sender":{"key":"dripton@ripton.net","avatar":"https://avatars.githubusercontent.com/u/153528?v=4"},"body":"On 2010.06.10 11:28:15 +0200, Michael J Gruber wrote:\n> Doesn't P2.4 have\n> \n> \tfrom hashlib import sha1 as _digest\n> \n> etc.? I haven't checked for \"as\".\n\nHashlib was new in Python 2.5.  See the note at the top of:\nhttp://docs.python.org/library/hashlib.html\n\nYou may have hashlib in your Python 2.4, but if so it's a third-party\nmodule, not part of the standard library.  You shouldn't rely on\neveryone having it, when it's so easy to fallback to the sha module.\n\n\"import foo as bar\" was added in Python 2.0.  \"as\" became a reserved\nword in Python 2.6.\n\n-- \nDavid Ripton    dripton@ripton.net\n"},{"id":"143506","messageId":"4C123A10.6050103@drmicha.warpmail.net","threadId":"24058","inReplyTo":"20100610154114.GC31213@vidar.dreamhost.com","subject":"Re: [PATCH next 2/2 v2] Remove python 2.5'isms","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-06-11T13:28:48Z","receivedAt":"2010-06-11T13:28:48Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"David Ripton venit, vidit, dixit 10.06.2010 17:41:\n> On 2010.06.10 11:28:15 +0200, Michael J Gruber wrote:\n>> Doesn't P2.4 have\n>>\n>> \tfrom hashlib import sha1 as _digest\n>>\n>> etc.? I haven't checked for \"as\".\n> \n> Hashlib was new in Python 2.5.  See the note at the top of:\n> http://docs.python.org/library/hashlib.html\n> \n> You may have hashlib in your Python 2.4, but if so it's a third-party\n> module, not part of the standard library.  You shouldn't rely on\n> everyone having it, when it's so easy to fallback to the sha module.\n\nWell sure, that's why we need the try/except's.\n> \n> \"import foo as bar\" was added in Python 2.0.  \"as\" became a reserved\n> word in Python 2.6.\n\nThanks!. Then we can use the clean version as suggested above (inside\ntry/except).\n\nMichael\n"}]}