File: clean.py

package info (click to toggle)
natsort 8.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 504 kB
  • sloc: python: 4,891; makefile: 17; sh: 4
file content (32 lines) | stat: -rwxr-xr-x 780 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env python

"""
Cross-platform clean of working directory.
INTENDED TO BE CALLED FROM PROJECT ROOT, NOT FROM dev/!
"""

import pathlib
import shutil

# Directories to obliterate
dirs = [
    pathlib.Path("build"),
    pathlib.Path("dist"),
    pathlib.Path(".pytest_cache"),
    pathlib.Path(".hypothesis"),
    pathlib.Path(".tox"),
]
dirs += pathlib.Path.cwd().glob("*.egg-info")
for d in dirs:
    if d.is_dir():
        shutil.rmtree(d, ignore_errors=True)
    elif d.is_file():
        d.unlink()  # just in case there is a file.

# Clean up any stray __pycache__.
for d in pathlib.Path.cwd().rglob("__pycache__"):
    shutil.rmtree(d, ignore_errors=True)

# Shouldn't be any .pyc left, but just in case
for f in pathlib.Path.cwd().rglob("*.pyc"):
    f.unlink()