diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-07-04 00:13:03 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-07-04 00:13:03 -0400 |
commit | 9c7594514f50263a14fb15514078c1bc0f273bd0 (patch) | |
tree | 952d55a9b0c2c017f8f0a3751d661e2e1e288143 /coverage/files.py | |
parent | b0d089c4df4b14e38c55016bcfa2d48d0e83c63d (diff) | |
download | python-coveragepy-9c7594514f50263a14fb15514078c1bc0f273bd0.tar.gz |
With --source=dir, dir/__init__.py need not exist any longer, but dir/sub/__init__.py still does.
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/coverage/files.py b/coverage/files.py index e6dc4aa..e07c576 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -207,9 +207,17 @@ class PathAliases(object): def find_python_files(dirname): - """Yield all of the importable Python files in `dirname`, recursively.""" - for dirpath, dirnames, filenames in os.walk(dirname, topdown=True): - if '__init__.py' not in filenames: + """Yield all of the importable Python files in `dirname`, recursively. + + To be importable, the files have to be in a directory with a __init__.py, + except for `dirname` itself, which isn't required to have one. The + assumption is that `dirname` was specified directly, so the user knows + best, but subdirectories are checked for a __init__.py to be sure we only + find the importable files. + + """ + for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)): + if i > 0 and '__init__.py' not in filenames: # If a directory doesn't have __init__.py, then it isn't # importable and neither are its files del dirnames[:] |