[pypy-svn] r56023 - in pypy/dist/pypy: bin module/sys translator/goal
arigo at codespeak.net
arigo at codespeak.net
Sun Jun 22 13:35:40 CEST 2008
Author: arigo
Date: Sun Jun 22 13:35:39 2008
New Revision: 56023
Modified:
pypy/dist/pypy/bin/py.py
pypy/dist/pypy/module/sys/state.py
pypy/dist/pypy/translator/goal/app_main.py
Log:
issue295 resolved
Moved bits and pieces around to handle $PYTHONPATH when pypy-c and py.py
start, instead of hard-coding it in the pypy-c.
Modified: pypy/dist/pypy/bin/py.py
==============================================================================
--- pypy/dist/pypy/bin/py.py (original)
+++ pypy/dist/pypy/bin/py.py Sun Jun 22 13:35:39 2008
@@ -49,15 +49,6 @@
print >> sys.stderr, "import site\' failed"
''').interphook('pypy_init')
-def getenv_w(space, name):
- w_os = space.getbuiltinmodule('os')
- w_environ = space.getattr(w_os, space.wrap('environ'))
- w_v = space.call_method(w_environ, 'get', space.wrap(name))
- try:
- return space.str_w(w_v)
- except:
- return None
-
def main_(argv=None):
starttime = time.time()
@@ -76,6 +67,16 @@
space.setitem(space.sys.w_dict, space.wrap('executable'),
space.wrap(argv[0]))
+ w_path = space.sys.get('path')
+ path = os.getenv('PYTHONPATH')
+ if path:
+ path = path.split(os.pathsep)
+ else:
+ path = []
+ path.insert(0, '')
+ for i, dir in enumerate(path):
+ space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir))
+
# store the command-line arguments into sys.argv
go_interactive = interactiveconfig.interactive
banner = ''
@@ -118,7 +119,7 @@
exit_status = 1
# start the interactive console
- if go_interactive or getenv_w(space, 'PYTHONINSPECT'):
+ if go_interactive or os.getenv('PYTHONINSPECT'):
try:
import readline
except:
Modified: pypy/dist/pypy/module/sys/state.py
==============================================================================
--- pypy/dist/pypy/module/sys/state.py (original)
+++ pypy/dist/pypy/module/sys/state.py Sun Jun 22 13:35:39 2008
@@ -50,12 +50,7 @@
pypy_lib = os.path.join(pypydir, 'lib')
checkdir(pypy_lib)
- importlist = ['']
- pythonpath = os.environ.get('PYTHONPATH')
- if pythonpath:
- for p in pythonpath.split(os.pathsep):
- if p:
- importlist.append(p)
+ importlist = []
importlist.append(pypy_lib)
importlist.append(python_std_lib_modified)
importlist.append(python_std_lib)
Modified: pypy/dist/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/dist/pypy/translator/goal/app_main.py (original)
+++ pypy/dist/pypy/translator/goal/app_main.py Sun Jun 22 13:35:39 2008
@@ -193,6 +193,7 @@
# not found! let's hope that the compiled-in path is ok
print >> sys.stderr, ('debug: WARNING: library path not found, '
'using compiled-in sys.path')
+ newpath = sys.path[:]
break
newpath = sys.pypy_initial_path(dirname)
if newpath is None:
@@ -200,9 +201,20 @@
if newpath is None:
search = dirname # walk to the parent directory
continue
- sys.path = newpath # found!
- break
-
+ break # found!
+ path = os.getenv('PYTHONPATH')
+ if path:
+ newpath = path.split(os.pathsep) + newpath
+ newpath.insert(0, '')
+ # remove duplicates
+ _seen = {}
+ sys.path = []
+ for dir in newpath:
+ if dir not in _seen:
+ sys.path.append(dir)
+ _seen[dir] = True
+ del newpath, _seen
+
go_interactive = False
run_command = False
import_site = True
More information about the Pypy-commit
mailing list