Skip to content

Commit 4dca320

Browse files
committed
Added ruff cache clean invoke task to plugins
1 parent fd4f7be commit 4dca320

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

plugins/tasks.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
- setuptools >= 39.1.0
1010
"""
1111

12+
import os
1213
import pathlib
14+
import shutil
1315

1416
import invoke
1517

@@ -38,6 +40,23 @@
3840
TASK_ROOT_STR = str(TASK_ROOT)
3941

4042

43+
# shared function
44+
def rmrf(items, verbose=True):
45+
"""Silently remove a list of directories or files"""
46+
if isinstance(items, str):
47+
items = [items]
48+
49+
for item in items:
50+
if verbose:
51+
print("Removing {}".format(item))
52+
shutil.rmtree(item, ignore_errors=True)
53+
# rmtree doesn't remove bare files
54+
try:
55+
os.remove(item)
56+
except FileNotFoundError:
57+
pass
58+
59+
4160
@invoke.task(pre=[ext_test_tasks.pytest])
4261
@invoke.task()
4362
def pytest(_):
@@ -154,3 +173,14 @@ def format(context):
154173

155174

156175
namespace.add_task(format)
176+
177+
178+
@invoke.task()
179+
def ruff_clean(context):
180+
"""Remove .ruff_cache directory"""
181+
with context.cd(TASK_ROOT_STR):
182+
dirs = ['.ruff_cache']
183+
rmrf(dirs)
184+
185+
186+
namespace_clean.add_task(ruff_clean, 'ruff')

0 commit comments

Comments
 (0)