class PythonCILEDriver(CILEDriver): lang = lang def scan_purelang(self, buf): #log.warn("TODO: python cile that uses elementtree") content = buf.accessor.text if isinstance(content, unicode): encoding = buf.encoding or "utf-8" try: content = content.encode(encoding) except UnicodeError, ex: raise CodeIntelError( "cannot encode Python content as %r (%s)" % (encoding, ex)) el = pythoncile.scan_et(content, buf.path, lang=self.lang) return el
def get_pythoncile_cix_tree_for_path(mod_path): try: from codeintel2 import pythoncile # In process ciling. return pythoncile.scan_et(file(mod_path, "r").read(), mod_path) except (ImportError, SyntaxError): # Need to perform the ciling using a Python 2.6 interpreter. from os.path import abspath, dirname, join import subprocess ci_dir = dirname(dirname(dirname(dirname(abspath(__file__))))) ko_dir = dirname(dirname(ci_dir)) ci2_path = join(ci_dir, "ci2.py") env = os.environ.copy() pypaths = [ join(ci_dir, "lib"), join(ci_dir, "support"), join(ko_dir, "src", "python-sitelib"), join(ko_dir, "src", "find"), join(ko_dir, "util"), join(ko_dir, "contrib", "smallstuff"), ] env['PYTHONPATH'] = os.pathsep.join(pypaths) if sys.platform == "darwin": # Komodo only has 32-bit versions on the Mac. env['VERSIONER_PYTHON_PREFER_32_BIT'] = 'yes' if major < 3: # Convert env to strings (not unicode). encoding = sys.getfilesystemencoding() _enc_env = {} for key, value in env.items(): try: _enc_env[key.encode(encoding)] = value.encode(encoding) except UnicodeEncodeError: # Could not encode it, warn we are dropping it. log.warn( "Could not encode environment variable %r " "so removing it", key) env = _enc_env cmd = [get_py_ci_executable(), ci2_path, "scan", mod_path] p = subprocess.Popen(cmd, cwd=ci_dir, env=env, stdout=subprocess.PIPE) cix, stderr = p.communicate() tree = tree_from_cix(cix) return tree
def get_pythoncile_cix_tree_for_path(mod_path): try: from codeintel2 import pythoncile # In process ciling. return pythoncile.scan_et(file(mod_path, "r").read(), mod_path) except (ImportError, SyntaxError): # Need to perform the ciling using a Python 2.6 interpreter. from os.path import abspath, dirname, join import subprocess ci_dir = dirname(dirname(dirname(dirname(abspath(__file__))))) ko_dir = dirname(dirname(ci_dir)) ci2_path = join(ci_dir, "ci2.py") env = os.environ.copy() pypaths = [join(ci_dir, "lib"), join(ci_dir, "support"), join(ko_dir, "src", "python-sitelib"), join(ko_dir, "src", "find"), join(ko_dir, "util"), join(ko_dir, "contrib", "smallstuff"), ] env['PYTHONPATH'] = os.pathsep.join(pypaths) if sys.platform == "darwin": # Komodo only has 32-bit versions on the Mac. env['VERSIONER_PYTHON_PREFER_32_BIT'] = 'yes' if major < 3: # Convert env to strings (not unicode). encoding = sys.getfilesystemencoding() _enc_env = {} for key, value in env.items(): try: _enc_env[key.encode(encoding)] = value.encode(encoding) except UnicodeEncodeError: # Could not encode it, warn we are dropping it. log.warn("Could not encode environment variable %r " "so removing it", key) env = _enc_env cmd = [get_py_ci_executable(), ci2_path, "scan", mod_path] p = subprocess.Popen(cmd, cwd=ci_dir, env=env, stdout=subprocess.PIPE) cix, stderr = p.communicate() tree = tree_from_cix(cix) return tree