File: clean.py

package info (click to toggle)
python-rjsmin 1.2.5%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,256 kB
  • sloc: javascript: 8,503; python: 5,315; ansic: 821; sh: 100; makefile: 19
file content (115 lines) | stat: -rw-r--r-- 3,225 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: ascii -*-
#
# Copyright 2018 - 2025
# Andr\xe9 Malo or his licensors, as applicable
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Cleanup tasks
~~~~~~~~~~~~~

"""

import invoke as _invoke

from ._inv import tasks as _tasks


@_invoke.task()
def py(ctx):
    """Wipe *.py[co] files"""
    ctx.shell.rm_rf(ctx.shell.glob("**/__pycache__/", "**/*.py[co]"))


@_invoke.task(py)
def dist(ctx):
    """Wipe all"""
    _tasks.execute(ctx, "clean.clean", so=True, cache=True)
    ctx.shell.rm_rf(ctx.shell.glob("*.egg-info"))


@_invoke.task(py, default=True)
def clean(ctx, so=False, cache=False):
    """
    Wipe *.py[co] files and test leftovers

    Parameters:
      so (bool):
        Clean *.so files, too? Default: false

      cache (bool):
        Clean various cache files and directories, too? Default: false
    """
    ctx.shell.rm(ctx.shell.files(".", ".coverage*"))
    path = ctx.paths.get("terraform")
    if path:
        gpath = ctx.shell.glob_escape(path.rstrip("/")) + "/**/"
        ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.auto.tfvars.json"))
        ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.tf.json"))
    path = ctx.paths.get("cloudformation")
    if path:
        gpath = ctx.shell.glob_escape(path.rstrip("/")) + "/**/"
        ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.auto.*.yaml"))
        ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.zip"))

    ctx.shell.rm_rf(ctx.shell.glob("tasks/**/*.generated*"))
    ctx.shell.rm_rf(
        "gcov.out",
        "setup.cfg",
        "docs/coverage/",
        "docs/gcov/",
        "build/",
        "dist/",
        ".sdist/",
        ".bdist/",
        ctx.doc.userdoc,
        ctx.doc.sphinx.build,
        ctx.doc.website.source,
        ctx.doc.website.target,
    )
    more = ctx.get("clean", {}).get("default", [])
    for glob in more:
        ctx.shell.rm_rf(ctx.shell.glob(glob))

    if cache:
        _tasks.execute(ctx, "clean.cache")
    if so:
        _tasks.execute(ctx, "clean.so")


@_invoke.task(name="cache")
def cacheclean(ctx):
    """Wipe Cache files"""
    path = ctx.paths.get("terraform")
    if path:
        gpath = ctx.shell.glob_escape(path.rstrip("/")) + "/**/"
        ctx.shell.rm_rf(ctx.shell.glob(gpath + ".terraform/"))
        ctx.shell.rm_rf(ctx.shell.glob(gpath + ".terraform.lock.hcl"))

    ctx.shell.rm_rf(
        ".tox/",
        ".cache/",
        ".pytest_cache/",
        "tests/.cache/",
        "tests/.pytest_cache/",
        ".mypy_cache/",
    )
    more = ctx.get("clean", {}).get("cache", [])
    for glob in more:
        ctx.shell.rm_rf(ctx.shell.glob(glob))


@_invoke.task(name="so")
def soclean(ctx):
    """Wipe *.so files"""
    ctx.shell.rm(ctx.shell.glob("**/*.pyd", "**/*.so"))