File: clean.py

package info (click to toggle)
python-imageio 2.37.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,144 kB
  • sloc: python: 26,306; makefile: 138
file content (46 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import shutil
import fnmatch

from invoke import task

from ._config import ROOT_DIR, NAME


@task
def clean(ctx):
    """clear all .pyc modules and __pycache__ dirs"""
    count1, count2 = 0, 0

    for root, dirnames, filenames in os.walk(ROOT_DIR):
        for dirname in dirnames:
            if dirname == "__pycache__":
                shutil.rmtree(os.path.join(root, dirname))
                count1 += 1
    print("removed %i __pycache__ dirs" % count1)

    for root, dirnames, filenames in os.walk(ROOT_DIR):
        for filename in fnmatch.filter(filenames, "*.pyc"):
            os.remove(os.path.join(root, filename))
            count2 += 1
    print("removed %i .pyc files" % count2)

    for dir in [
        "dist",
        "build",
        NAME + ".egg-info",
        "htmlcov",
        ".cache",
        ".hypothesis",
        ".pytest_cache",
    ]:
        dirname = os.path.join(ROOT_DIR, dir)
        if os.path.isdir(dirname):
            shutil.rmtree(dirname)
            print("Removed directory %r" % dir)

    for fname in ["MANIFEST", ".coverage"]:
        filename = os.path.join(ROOT_DIR, fname)
        if os.path.isfile(filename):
            os.remove(filename)
            print("Removed file %r" % fname)