summaryrefslogtreecommitdiff
path: root/coverage/files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-12-27 11:36:12 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-12-27 11:36:12 -0500
commitea3ebc5dfa425bbd0fb94f96445bb2967cb3d2f1 (patch)
tree2efe748b986ea2c661814df20cd8e515aff75aae /coverage/files.py
parent280a9ab2056ae33616528955e99a419632d92b3b (diff)
downloadpython-coveragepy-ea3ebc5dfa425bbd0fb94f96445bb2967cb3d2f1.tar.gz
Make .pyw work again.
Diffstat (limited to 'coverage/files.py')
-rw-r--r--coverage/files.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 2945054..c66327d 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(