Checks whether the file can be read by the coverage module. This is especially needed for .pyx files and .py files with syntax errors.
(path)
| 4 | |
| 5 | |
| 6 | def is_valid_py_file(path): |
| 7 | """ |
| 8 | Checks whether the file can be read by the coverage module. This is especially |
| 9 | needed for .pyx files and .py files with syntax errors. |
| 10 | """ |
| 11 | import os |
| 12 | |
| 13 | is_valid = False |
| 14 | if os.path.isfile(path) and not os.path.splitext(path)[1] == ".pyx": |
| 15 | try: |
| 16 | with open(path, "rb") as f: |
| 17 | compile(f.read(), path, "exec") |
| 18 | is_valid = True |
| 19 | except: |
| 20 | pass |
| 21 | return is_valid |
| 22 | |
| 23 | |
| 24 | def execute(): |