git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Python scripts audited for minimum compatible version and checks added.

From
PWPete Wyckoff <pw@padd.com>
Date
Dec 24, 2012, 13:36 UTC
Message-ID
<20121224133649.GA1400@padd.com>
In-Reply-To
<20121220141855.05DAA44105@snark.thyrsus.com>
esr@thyrsus.com wrote on Thu, 20 Dec 2012 09:13 -0500:
Show 14 quoted lines
> diff --git a/git-p4.py b/git-p4.py
> index 551aec9..ec060b4 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -12,6 +12,11 @@ import optparse, sys, os, marshal, subprocess, shelve
>  import tempfile, getopt, os.path, time, platform
>  import re, shutil
>  
> +if sys.hexversion < 0x02040000:
> +    # The limiter is the subprocess module
> +    sys.stderr.write("git-p4.py: requires Python 2.4 or later.")
> +    sys.exit(1)
> +
>  verbose = False

If 2.3 does not have the subprocess module, this script will fail at the import, and not run your version test.

All the uses of sys.stderr.write() should probably include a newline. Presumably you used write instead of print to avoid 2to3 differences.

The name of this particular script, as users would type it, is "git p4"; no dash and no ".py".

Many of your changes have these three problems; I just picked on my favorite one.

Show 13 quoted lines
> diff --git a/git-remote-testgit.py b/git-remote-testgit.py
> index 5f3ebd2..22d2eb6 100644
> --- a/git-remote-testgit.py
> +++ b/git-remote-testgit.py
> @@ -31,6 +31,11 @@ from git_remote_helpers.git.exporter import GitExporter
>  from git_remote_helpers.git.importer import GitImporter
>  from git_remote_helpers.git.non_local import NonLocalGit
>  
> +if sys.hexversion < 0x01050200:
> +    # os.makedirs() is the limiter
> +    sys.stderr.write("git-remote-testgit.py: requires Python 1.5.2 or later.")
> +    sys.exit(1)
> +

This one, though, is a bit of a lie because git_remote_helpers needs 2.4, and you add that version enforcement in the library.

I assume what you're trying to do here is to make the version-related failures more explicit, rather than have users parse an ImportError traceback, e.g. That seems somewhat useful for people with ancient installs.

But what about the high-end of the version range? I'm pretty sure most of these scripts will throw syntax errors on >= 3.0, how should we catch that before users see it?

		-- Pete
Previous: Manlio PerilloNext: Eric S. Raymond
Message 9 of 12 in “Python scripts audited for minimum compatible version and checks added.”
  1. Python scripts audited for minimum compatible version and checks added.Eric S. Raymond, Dec 20, 2012
  2. Jeff KingDec 20, 2012
  3. Eric S. RaymondDec 20, 2012
  4. Junio C HamanoDec 20, 2012
  5. Junio C HamanoDec 21, 2012
  6. Junio C HamanoDec 24, 2012
  7. Eric S. RaymondDec 24, 2012
  8. Manlio PerilloDec 21, 2012
  9. Pete WyckoffDec 24, 2012
  10. Eric S. RaymondDec 24, 2012
  11. Junio C HamanoDec 24, 2012
  12. Eric S. RaymondDec 24, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.