Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r84917:6174f94686c9
Date: 2016-06-04 16:30 +0100
http://bitbucket.org/pypy/pypy/changeset/6174f94686c9/

Log:    Move pypydir definition from conftest.py to pypy/__init__.py

diff --git a/pypy/__init__.py b/pypy/__init__.py
--- a/pypy/__init__.py
+++ b/pypy/__init__.py
@@ -1,4 +1,5 @@
-# Empty
+import os
+pypydir = os.path.realpath(os.path.dirname(__file__))
 
 # XXX Should be empty again, soon.
 # XXX hack for win64:
diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -1,4 +1,4 @@
-import py, pytest, sys, os, textwrap
+import py, pytest, sys, textwrap
 from inspect import isclass
 
 # pytest settings
@@ -10,8 +10,6 @@
 #
 option = None
 
-pypydir = os.path.realpath(os.path.dirname(__file__))
-
 def braindead_deindent(self):
     """monkeypatch that wont end up doing stupid in the python tokenizer"""
     text = '\n'.join(self.lines)
diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -9,7 +9,7 @@
 from rpython.config.config import to_optparse, make_dict, SUPPRESS_USAGE
 from rpython.config.config import ConflictConfigError
 from pypy.tool.option import make_objspace
-from pypy.conftest import pypydir
+from pypy import pypydir
 from rpython.rlib import rthread
 from pypy.module.thread import os_thread
 
@@ -293,7 +293,7 @@
             self.hack_for_cffi_modules(driver)
 
         return self.get_entry_point(config)
-    
+
     def hack_for_cffi_modules(self, driver):
         # HACKHACKHACK
         # ugly hack to modify target goal from compile_* to build_cffi_imports
@@ -320,7 +320,7 @@
             while not basedir.join('include').exists():
                 _basedir = basedir.dirpath()
                 if _basedir == basedir:
-                    raise ValueError('interpreter %s not inside pypy repo', 
+                    raise ValueError('interpreter %s not inside pypy repo',
                                      str(exename))
                 basedir = _basedir
             modules = self.config.objspace.usemodules.getpaths()
diff --git a/pypy/interpreter/test/test_app_main.py 
b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -6,7 +6,7 @@
 import sys, os, re, runpy, subprocess
 from rpython.tool.udir import udir
 from contextlib import contextmanager
-from pypy.conftest import pypydir
+from pypy import pypydir
 from lib_pypy._pypy_interact import irc_header
 
 try:
@@ -291,7 +291,7 @@
         child.expect('>>>')   # banner
         if irc_topic:
             assert irc_header in child.before
-        else:    
+        else:
             assert irc_header not in child.before
 
     def test_help(self):
@@ -1074,4 +1074,4 @@
             # assert it did not crash
         finally:
             sys.path[:] = old_sys_path
-    
+
diff --git a/pypy/module/_minimal_curses/test/test_curses.py 
b/pypy/module/_minimal_curses/test/test_curses.py
--- a/pypy/module/_minimal_curses/test/test_curses.py
+++ b/pypy/module/_minimal_curses/test/test_curses.py
@@ -1,4 +1,4 @@
-from pypy.conftest import pypydir
+from pypy import pypydir
 from rpython.tool.udir import udir
 import py
 import sys
@@ -70,7 +70,7 @@
         f.write(source)
         child = self.spawn(['--withmod-_minimal_curses', str(f)])
         child.expect('ok!')
-        
+
 class TestCCurses(object):
     """ Test compiled version
     """
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -4,7 +4,7 @@
 
 import py
 
-from pypy.conftest import pypydir
+from pypy import pypydir
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rtyper.tool import rffi_platform
 from rpython.rtyper.lltypesystem import ll2ctypes
diff --git a/pypy/module/cpyext/test/test_cpyext.py 
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -4,7 +4,7 @@
 
 import py, pytest
 
-from pypy.conftest import pypydir
+from pypy import pypydir
 from pypy.interpreter import gateway
 from rpython.rtyper.lltypesystem import lltype, ll2ctypes
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -5,7 +5,7 @@
 from pypy.objspace.std import StdObjSpace
 from rpython.tool.udir import udir
 from pypy.tool.pytest.objspace import gettestobjspace
-from pypy.conftest import pypydir
+from pypy import pypydir
 from rpython.translator.c.test.test_extfunc import need_sparse_files
 from rpython.rlib import rposix
 import os
diff --git a/pypy/module/sys/state.py b/pypy/module/sys/state.py
--- a/pypy/module/sys/state.py
+++ b/pypy/module/sys/state.py
@@ -2,7 +2,7 @@
 Implementation of interpreter-level 'sys' routines.
 """
 import os
-import pypy
+from pypy import pypydir
 
 # ____________________________________________________________
 #
@@ -20,7 +20,6 @@
     def setinitialpath(self, space):
         from pypy.module.sys.initpath import compute_stdlib_path
         # Initialize the default path
-        pypydir = os.path.dirname(os.path.abspath(pypy.__file__))
         srcdir = os.path.dirname(pypydir)
         path = compute_stdlib_path(self, srcdir)
         self.w_path = space.newlist([space.wrap(p) for p in path])
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -14,7 +14,7 @@
 
 
 import pypy
-pypydir = os.path.dirname(os.path.abspath(pypy.__file__))
+pypydir = pypy.pypydir
 pypyroot = os.path.dirname(pypydir)
 del pypy
 from rpython.tool.version import get_repo_version_info
diff --git a/pypy/module/termios/test/test_termios.py 
b/pypy/module/termios/test/test_termios.py
--- a/pypy/module/termios/test/test_termios.py
+++ b/pypy/module/termios/test/test_termios.py
@@ -1,7 +1,7 @@
 import os
 import sys
 import py
-from pypy.conftest import pypydir
+from pypy import pypydir
 from rpython.tool.udir import udir
 
 if os.name != 'posix':
diff --git a/pypy/tool/genstatistic.py b/pypy/tool/genstatistic.py
--- a/pypy/tool/genstatistic.py
+++ b/pypy/tool/genstatistic.py
@@ -1,22 +1,22 @@
 
 import py
-from py._cmdline import pycountloc as countloc 
+from py._cmdline import pycountloc as countloc
 from py.xml import raw
-from pypy import conftest
+from pypy import pypydir
 
-pypydir = py.path.local(conftest.pypydir)
+pypydir = py.path.local(pypydir)
 
 def isdocfile(p):
     return (p.ext in ('.txt', '.rst') or
             p.basename in ('README', 'NOTES', 'LICENSE'))
 
 def istestfile(p):
-    if not p.check(file=1, ext='.py'): 
-        return False 
-    pb = p.purebasename 
-    if pb.startswith('test_') or pb.endswith('_test'): 
-        return True 
-    if 'test' in [x.basename for x in p.parts()[-4:]]: 
+    if not p.check(file=1, ext='.py'):
+        return False
+    pb = p.purebasename
+    if pb.startswith('test_') or pb.endswith('_test'):
+        return True
+    if 'test' in [x.basename for x in p.parts()[-4:]]:
         return True
 
 notistestfile = lambda x: not istestfile(x)
@@ -24,42 +24,43 @@
 class relchecker:
     def __init__(self, rel):
         self.rel = rel
-    def __call__(self, p): 
-        return p.relto(conftest.pypydir).startswith(self.rel)
+
+    def __call__(self, p):
+        return p.relto(pypydir).startswith(self.rel)
 
 def isfile(p):
     return p.check(file=1) and p.ext in ('.py', '.txt', '')
 
 def recpypy(p):
-    if p.basename[0] == '.': 
-        return False 
-    if p.basename in ('Pyrex', 
-                      '_cache', 
-                      'unicodedata', 
+    if p.basename[0] == '.':
+        return False
+    if p.basename in ('Pyrex',
+                      '_cache',
+                      'unicodedata',
                       'pypy-translation-snapshot'):
-        return False 
-    return True 
+        return False
+    return True
 
 def getpypycounter():
-    filecounter = countloc.FileCounter() 
-    root = py.path.local(conftest.pypydir)
+    filecounter = countloc.FileCounter()
+    root = py.path.local(pypydir)
     filecounter.addrecursive(root, isfile, rec=recpypy)
-    return filecounter 
+    return filecounter
 
-class CounterModel: 
-    def __init__(self, pypycounter): 
-        self.counter = pypycounter 
-        self.totallines = pypycounter.numlines 
+class CounterModel:
+    def __init__(self, pypycounter):
+        self.counter = pypycounter
+        self.totallines = pypycounter.numlines
         self.totalfiles = pypycounter.numfiles
-        self.testlines = pypycounter.getnumlines(istestfile) 
-        self.testfiles = pypycounter.getnumfiles(istestfile) 
-        self.notestlines = pypycounter.getnumlines(notistestfile) 
-        self.notestfiles = pypycounter.getnumfiles(notistestfile) 
+        self.testlines = pypycounter.getnumlines(istestfile)
+        self.testfiles = pypycounter.getnumfiles(istestfile)
+        self.notestlines = pypycounter.getnumlines(notistestfile)
+        self.notestfiles = pypycounter.getnumfiles(notistestfile)
         self.doclines = pypycounter.getnumlines(isdocfile)
-        self.docfiles = pypycounter.getnumfiles(isdocfile) 
+        self.docfiles = pypycounter.getnumfiles(isdocfile)
 
 #
-# rendering 
+# rendering
 #
 def row(*args):
     return html.tr([html.td(arg) for arg in args])
@@ -69,22 +70,22 @@
 
 def viewlocsummary(model):
     t = html.table(
-        row("total number of lines", model.totallines, raw("&nbsp;")), 
-        row("number of testlines", model.testlines, 
-            percent(model.testlines, model.totallines)), 
-        row("number of non-testlines", model.notestlines, 
-            percent(model.notestlines, model.totallines)), 
+        row("total number of lines", model.totallines, raw("&nbsp;")),
+        row("number of testlines", model.testlines,
+            percent(model.testlines, model.totallines)),
+        row("number of non-testlines", model.notestlines,
+            percent(model.notestlines, model.totallines)),
 
-        row("total number of files", model.totalfiles, raw("&nbsp;")), 
-        row("number of testfiles", model.testfiles, 
-            percent(model.testfiles, model.totalfiles)), 
-        row("number of non-testfiles", model.notestfiles, 
-            percent(model.notestfiles, model.totalfiles)), 
+        row("total number of files", model.totalfiles, raw("&nbsp;")),
+        row("number of testfiles", model.testfiles,
+            percent(model.testfiles, model.totalfiles)),
+        row("number of non-testfiles", model.notestfiles,
+            percent(model.notestfiles, model.totalfiles)),
         )
-    if model.docfiles: 
-        t.append(row("number of docfiles", model.docfiles, 
+    if model.docfiles:
+        t.append(row("number of docfiles", model.docfiles,
             percent(model.docfiles, model.totalfiles)))
-        t.append(row("number of doclines", model.doclines, 
+        t.append(row("number of doclines", model.doclines,
             percent(model.doclines, model.totallines)))
     return t
 
@@ -92,46 +93,46 @@
     t = html.table()
     d = model.counter.file2numlines
     paths = d.items()
-    paths.sort(lambda x,y : -cmp(x[1], y[1])) # sort by numlines 
-    for p, numlines in paths: 
-        if numlines < 3: 
+    paths.sort(lambda x, y: -cmp(x[1], y[1]))  # sort by numlines
+    for p, numlines in paths:
+        if numlines < 3:
             continue
         t.append(row(p.relto(pypydir.dirpath()), numlines))
     return t
 
-def viewsubdirs(model): 
+def viewsubdirs(model):
     t = html.table()
-    for p in pypydir.listdir(): 
-        if p.basename in '_cache .svn'.split(): 
+    for p in pypydir.listdir():
+        if p.basename in '_cache .svn'.split():
             continue
-        if p.check(dir=1): 
+        if p.check(dir=1):
             counter = countloc.FileCounter()
             counter.addrecursive(p, isfile, recpypy)
-            model = CounterModel(counter) 
+            model = CounterModel(counter)
             t.append(row(html.h2(p.relto(pypydir.dirpath()))))
             t.append(viewlocsummary(model))
             t.append(viewloclist(model))
     return t
 
-if __name__ == '__main__': 
+if __name__ == '__main__':
     if len(py.std.sys.argv) >= 2:
         target = py.path.local(py.std.sys.argv[1])
     else:
         target = py.path.local('index.html')
     print "writing source statistics to", target
-    pypycounter = getpypycounter() 
-    model = CounterModel(pypycounter) 
-    rev = py.path.svnwc(conftest.pypydir).info().rev
+    pypycounter = getpypycounter()
+    model = CounterModel(pypycounter)
+    rev = py.path.svnwc(pypydir).info().rev
     html = py.xml.html
     doc = html.html(
         html.head(
             html.title("PyPy Statistics %d" % rev),
-        ), 
+        ),
         html.body(
             html.h2("rev %d PyPy Summary of Files and Lines" % rev),
-            viewlocsummary(model), 
-            html.h2("Details on first-level subdirectories"), 
-            viewsubdirs(model), 
+            viewlocsummary(model),
+            html.h2("Details on first-level subdirectories"),
+            viewsubdirs(model),
             html.h3("PyPy Full List Files and Lines"),
             viewloclist(model),
             html.p("files with less than 3 lines ignored")
@@ -139,4 +140,3 @@
     )
     content = doc.unicode(indent=2).encode('utf8')
     target.write(content)
-
diff --git a/pypy/tool/getdocstrings.py b/pypy/tool/getdocstrings.py
--- a/pypy/tool/getdocstrings.py
+++ b/pypy/tool/getdocstrings.py
@@ -1,7 +1,7 @@
 import re
 from os import listdir
 from sys import stdin, stdout, stderr
-from pypy.conftest import pypydir
+from pypy import pypydir
 
 where = pypydir + '/objspace/std/'
 quote = '(' + "'" + '|' + '"' + ')'
@@ -29,7 +29,7 @@
 
 def compile_typedef(typ):
     return re.compile(r"(?P<whitespace>\s+)"
-                      + r"(?P<typeassign>" + typ 
+                      + r"(?P<typeassign>" + typ
                       + "_typedef = StdTypeDef+\s*\(\s*"
                       + quote + typ +  quote + ",).*"
                       + r"(?P<indent>^\s+)"
@@ -38,7 +38,7 @@
 
 def get_pypydoc(sourcefile):
     doc = compile_doc()
-    
+
     try: # if this works we already have a docstring
         pypydoc = doc.search(sourcefile).group('docstring')
 
@@ -86,14 +86,10 @@
 if __name__ == '__main__':
 
     filenames = mk_std_filelist()
-    
+
     for f in filenames:
         inf = file(where + f).read()
         outs = add_docstring(f[:-7], inf)
         if outs is not None:
             outf = file(where + f, 'w')
             outf.write(outs)
-        
-
-                
-            
diff --git a/pypy/tool/release/test/test_package.py 
b/pypy/tool/release/test/test_package.py
--- a/pypy/tool/release/test/test_package.py
+++ b/pypy/tool/release/test/test_package.py
@@ -1,6 +1,6 @@
 
 import py
-from pypy.conftest import pypydir
+from pypy import pypydir
 from pypy.tool.release import package
 from pypy.module.sys.version import  CPYTHON_VERSION
 from rpython.tool.udir import udir
diff --git a/pypy/tool/test/test_tab.py b/pypy/tool/test/test_tab.py
--- a/pypy/tool/test/test_tab.py
+++ b/pypy/tool/test/test_tab.py
@@ -3,7 +3,7 @@
 """
 
 import os
-from pypy.conftest import pypydir
+from pypy import pypydir
 
 ROOT = os.path.abspath(os.path.join(pypydir, '..'))
 RPYTHONDIR = os.path.join(ROOT, "rpython")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to