[Zope-Checkins] CVS: Zope3/lib/python/Interface - pyskel.py:1.1.2.12
Stephan Richter
srichter@cbu.edu
Wed, 5 Jun 2002 10:49:12 -0400
Update of /cvs-repository/Zope3/lib/python/Interface
In directory cvs.zope.org:/tmp/cvs-serv7757
Modified Files:
Tag: Zope-3x-branch
pyskel.py
Log Message:
Okay, I have added something to pyskel.py that bugs me already since a long
time. Until now you could only use the Python dot syntax to specify an
interface. That meant that I could not use my TAB key in the shell to
wander through the directories.
I therefore added some functionality that '/' are also allowed. Furthermore
you can use relative paths like ../Zope/I18n/IDomain.py if you are in the
Interface directory for example. I find that particularly helpful, since I
often reside in the directory of the package I am working in. So, if I am
in Zope/I18n, I can say:
pyskel.py ./IDomain.py
Note: Assuming pyskel in somewhere in your shell search path.
=== Zope3/lib/python/Interface/pyskel.py 1.1.2.11 => 1.1.2.12 ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
@@ -95,6 +96,25 @@
def resolve(name, _silly=('__doc__',), _globals={}):
+ # Support for file path syntax; this way I can use TAB to search for
+ # the module.
+ if '/' in name:
+ # We got a relative path. Let's try to get the full one and then
+ # make a package path out of it.
+ if name.startswith('./') or name.startswith('../'):
+ cwd = os.getcwd()
+ for path in sys.path[1:]: # Yeah, we need to exclude the cwd itself
+ if path != '' and cwd.startswith(path):
+ name = os.path.join(cwd[len(path)+1:], name)
+ name = os.path.normpath(name)
+ break
+
+ # get rid of the file ending :)
+ if name.endswith('.py'):
+ name = name[:-3]
+ name = name.replace('/', '.')
+
+ # Now to the regular lookup
if name[:1]=='.':
name='ZopeProducts'+name