This repository was archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtasks.py
More file actions
125 lines (106 loc) · 2.89 KB
/
tasks.py
File metadata and controls
125 lines (106 loc) · 2.89 KB
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
116
117
118
119
120
121
122
123
124
125
import time
from invoke import task
from rich import print
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
class Handler(FileSystemEventHandler):
def __init__(self):
self.event_type = None
self.src_path = None
def on_any_event(self, event):
# if event.is_directory:
# return None
if event.src_path.find("__pycache__") == -1:
self.event_type = event.event_type
self.src_path = event.src_path
print(f"{time.asctime()} noticed: {event.event_type} on: {event.src_path}")
@task
def black_w(c, args):
"""
This will run black in a watching state
Args:
c (_type_): _description_
"""
print("[bold yellow] Black is watching files [/bold yellow]")
if args == "lint":
print(" [bold yellow]pylint is watching[/bold yellow]")
path = "cdapython"
file_event_handler = Handler()
observer = Observer()
observer.schedule(file_event_handler, path, recursive=True)
observer.start()
try:
while True:
try:
time.sleep(10)
if file_event_handler.event_type == "created":
continue
if file_event_handler.event_type == "modified":
c.run(f"black {file_event_handler.src_path}")
if args == "lint":
c.run(f"pylint {file_event_handler.src_path}")
except Exception as e:
print(e)
except KeyboardInterrupt:
observer.stop()
observer.join()
@task
def venv(c):
"""
This will create a venv for you
Args:
c (_type_): _description_
"""
print("Create venv ")
c.run("python3 -m venv venv && source venv/bin/activate")
@task
def formatting(c) -> None:
"""
This will run black formatting for you
Args:
c (_type_): _description_
"""
print("Formatting!")
c.run("black .")
@task
def mypy(c, args=None) -> None:
"""
This will run mypy to check the types in the cdapython
Args:
c (_type_): _description_
"""
print("Checking Types")
if args is None:
c.run("mypy cdapython")
else:
c.run(f"mypy {args}")
@task
def tests(c, args=None) -> None:
"""
This will run pytest
Args:
c (_type_): _description_
"""
print("Run pytest")
if args is None:
c.run("pytest .")
else:
c.run(f"pytest {args}")
@task
def lint(c, args=None) -> None:
"""
This will run pylint
Args:
c (_type_): _description_
args (_type_): _description_
"""
print(f"linting {args}")
if args is None:
c.run("pylint")
else:
c.run(f"pylint {args}")
c.run(f"pylint {args}")
@task
def uninstall(c, args=None) -> None:
print("uninstall and reinstall")
c.run("pip uninstall cdapython -y && pip install -e .")