Skip to content

Commit f4d3af6

Browse files
committed
fix windows (p)npm cmd
1 parent d17af48 commit f4d3af6

5 files changed

Lines changed: 82 additions & 42 deletions

File tree

AGENTS.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ This project is a cross-desktop platform to making webapps with python as the ba
1515
- Selecting between GTK or Qt.
1616
- This app is built with the intention to make it cross-desktop platform. For Windows, Linux and macOS. GTK and Qt is a option for Linux, as this is required for picking the correct renderer. And this options is only meant for Linux and will be asked in all platform.
1717
- Selecting frameworks.
18-
- The user currently has 4 different options to pick for their project: That being:
18+
- The user currently has 4 different options to pick for their project:
1919
- Vanilla
2020
- Svelte
2121
- React
2222
- Vue
2323
- Selecting variant.
2424
- This being able to use JavaScript or TypeScript.
2525
- Selecting their NodeJS Package Manager
26-
- The user has 2 different options to pick for their project: That being:
26+
- The user has 2 different options to pick for their project:
2727
- npm : NodeJS's default package manager.
2828
- pnpm : A faster alternative to npm.
29-
-
3029
- [@src/initialize.py](src/initialize.py)
31-
- This is where when the user confirms that it's ready to be initialized, it starts here. This includes:
30+
- When the user confirms that it's ready to be initialized, it starts here. This includes:
3231
- Copying icons.
3332
- From `{pyderProjectRoot}/icon/*` to `{userProject}/icon/`
3433
- Creating file structure.
@@ -42,7 +41,7 @@ This project is a cross-desktop platform to making webapps with python as the ba
4241
- Dev mode being, running the page at `http://localhost:5173`.
4342
- Compiled mode being, running the page at `src/frontend/dist/index.html`.
4443
- `run.py`
45-
- This is where the user can run the flags like `dev`, `compile`, `test`.
44+
- The user can run the flags like `dev`, `compile`, `test`.
4645
- `dev` flag:
4746
- This will run the development server in `src/frontend/` from `subprocess.Popen`, which will open the server in a thread.
4847
- And after a second, it will run pywebview and opening a page at `http://localhost:5173`.
@@ -54,7 +53,7 @@ This project is a cross-desktop platform to making webapps with python as the ba
5453
- It first builds the app in `src/frontend/` with nothing special. Just doing `npm/pnpm run build`.
5554
- Then, instead of building for python, it will open the window. That's it.
5655
- `src/backend/api.py`
57-
- This is where the user can do all their Python contacting things. There's only one function and that's getting the user's operating system, and then returning their config path.
56+
- The user can do all their Python contacting things. There's only one function and that's getting the user's operating system, and then returning their config path.
5857
- `.gitignore`
5958
- This just has the ignores for pnpm, python and other things. Mainly used when the user wants to put their project to GitHub, GitLab, GitBucket, etc...
6059
- `pyder.py`
@@ -104,7 +103,9 @@ Instead of using [@main.py](main.py), you should use [@tests.py](tests.py) and c
104103

105104
You should NOT touch [@CONTRIBUTING.md](CONTRIBUTING.md), [@README.md](README.md), [@LICENSE](LICENSE), and [@CHANGELOG.md](CHANGELOG.md). These files are not meant to touch by a LLM. Same thing applies to `git` commands too. Except for `git diff`, `git status` and other commands that doesn't change anything.
106105

107-
This project prefers to have every variable and functions to be `camelCase`, as it it widely used around the whole project. Please do NOT use anything other than `camelCase`.
106+
This project prefers to have every variable and functions to be `camelCase`, as it it widely used around the whole project. Please do NOT use anything other than `camelCase`. Always keep the code readable, simple, and follow my exact coding style I made.
107+
108+
If something isn't clear. Please refer to asking me instead of hallucinating.
108109

109110
---
110111

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
requests
21
InquirerPy
32
termcolor
43
pyinstaller

src/initialize.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
variant,
1818
packageManager,
1919
):
20-
20+
2121
self.projectName = projectName
2222
self.projectID = projectID
2323
self.domainSystem = domainSystem
@@ -26,6 +26,18 @@ def __init__(
2626
self.packageManager = packageManager
2727
self.qtorgtk = qtorgtk
2828

29+
def resolveCommand(self, command):
30+
commandPath = shutil.which(command)
31+
if commandPath:
32+
return commandPath
33+
34+
if os.name == "nt":
35+
commandPath = shutil.which(f"{command}.cmd")
36+
if commandPath:
37+
return commandPath
38+
39+
return command
40+
2941
def getPythonExecutable(self):
3042
if not getattr(sys, "frozen", False):
3143
return sys.executable
@@ -76,7 +88,7 @@ def startPackageManager(self):
7688

7789
if self.packageManager == "npm":
7890
command = [
79-
"npm",
91+
self.resolveCommand("npm"),
8092
"create",
8193
"vite@latest",
8294
"src/frontend",
@@ -87,7 +99,7 @@ def startPackageManager(self):
8799
]
88100
else:
89101
command = [
90-
self.packageManager,
102+
self.resolveCommand(self.packageManager),
91103
"create",
92104
"vite@latest",
93105
"src/frontend",
@@ -117,6 +129,7 @@ def mainScript():
117129
import argparse
118130
import subprocess
119131
import sys
132+
import shutil
120133
from pathlib import Path
121134
import window as w
122135
import time
@@ -126,8 +139,20 @@ def mainScript():
126139
frontendDir = projectRoot / "src" / "frontend"
127140
packageManager = "{self.packageManager}"
128141
142+
def resolveCommand(command):
143+
commandPath = shutil.which(command)
144+
if commandPath:
145+
return commandPath
146+
147+
if sys.platform == "win32":
148+
commandPath = shutil.which(f"{{command}}.cmd")
149+
if commandPath:
150+
return commandPath
151+
152+
return command
153+
129154
def buildFrontend():
130-
subprocess.run([packageManager, "run", "build"], cwd=frontendDir, check=True)
155+
subprocess.run([resolveCommand(packageManager), "run", "build"], cwd=frontendDir, check=True)
131156
132157
def compileApp():
133158
buildFrontend()
@@ -171,7 +196,7 @@ def main():
171196
if args.command == "compile":
172197
compileApp()
173198
if args.command == "dev":
174-
devServer = subprocess.Popen([packageManager, "run", "dev"], cwd=frontendDir)
199+
devServer = subprocess.Popen([resolveCommand(packageManager), "run", "dev"], cwd=frontendDir)
175200
print("Starting dev server...")
176201
try:
177202
time.sleep(1)
@@ -329,14 +354,14 @@ def startWindow(dev):
329354
subprocess.run([pythonExecutable, "-m", "venv", "venv"], cwd=self.projectID, check=True)
330355

331356
if sys.platform == "win32":
332-
venvPython = ".\\venv\\Scripts\\python"
357+
venvPython = f".\\{self.projectID}\\venv\\Scripts\\python"
333358
subprocess.run(
334359
[venvPython, "-m", "pip", "install", "-r", "requirements.txt"],
335360
cwd=self.projectID,
336361
check=True,
337362
)
338363
else:
339-
venvPython = "./venv/bin/python"
364+
venvPython = f"./{self.projectID}/venv/bin/python"
340365
subprocess.run(
341366
[venvPython, "-m", "pip", "install", "-r", "requirements.txt"],
342367
cwd=self.projectID,
@@ -380,8 +405,10 @@ def start(
380405

381406
print.log("If you're lazy (like me), just copy this code below. This for macOS/Linux.")
382407
print.log(f" cd {projectID}/src/frontend/ && {packageManager} install && cd ../.. && venv/bin/python run.py dev")
383-
print.log("For windows powershell.")
384-
print.log(f" cd {projectID}\\src\\frontend\\ && {packageManager} install && cd ..\\.. && venv\\Scripts\\python run.py dev")
408+
print.log("For windows powershell <7.")
409+
print.log(f" cd project-test\\src\\frontend; if ($?) {{ {packageManager} install }}; if ($?) {{ cd ..\\.. }}; if ($?) {{ venv\\Scripts\\python run.py dev }}")
410+
print.log("For windows powershell 7+.")
411+
print.log(f" cd {projectID}\\src\\frontend && {packageManager} install && cd ..\\.. && venv\\Scripts\\python run.py dev")
385412
print.empty()
386413

387414
print.log("To compile after installing the frontend dependencies, run:")

src/interactive.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import subprocess
34
import time
45

@@ -93,22 +94,34 @@ def packageManager(self):
9394
class Checks:
9495
def __init__(self):
9596
pass
97+
98+
def resolveCommand(self, command):
99+
commandPath = shutil.which(command)
100+
if commandPath:
101+
return commandPath
102+
103+
if os.name == "nt":
104+
commandPath = shutil.which(f"{command}.cmd")
105+
if commandPath:
106+
return commandPath
107+
108+
return command
96109

97110
def npm(self):
98111
try:
99-
subprocess.run(["npm", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
112+
subprocess.run([self.resolveCommand("npm"), "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
100113
print.success("npm is installed.")
101114
return True
102-
except subprocess.CalledProcessError:
115+
except (subprocess.CalledProcessError, FileNotFoundError):
103116
print.error("npm is not installed.")
104117
return False
105118

106119
def pnpm(self):
107120
try:
108-
subprocess.run(["pnpm", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
121+
subprocess.run([self.resolveCommand("pnpm"), "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
109122
print.success("pnpm is installed.")
110123
return True
111-
except subprocess.CalledProcessError:
124+
except (subprocess.CalledProcessError, FileNotFoundError):
112125
print.error("pnpm is not installed.")
113126
return False
114127

@@ -117,7 +130,7 @@ def python(self):
117130
subprocess.run(["python", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
118131
print.success("Python is installed.")
119132
return True
120-
except subprocess.CalledProcessError:
133+
except (subprocess.CalledProcessError, FileNotFoundError):
121134
print.error("Python is not installed.")
122135
return False
123136

@@ -157,4 +170,4 @@ def start():
157170
if _continue:
158171
initialize.start(projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager)
159172
else:
160-
print.log("Pyder selection cancelled.")
173+
print.log("Pyder selection cancelled.")

src/print.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
from termcolor import colored
22

3-
def success(m):
4-
s = "✓"
5-
c = "green"
6-
pta(s, c, m)
7-
def error(m):
8-
s = "✗"
9-
c = "light_red"
10-
pta(s, c, m)
11-
def log(m):
12-
s = "⋯"
13-
c = "dark_grey"
14-
pta(s, c, m)
15-
def warning(m):
16-
s = "!"
17-
c = "yellow"
18-
pta(s, c, m)
3+
def success(message):
4+
symbol = "✓"
5+
color = "green"
6+
pta(symbol, color, message)
7+
def error(message):
8+
symbol = "✗"
9+
color = "light_red"
10+
pta(symbol, color, message)
11+
def log(message):
12+
symbol = "⋯"
13+
color = "dark_grey"
14+
pta(symbol, color, message)
15+
def warning(message):
16+
symbol = "!"
17+
color = "yellow"
18+
pta(symbol, color, message)
1919

20-
def pta(t, c, m):
20+
def pta(tag, color, message):
2121
print(
22-
colored(f"{t}", c, force_color=True)
22+
colored(f"{tag}", color, force_color=True)
2323
+ " " +
24-
m
24+
message
2525
)
2626

2727
def empty():

0 commit comments

Comments
 (0)