Passed
Push — master ( d7aedc...c4fafb )
by Max
55s
created

mutmut_helper.untracked_files()   A

Complexity

Conditions 3

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
import os.path
2
import subprocess
3
4
5
def modified_files():
6
    for file_ in (
7
        subprocess.run(["hg", "status", "--modified"], capture_output=True)
8
        .stdout.decode()
9
        .split("\n")
10
    ):
11
        if file_:
12
            yield file_[2:]
13
14
15
def cache_files(file_list):
16
    for file_ in file_list:
17
        dirname, fn = os.path.split(file_)
18
        cache_dir = os.path.join(dirname, "__pycache__")
19
        try:
20
            cache_files = os.listdir(cache_dir)
21
        except FileNotFoundError:
22
            continue
23
        for cache_file in cache_files:
24
            if cache_file.startswith(fn):
25
                yield os.path.join(cache_dir, cache_file)
26
27
28
if __name__ == "__main__":
29
    for cache_file in cache_files(modified_files()):
30
        print(cache_file)
31
        os.remove(cache_file)
32