From fb05fb4c1903d88bd615b4c753e23b0b82606c09 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 14 May 2017 13:51:04 -0400 Subject: [PATCH] Get rid of most jedi usages. --- parso/cache.py | 4 ++-- parso/python/__init__.py | 5 ++--- parso/python/diff.py | 25 +++++++++++-------------- parso/python/parser.py | 2 +- parso/python/tree.py | 2 +- parso/tokenize.py | 2 +- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/parso/cache.py b/parso/cache.py index 4d9ad32..8656174 100644 --- a/parso/cache.py +++ b/parso/cache.py @@ -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 diff --git a/parso/python/__init__.py b/parso/python/__init__.py index bf68bf3..71f3cda 100644 --- a/parso/python/__init__.py +++ b/parso/python/__init__.py @@ -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: diff --git a/parso/python/diff.py b/parso/python/diff.py index 47b1982..abfa9bb 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -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, diff --git a/parso/python/parser.py b/parso/python/parser.py index bdd564c..baf5dcc 100644 --- a/parso/python/parser.py +++ b/parso/python/parser.py @@ -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): diff --git a/parso/python/tree.py b/parso/python/tree.py index ad01175..fa52035 100644 --- a/parso/python/tree.py +++ b/parso/python/tree.py @@ -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 diff --git a/parso/tokenize.py b/parso/tokenize.py index ce32e92..702be2a 100644 --- a/parso/tokenize.py +++ b/parso/tokenize.py @@ -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.]+)")