Remove circular dependency between pyct and utils. This was undetected for a while, but an upcoming change detects it.

PiperOrigin-RevId: 286057471
Change-Id: Ib8c8f5fe30af1c49d798515c0b3ddfb155a1e2f2
This commit is contained in:
Dan Moldovan 2019-12-17 14:15:47 -08:00 committed by TensorFlower Gardener
parent 15f868b245
commit 140687f298
2 changed files with 18 additions and 17 deletions

View File

@ -33,7 +33,6 @@ import six
from tensorflow.python.autograph.pyct import origin_info
from tensorflow.python.autograph.pyct import parser
from tensorflow.python.autograph.utils import ag_logging
def load_source(source, delete_on_exit):
@ -49,7 +48,7 @@ def load_source(source, delete_on_exit):
module_name = os.path.basename(f.name[:-3])
f.write(source)
if delete_on_exit and ag_logging.get_verbosity() < 3:
if delete_on_exit:
atexit.register(lambda: os.remove(f.name))
return imp.load_source(module_name, f.name), f.name

View File

@ -29,7 +29,6 @@ from tensorflow.python.autograph.pyct import anno
from tensorflow.python.autograph.pyct import ast_util
from tensorflow.python.autograph.pyct import parser
from tensorflow.python.autograph.pyct import pretty_printer
from tensorflow.python.autograph.utils import ag_logging as logging
from tensorflow.python.util import tf_inspect
@ -137,20 +136,23 @@ def create_source_map(nodes, code, filepath):
source_map[line_loc] = origin_info
except ValueError:
if logging.has_verbosity(3):
for n, rn in zip(nodes, reparsed_nodes):
nodes_str = pretty_printer.fmt(n, color=False, noanno=True)
reparsed_nodes_str = pretty_printer.fmt(rn, color=False, noanno=True)
diff = difflib.context_diff(
nodes_str.split('\n'),
reparsed_nodes_str.split('\n'),
fromfile='Original nodes',
tofile='Reparsed nodes',
n=7)
diff = '\n'.join(diff)
logging.log(3, 'AST seems to lack integrity. Diff:\n%s', diff)
raise
except ValueError as err:
new_msg = 'Inconsistent ASTs detected. This is a bug. Cause: \n'
new_msg += str(err)
new_msg += 'Diff:\n'
for n, rn in zip(nodes, reparsed_nodes):
nodes_str = pretty_printer.fmt(n, color=False, noanno=True)
reparsed_nodes_str = pretty_printer.fmt(rn, color=False, noanno=True)
diff = difflib.context_diff(
nodes_str.split('\n'),
reparsed_nodes_str.split('\n'),
fromfile='Original nodes',
tofile='Reparsed nodes',
n=7)
diff = '\n'.join(diff)
new_msg += diff + '\n'
raise ValueError(new_msg)
return source_map