Get rid of most jedi usages.

This commit is contained in:
Dave Halter
2017-05-14 13:51:04 -04:00
parent efac51c1b1
commit fb05fb4c19
6 changed files with 18 additions and 22 deletions

View File

@@ -7,9 +7,9 @@ import shutil
import pickle
import platform
import errno
import logging
from jedi import settings
from jedi import debug
from parso._compatibility import FileNotFoundError
@@ -99,7 +99,7 @@ def _load_from_file_system(grammar, path, p_time):
return None
else:
parser_cache[path] = module_cache_item
debug.dbg('pickle loaded: %s', path)
logging.debug('pickle loaded: %s', path)
return module_cache_item.node

View File

@@ -3,8 +3,7 @@ Parsers for Python
"""
import os
from jedi import settings
from jedi.common import splitlines, source_to_unicode
from parso.utils import splitlines, source_to_unicode
from parso._compatibility import FileNotFoundError
from parso.pgen2.pgen import generate_grammar
from parso.python.parser import Parser, _remove_last_newline
@@ -84,7 +83,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
with open(path, 'rb') as f:
code = source_to_unicode(f.read())
if diff_cache and settings.fast_parser:
if diff_cache:
try:
module_cache_item = parser_cache[path]
except KeyError:

View File

@@ -8,9 +8,9 @@ fragments.
import re
import difflib
from collections import namedtuple
import logging
from jedi.common import splitlines
from jedi import debug
from parso.utils import splitlines
from parso.python.parser import Parser, _remove_last_newline
from parso.python.tree import EndMarker
from parso.tokenize import (generate_tokens, NEWLINE, TokenInfo,
@@ -115,7 +115,7 @@ class DiffParser(object):
Returns the new module node.
'''
debug.speed('diff parser start')
logging.debug('diff parser start')
# Reset the used names cache so they get regenerated.
self._module._used_names = None
@@ -134,11 +134,11 @@ class DiffParser(object):
line_length = len(new_lines)
sm = difflib.SequenceMatcher(None, old_lines, self._parser_lines_new)
opcodes = sm.get_opcodes()
debug.speed('diff parser calculated')
debug.dbg('diff: line_lengths old: %s, new: %s' % (len(old_lines), line_length))
logging.debug('diff parser calculated')
logging.debug('diff: line_lengths old: %s, new: %s' % (len(old_lines), line_length))
for operation, i1, i2, j1, j2 in opcodes:
debug.dbg('diff %s old[%s:%s] new[%s:%s]',
logging.debug('diff %s old[%s:%s] new[%s:%s]',
operation, i1 + 1, i2, j1 + 1, j2)
if j2 == line_length + int(self._added_newline):
@@ -162,9 +162,6 @@ class DiffParser(object):
if self._added_newline:
_remove_last_newline(self._module)
# Good for debugging.
if debug.debug_function:
self._enabled_debugging(old_lines, new_lines)
last_pos = self._module.end_pos[0]
if last_pos != line_length:
current_lines = splitlines(self._module.get_code(), keepends=True)
@@ -174,13 +171,13 @@ class DiffParser(object):
% (last_pos, line_length, ''.join(diff))
)
debug.speed('diff parser end')
logging.debug('diff parser end')
return self._module
def _enabled_debugging(self, old_lines, lines_new):
if self._module.get_code() != ''.join(lines_new):
debug.warning('parser issue:\n%s\n%s', ''.join(old_lines),
''.join(lines_new))
logging.warning('parser issue:\n%s\n%s', ''.join(old_lines),
''.join(lines_new))
def _copy_from_old_parser(self, line_offset, until_line_old, until_line_new):
copied_nodes = [None]
@@ -216,7 +213,7 @@ class DiffParser(object):
from_ = copied_nodes[0].get_start_pos_of_prefix()[0] + line_offset
to = self._nodes_stack.parsed_until_line
debug.dbg('diff actually copy %s to %s', from_, to)
logging.debug('diff actually copy %s to %s', from_, to)
# Since there are potential bugs that might loop here endlessly, we
# just stop here.
assert last_until_line != self._nodes_stack.parsed_until_line \
@@ -262,7 +259,7 @@ class DiffParser(object):
#self._insert_nodes(nodes)
self._nodes_stack.add_parsed_nodes(nodes)
debug.dbg(
logging.debug(
'parse part %s to %s (to %s in parser)',
nodes[0].get_start_pos_of_prefix()[0],
self._nodes_stack.parsed_until_line,

View File

@@ -3,7 +3,7 @@ from parso import tokenize
from parso.token import (DEDENT, INDENT, ENDMARKER, NEWLINE, NUMBER,
STRING, tok_name)
from parso.parser import BaseParser
from jedi.common import splitlines
from parso.utils import splitlines
class Parser(BaseParser):

View File

@@ -12,7 +12,7 @@ the input given to the parser. This is important if you are using refactoring.
The easiest way to play with this module is to use :class:`parsing.Parser`.
:attr:`parsing.Parser.module` holds an instance of :class:`Module`:
>>> from jedi.parser.python import parse
>>> from parso.python import parse
>>> parser = parse('import os')
>>> module = parser.get_root_node()
>>> module

View File

@@ -19,7 +19,7 @@ import itertools as _itertools
from parso.token import (tok_name, N_TOKENS, ENDMARKER, STRING, NUMBER, opmap,
NAME, OP, ERRORTOKEN, NEWLINE, INDENT, DEDENT)
from parso._compatibility import py_version, u
from jedi.common import splitlines
from parso.utils import splitlines
cookie_re = re.compile("coding[:=]\s*([-\w.]+)")