diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-12-27 11:36:12 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-12-27 11:36:12 -0500 |
commit | 7030ebe44b4138e88ffa3baf34d88a2b39bb3697 (patch) | |
tree | ce9cf0a965ee0e030ed9501f5c38d938a1fd3d99 /coverage/files.py | |
parent | abd2ae644d0009cc469e86492216ff311e543116 (diff) | |
download | python-coveragepy-git-7030ebe44b4138e88ffa3baf34d88a2b39bb3697.tar.gz |
Make .pyw work again.
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/coverage/files.py b/coverage/files.py index 29450542..c66327d3 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -57,16 +57,24 @@ class FileLocator(object): def get_python_source(filename): """Return the source code, as a str.""" - if os.path.exists(filename): - # A regular text file: open it. - return read_python_source(filename) - - # Maybe it's in a zip file? - source = get_zip_bytes(filename) - if source is not None: - if sys.version_info >= (3, 0): - source = source.decode(source_encoding(source)) - return source + base, ext = os.path.splitext(filename) + if ext == ".py" and sys.platform == "win32": + exts = [".py", ".pyw"] + else: + exts = [ext] + + for ext in exts: + try_filename = base + ext + if os.path.exists(try_filename): + # A regular text file: open it. + return read_python_source(try_filename) + + # Maybe it's in a zip file? + source = get_zip_bytes(try_filename) + if source is not None: + if sys.version_info >= (3, 0): + source = source.decode(source_encoding(source)) + return source # Couldn't find source. raise NoSource( |