MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / source_to_entity

Function source_to_entity

tensorflow/python/autograph/pyct/compiler.py:89–104  ·  view source on GitHub ↗

Loads the given source code as a Python module.

(source, delete_on_exit)

Source from the content-addressed store, hash-verified

87
88
89def source_to_entity(source, delete_on_exit):
90 """Loads the given source code as a Python module."""
91 if six.PY2:
92 source = source.encode('utf-8')
93 f = tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False)
94 else:
95 f = tempfile.NamedTemporaryFile( # pylint:disable=unexpected-keyword-arg
96 mode='w', suffix='.py', delete=False, encoding='utf-8')
97
98 with f:
99 module_name = os.path.basename(f.name[:-3])
100 f.write(source)
101
102 if delete_on_exit and ag_logging.get_verbosity() < 3:
103 atexit.register(lambda: os.remove(f.name))
104 return imp.load_source(module_name, f.name), f.name
105
106
107# TODO(mdan): Rename: ast_to_entity

Callers 1

ast_to_objectFunction · 0.85

Calls 4

encodeMethod · 0.45
writeMethod · 0.45
registerMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected