diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-12-28 10:09:09 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-12-28 10:09:09 -0500 |
commit | 93561c76f281656169e5c062d93bc30da95d8c94 (patch) | |
tree | ac5a824337730c134d9e822bc63aa2a4ce98414c /coverage/execfile.py | |
parent | 98a7b99ed97af0f5dfc6fc7f5219ad4b026a6dfc (diff) | |
download | python-coveragepy-git-93561c76f281656169e5c062d93bc30da95d8c94.tar.gz |
Further consolidation of code reading Python source.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index ecb03372..beaf1913 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -7,8 +7,8 @@ import types from coverage.backward import BUILTINS from coverage.backward import PYC_MAGIC_NUMBER, imp, importlib_util_find_spec +from coverage.files import get_python_source from coverage.misc import ExceptionDuringRun, NoCode, NoSource -from coverage.phystokens import read_python_source class DummyLoader(object): @@ -178,16 +178,11 @@ def make_code_from_py(filename): """Get source from `filename` and make a code object of it.""" # Open the source file. try: - source = read_python_source(filename) - except IOError: + source = get_python_source(filename) + except (IOError, NoSource): raise NoSource("No file to run: %r" % filename) - # We have the source. `compile` still needs the last line to be clean, - # so make sure it is, then compile a code object from it. - if not source or source[-1] != '\n': - source += '\n' code = compile(source, filename, "exec") - return code |