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 | d0e95e510f5fa73f81fc9a2ed6fc4f925f6c6460 (patch) | |
tree | d4340465e8520402d316eae289d20536ed1b545a /coverage/execfile.py | |
parent | 3ca6fdd609eea353f89fa7047d85d6b48f2af68f (diff) | |
download | python-coveragepy-d0e95e510f5fa73f81fc9a2ed6fc4f925f6c6460.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 ecb0337..beaf191 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 |