michael@0: # High Priority michael@0: michael@0: - Figure out the script story on the various platforms. On Windows, look into michael@0: the launcher thing that effbot has. Unix, don't install the script my michael@0: default. They can always do "python -m which ..." with Python >= 2.4. michael@0: Suggest an alias that some folks might want to use for that. michael@0: michael@0: michael@0: # Medium Priority michael@0: michael@0: - define __all__? michael@0: - improve test suite michael@0: - test with other versions of Python michael@0: - get the PATHEXT attached extension to reflect the actual canonical michael@0: case of file matches on Windows, currently the extension from PATHEXT michael@0: is always uppercase michael@0: - What to do with Change 145624 by shanec. It is a bit of a michael@0: bastardization. Maybe allow this with a special option to allow the change michael@0: in semantics. michael@0: michael@0: > Change 145624 by shanec@shanec-ocelotl on 2005/05/24 16:51:55 michael@0: > michael@0: > make which work better on OSX michael@0: > - add support for searching /Applications and /Network/Applications michael@0: > - add support for .app bundles michael@0: > michael@0: > Affected files ... michael@0: > michael@0: > ... //depot/main/Apps/Komodo-devel/src/python-sitelib/which.py#7 edit michael@0: > michael@0: > Differences ... michael@0: > michael@0: > ==== //depot/main/Apps/Komodo-devel/src/python-sitelib/which.py#7 (text) ==== michael@0: > michael@0: > @@ -126,10 +126,11 @@ michael@0: > sys.stderr.write("duplicate: %s (%s)\n" % potential) michael@0: > return None michael@0: > else: michael@0: > - if not stat.S_ISREG(os.stat(potential[0]).st_mode): michael@0: > + darwinApp = sys.platform == 'darwin' and potential[0][-4:]=='.app' michael@0: > + if not darwinApp and not stat.S_ISREG(os.stat(potential[0]).st_mode): michael@0: > if verbose: michael@0: > sys.stderr.write("not a regular file: %s (%s)\n" % potential) michael@0: > - elif not os.access(potential[0], os.X_OK): michael@0: > + elif not darwinApp and not os.access(potential[0], os.X_OK): michael@0: > if verbose: michael@0: > sys.stderr.write("no executable access: %s (%s)\n"\ michael@0: > % potential) michael@0: > @@ -166,6 +167,9 @@ michael@0: > path = os.environ.get("PATH", "").split(os.pathsep) michael@0: > if sys.platform.startswith("win"): michael@0: > path.insert(0, os.curdir) # implied by Windows shell michael@0: > + if sys.platform == 'darwin': michael@0: > + path.insert(0, '/Network/Applications') michael@0: > + path.insert(0, '/Applications') michael@0: > else: michael@0: > usingGivenPath = 1 michael@0: > michael@0: > @@ -182,6 +186,9 @@ michael@0: > exts = ['.COM', '.EXE', '.BAT'] michael@0: > elif not isinstance(exts, list): michael@0: > raise TypeError("'exts' argument must be a list or None") michael@0: > + elif sys.platform == 'darwin': michael@0: > + if exts is None: michael@0: > + exts = ['.app'] michael@0: > else: michael@0: > if exts is not None: michael@0: > raise WhichError("'exts' argument is not supported on "\ michael@0: > @@ -202,7 +209,8 @@ michael@0: > for ext in ['']+exts: michael@0: > absName = os.path.abspath( michael@0: > os.path.normpath(os.path.join(dirName, command+ext))) michael@0: > - if os.path.isfile(absName): michael@0: > + if os.path.isfile(absName) or (sys.platform == 'darwin' and \ michael@0: > + absName[-4:]=='.app' and os.path.isdir(absName)): michael@0: > if usingGivenPath: michael@0: > fromWhere = "from given path element %d" % i michael@0: > elif not sys.platform.startswith("win"): michael@0: michael@0: Here is a start with slight improvements: michael@0: michael@0: > Index: which.py michael@0: > =================================================================== michael@0: > --- which.py (revision 270) michael@0: > +++ which.py (working copy) michael@0: > @@ -126,9 +126,18 @@ michael@0: > sys.stderr.write("duplicate: %s (%s)\n" % potential) michael@0: > return None michael@0: > else: michael@0: > - if not stat.S_ISREG(os.stat(potential[0]).st_mode): michael@0: > + st_mode = os.stat(potential[0]).st_mode michael@0: > + isMacAppBundle = sys.platform == "darwin" \ michael@0: > + and potential[0].endswith(".app") \ michael@0: > + and stat.S_ISDIR(st_mode) michael@0: > + if not isMacAppBundle and not stat.S_ISREG(st_mode): michael@0: > if verbose: michael@0: > - sys.stderr.write("not a regular file: %s (%s)\n" % potential) michael@0: > + if sys.platform == "darwin": michael@0: > + sys.stderr.write("not a regular file or .app bundle: " michael@0: > + "%s (%s)\n" % potential) michael@0: > + else: michael@0: > + sys.stderr.write("not a regular file: %s (%s)\n" michael@0: > + % potential) michael@0: > elif not os.access(potential[0], os.X_OK): michael@0: > if verbose: michael@0: > sys.stderr.write("no executable access: %s (%s)\n"\ michael@0: michael@0: michael@0: # Low Priority michael@0: michael@0: - have a version for pre-generators (i.e. Python 2.1) michael@0: - add a "logging" interface michael@0: