11# type: ignore
22import shutil
3- import subprocess
43
54import toml
65from invoke import Context , task
7- from rich .console import Console
86
97import monkey_patch_invoke as _ # noqa: F401
108
11- console = Console ()
12-
139
1410def get_pep8_compliant_name (project_name : str ) -> str :
1511 return project_name .replace ('-' , '_' )
@@ -22,14 +18,6 @@ def get_project_path():
2218 return project_name
2319
2420
25- def execute_command (command : str ) -> dict [str , str ]:
26- with subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE ) as process :
27- stdout , stderr = process .communicate ()
28- if process .returncode != 0 :
29- raise Exception (stderr .decode ())
30- return {'command' : command , 'result' : stdout .decode ()}
31-
32-
3321@task
3422def run (context : Context ):
3523 context .run (f'python { get_project_path ()} /main.py' , pty = True )
@@ -41,23 +29,15 @@ def test(context: Context):
4129
4230
4331@task
44- def format_code (context : Context , verbose : bool = False ) -> None :
32+ def format_code (context : Context , verbose : bool = False ):
4533 commands = [
4634 f'pautoflake { get_project_path ()} ' ,
4735 f'ruff --fix { get_project_path ()} ' ,
4836 f'yapf --in-place --recursive --parallel { get_project_path ()} ' ,
4937 ]
50- results : list [dict [str , str ]] = []
51- with console .status ('[bold green] Formatting code...' ):
52- for command in commands :
53- results .append (execute_command (command ))
5438
55- if verbose :
56- for result in results :
57- console .print (f'$ { result ["command" ]} ' )
58- console .print (result ['result' ])
59-
60- console .print ('[bold green]Success[/bold green]' )
39+ for command in commands :
40+ context .run (command , pty = True )
6141
6242
6343@task
@@ -69,7 +49,6 @@ def check(context: Context):
6949@task
7050def check_code_style (context : Context ):
7151 commands = [
72- f'pautoflake { get_project_path ()} --check' ,
7352 f'ruff { get_project_path ()} ' ,
7453 f'yapf --diff --recursive --parallel { get_project_path ()} ' ,
7554 ]
0 commit comments