Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 315d89c

Browse files
author
RaphaelK
committed
black norm
1 parent 3fdbff9 commit 315d89c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

libinstall/script.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,40 @@
33
from os.path import isfile, join, splitext
44
import click
55
import random
6+
67
python_extension = ".py"
78
mypath = "./"
89

910

10-
1111
def install_libraries(lib):
1212
p = Popen(["pip3", "install", lib], stdout=PIPE, stderr=PIPE)
1313
while p.poll() is None:
1414
l = p.stdout.readline()
15-
click.echo(l.decode('utf-8'))
15+
click.echo(l.decode("utf-8"))
1616
click.echo(p.stdout.read().decode("utf-8"))
1717
output, error = p.communicate()
1818
if p.returncode != 0:
1919
click.echo("\n\nERROR occured while installing librairies:")
20-
return error.decode('utf-8')
20+
return error.decode("utf-8")
2121
else:
2222
return False
2323

24+
2425
def get_missing_libraries(traceback):
25-
tracebacks = traceback.split('\n')
26+
tracebacks = traceback.split("\n")
2627
lib = [elem for elem in tracebacks if "ModuleNotFoundError" in elem]
2728
if not lib:
2829
return tracebacks[-5:]
2930
lib = str(lib)
3031
lib = lib.split("'")
31-
click.echo('\n'.join(tracebacks[-5:]))
32+
click.echo("\n".join(tracebacks[-5:]))
3233
return lib[-2]
3334

35+
3436
def ispythonfile(pythonfile):
3537
return isfile(pythonfile) and splitext(pythonfile)[1] == python_extension
3638

39+
3740
def lunch_script(file_name):
3841
p = Popen(["python3", file_name], stdout=PIPE, stderr=PIPE)
3942
output, error = p.communicate()
@@ -42,25 +45,26 @@ def lunch_script(file_name):
4245
if "ModuleNotFoundError" in error:
4346
pass
4447
except TypeError:
45-
error = error.decode('utf-8')
48+
error = error.decode("utf-8")
4649
missing_lib = get_missing_libraries(error)
4750
if isinstance(missing_lib, list):
4851
click.echo("\n\nERROR occured while installing librairies:")
4952
click.echo("\n".join(missing_lib))
50-
return
51-
click.echo("Installing "+missing_lib+"")
53+
return
54+
click.echo("Installing " + missing_lib + "")
5255
error_lib = install_libraries(missing_lib)
5356
if error_lib:
5457
click.echo(error_lib)
5558
else:
56-
click.echo("Installation of "+missing_lib+" done")
59+
click.echo("Installation of " + missing_lib + " done")
5760
click.echo("-------------------------------------\n\n")
5861
lunch_script(file_name)
5962
return
6063

64+
6165
@click.command()
62-
@click.option('--all', is_flag=True, help="Run all the file in current directory")
63-
@click.argument('file')
66+
@click.option("--all", is_flag=True, help="Run all the file in current directory")
67+
@click.argument("file")
6468
def cli(all, file):
6569
click.echo("Thanks for using lib_install\n\n")
6670
if all:
@@ -71,10 +75,7 @@ def cli(all, file):
7175
pass
7276
for file_name in python_files:
7377
click.echo("++++++++++++++++++++++++++++++++")
74-
click.echo("Starting script for "+file_name+"")
78+
click.echo("Starting script for " + file_name + "")
7579
lunch_script(file_name)
7680
else:
7781
lunch_script(file)
78-
79-
80-

0 commit comments

Comments
 (0)