Debian Codegraph @

tasks/clean.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2018 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 """
18 Cleanup tasks
19 ~~~~~~~~~~~~~
20
21 """
22
23 import invoke as _invoke
24
25 from ._inv import tasks as _tasks
26
27
28 @_invoke.task()
29 def py(ctx):
30 """Wipe *.py[co] files"""
31 ctx.shell.rm_rf(ctx.shell.glob("**/__pycache__/", "**/*.py[co]"))
32
33
34 @_invoke.task(py)
35 def dist(ctx):
36 """Wipe all"""
37 _tasks.execute(ctx, "clean.clean", so=True, cache=True)
38 ctx.shell.rm_rf(ctx.shell.glob("*.egg-info"))
39
40
41 @_invoke.task(py, default=True)
42 def clean(ctx, so=False, cache=False):
43 """
44 Wipe *.py[co] files and test leftovers
45
46 Parameters:
47 so (bool):
48 Clean *.so files, too? Default: false
49
50 cache (bool):
51 Clean various cache files and directories, too? Default: false
52 """
53 ctx.shell.rm(ctx.shell.files(".", ".coverage*"))
54 path = ctx.paths.get("terraform")
55 if path:
56 gpath = ctx.shell.glob_escape(path.rstrip("/")) + "/**/"
57 ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.auto.tfvars.json"))
58 ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.tf.json"))
59 path = ctx.paths.get("cloudformation")
60 if path:
61 gpath = ctx.shell.glob_escape(path.rstrip("/")) + "/**/"
62 ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.auto.*.yaml"))
63 ctx.shell.rm_rf(ctx.shell.glob(gpath + "*.zip"))
64
65 ctx.shell.rm_rf(ctx.shell.glob("tasks/**/*.generated*"))
66 ctx.shell.rm_rf(
67 "gcov.out",
68 "setup.cfg",
69 "docs/coverage/",
70 "docs/gcov/",
71 "build/",
72 "dist/",
73 ".sdist/",
74 ".bdist/",
75 ctx.doc.userdoc,
76 ctx.doc.sphinx.build,
77 ctx.doc.website.source,
78 ctx.doc.website.target,
79 )
80 more = ctx.get("clean", {}).get("default", [])
81 for glob in more:
82 ctx.shell.rm_rf(ctx.shell.glob(glob))
83
84 if cache:
85 _tasks.execute(ctx, "clean.cache")
86 if so:
87 _tasks.execute(ctx, "clean.so")
88
89
90 @_invoke.task(name="cache")
91 def cacheclean(ctx):
92 """Wipe Cache files"""
93 path = ctx.paths.get("terraform")
94 if path:
95 gpath = ctx.shell.glob_escape(path.rstrip("/")) + "/**/"
96 ctx.shell.rm_rf(ctx.shell.glob(gpath + ".terraform/"))
97 ctx.shell.rm_rf(ctx.shell.glob(gpath + ".terraform.lock.hcl"))
98
99 ctx.shell.rm_rf(
100 ".tox/",
101 ".cache/",
102 ".pytest_cache/",
103 "tests/.cache/",
104 "tests/.pytest_cache/",
105 ".mypy_cache/",
106 )
107 more = ctx.get("clean", {}).get("cache", [])
108 for glob in more:
109 ctx.shell.rm_rf(ctx.shell.glob(glob))
110
111
112 @_invoke.task(name="so")
113 def soclean(ctx):
114 """Wipe *.so files"""
115 ctx.shell.rm(ctx.shell.glob("**/*.pyd", "**/*.so"))