-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
114 lines (100 loc) · 4.59 KB
/
Copy pathmain.py
File metadata and controls
114 lines (100 loc) · 4.59 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
import src.interactive as inter
import src.print as print
import src.initialize as init
import src.misc as misc
import argparse
import subprocess
import sys
import os
import urllib.request
from InquirerPy import inquirer
if getattr(sys, 'frozen', False):
basePath = sys._MEIPASS
else:
basePath = os.path.dirname(os.path.abspath(__file__))
def argParser():
parser = argparse.ArgumentParser(description="")
subparsers = parser.add_subparsers(dest="command", help="Available commands")
# == Run ==
runParser = subparsers.add_parser("run", help="Able to run commands that are available in the project's run.py")
runParser.add_argument("runArgs", nargs=argparse.REMAINDER, help="Arguments to pass to run.py")
# == Version ==
subparsers.add_parser("version", help="Displays current version")
# == Install ==
installParser = subparsers.add_parser("install", help="Installs the project's dependencies")
installParser.add_argument("type", choices=["frontend", "backend"], help="Install either in Frontend or Backend")
installParser.add_argument("package", nargs=argparse.REMAINDER, help="Package(s) to install")
# == Init ==
initParser = subparsers.add_parser("init", help="Initializes a new Pyder project with the maintainer's choice of framework.")
initParser.add_argument("name", help="Name of the project")
initParser.add_argument("domainSystem", help="The domain system to use (e.g. io.github.pinpointtools)")
# == == ==
args = parser.parse_args()
if args.command is None:
inter.start()
elif args.command == "run":
if os.path.exists(".venv") or os.path.exists("venv"):
subprocess.run([f"{misc.getPython()}python3", "run.py", *args.runArgs])
else:
print.error("No virtual environment found.")
_continue = inquirer.confirm(
message="Do you want to create a virtual environment?",
).execute()
if _continue:
subprocess.run(["python3", "-m", "venv", ".venv"])
print.success("Virtual environment created successfully.")
print.log("Continuing with the command...")
subprocess.run([f"{misc.getPython()}python3", "run.py", *args.runArgs])
else:
return
elif args.command == "version":
url = "https://raw.githubusercontent.com/PinpointTools/Pyder/refs/heads/main/version.txt"
try:
with urllib.request.urlopen(url) as response:
latestVersion = response.read().decode('utf-8').strip()
except Exception as e:
print.error(f"Error fetching URL: {e}")
return None
versionPath = os.path.join(basePath, "version.txt")
with open(versionPath, "r") as f:
version = f.read().strip()
print.log(f"pyder ver; {version}")
if version != latestVersion:
print.warning(f"your pyder is out of date! ({version} != {latestVersion})")
else:
print.success(f"your pyder is up to date! ({version} == {latestVersion})")
elif args.command == "install":
if args.package:
print.log(f"Installing {args.package} for {args.type}...")
if args.type == "frontend":
subprocess.run(["npm", "install", *args.package], cwd="src/frontend")
elif args.type == "backend":
if os.path.exists(".venv") or os.path.exists("venv"):
subprocess.run([f"{misc.getPython()}pip", "install", *args.package])
else:
return print.error("No virtual environment found. Or it's a different folder name? We'll never know!")
print.success(f"Sucsesfully installed {args.package} for {args.type}.")
print.log("Or did it fail? Hopefully it didn't.")
else:
print.error("Please specify a package to install")
elif args.command == "init":
if args.name and args.domainSystem:
print.log(f"Initializing new Pyder project '{args.name}' with domain system '{args.domainSystem}'...")
init.start(
args.name,
misc.convertNameToID(args.name),
args.domainSystem,
"Qt",
"Svelte",
"TypeScript",
"pnpm",
False,
)
else:
print.error("Please specify a name and domain system for the project")
return args
if __name__ == "__main__":
try:
argParser()
except KeyboardInterrupt:
print.warning("Keyboard interuption. Exiting...")