From b1069dec00d073c3fa156b5f05be1e95f2594972 Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 21 Aug 2008 15:25:29 +0200 Subject: [PATCH] [svn r57551] normalizing py.which cmdline script --HG-- branch : trunk --- py/__init__.py | 5 +++-- py/bin/py.which | 26 +++----------------------- py/bin/win32/py.which.cmd | 2 ++ py/cmdline/pywhich.py | 23 +++++++++++++++++++++++ py/cmdline/testing/test_generic.py | 5 +++-- 5 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 py/bin/win32/py.which.cmd create mode 100755 py/cmdline/pywhich.py diff --git a/py/__init__.py b/py/__init__.py index be1a1bc76..3e582729d 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -26,8 +26,8 @@ version = "1.0.0a1" initpkg(__name__, description = "pylib and py.test: agile development and test support library", - revision = int('$LastChangedRevision: 57548 $'.split(':')[1][:-1]), - lastchangedate = '$LastChangedDate: 2008-08-21 14:12:20 +0200 (Thu, 21 Aug 2008) $', + revision = int('$LastChangedRevision: 57551 $'.split(':')[1][:-1]), + lastchangedate = '$LastChangedDate: 2008-08-21 15:25:29 +0200 (Thu, 21 Aug 2008) $', version = version, url = "http://pylib.org", download_url = "http://codespeak.net/py/0.9.2/download.html", @@ -59,6 +59,7 @@ initpkg(__name__, 'cmdline.pylookup' : ('./cmdline/pylookup.py', 'main',), 'cmdline.pycountloc' : ('./cmdline/pycountloc.py', 'main',), 'cmdline.pycleanup' : ('./cmdline/pycleanup.py', 'main',), + 'cmdline.pywhich' : ('./cmdline/pywhich.py', 'main',), # helpers for use from test functions or collectors 'test.__doc__' : ('./test/__init__.py', '__doc__'), diff --git a/py/bin/py.which b/py/bin/py.which index 6e54abd4a..f2b30cfff 100755 --- a/py/bin/py.which +++ b/py/bin/py.which @@ -1,23 +1,3 @@ -#!/usr/bin/env python - -"""\ -py.which [name] - -print the location of the given python module or package name -""" - -import sys - -if __name__ == '__main__': - name = sys.argv[1] - try: - mod = __import__(name) - except ImportError: - print >>sys.stderr, "could not import:", name - else: - try: - location = mod.__file__ - except AttributeError: - print >>sys.stderr, "module (has no __file__):", mod - else: - print location +#!/usr/bin/env python +from _findpy import py +py.cmdline.pywhich() \ No newline at end of file diff --git a/py/bin/win32/py.which.cmd b/py/bin/win32/py.which.cmd new file mode 100644 index 000000000..27af42fa6 --- /dev/null +++ b/py/bin/win32/py.which.cmd @@ -0,0 +1,2 @@ +@echo off +python "%~dp0\..\py.which" %* \ No newline at end of file diff --git a/py/cmdline/pywhich.py b/py/cmdline/pywhich.py new file mode 100755 index 000000000..2acd33651 --- /dev/null +++ b/py/cmdline/pywhich.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +"""\ +py.which [name] + +print the location of the given python module or package name +""" + +import sys + +def main(): + name = sys.argv[1] + try: + mod = __import__(name) + except ImportError: + print >>sys.stderr, "could not import:", name + else: + try: + location = mod.__file__ + except AttributeError: + print >>sys.stderr, "module (has no __file__):", mod + else: + print location diff --git a/py/cmdline/testing/test_generic.py b/py/cmdline/testing/test_generic.py index 8fa58fa7e..b8bf6b8cb 100644 --- a/py/cmdline/testing/test_generic.py +++ b/py/cmdline/testing/test_generic.py @@ -25,8 +25,9 @@ def checkprocess(script): else: cmd = "%s" %(script, ) - if script.basename.startswith("py.lookup"): - cmd += " hello" + if script.basename.startswith("py.lookup") or \ + script.basename.startswith("py.which"): + cmd += " sys" print "executing", script try: py.process.cmdexec(cmd)