-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_cly.py
executable file
·61 lines (46 loc) · 1.41 KB
/
install_cly.py
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
#!/usr/bin/env python3
"""
Install CLY?! package to project.
Install/update CLY?! latest version or pass version to script (in the format
major.minor.patch), to install/update specific version.
"""
import shutil
import subprocess # nosec
import sys
from pathlib import Path
PROJECT_ROOT: Path = Path(__file__).resolve().parent
CLY: str = "[email protected]:mateusoliveira43/cly.git"
SOURCE: Path = PROJECT_ROOT / "cly/cly"
def get_cly() -> str:
"""
Get CLY?!'s source code.
Returns
-------
str
Command to clone CLY?!'s Git repository.
"""
try:
return f"git clone --branch {sys.argv[1]} {CLY}"
except IndexError:
return f"git clone {CLY}"
def copy_files_to_scripts(folder: Path) -> None:
"""
Copy package to the project's scripts folder.
Files with the same name are overwritten.
Parameters
----------
folder : Path
Folder or file to be copied.
"""
for file in folder.glob("*"):
if file.is_dir():
copy_files_to_scripts(file)
else:
destination = (
PROJECT_ROOT / "scripts/cly" / file.relative_to(SOURCE)
)
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(src=file, dst=destination)
subprocess.run(get_cly(), shell=True, check=True, encoding="utf-8") # nosec
copy_files_to_scripts(SOURCE)
shutil.rmtree(PROJECT_ROOT / "cly")