Skip to content

Commit 6844ac2

Browse files
committed
conversion projectName to compatible
1 parent 004a0d7 commit 6844ac2

5 files changed

Lines changed: 92 additions & 46 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*.pyc
33
__pycache__
44

5-
projectTest
5+
project-test
66

77
build
88
dist

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,5 @@ It's at [the wiki](https://github.com/PinpointTools/Pyder/wiki)! You can find on
4545
# Known Issues:
4646
- Unstable. Still in ALPHA.
4747
- Possibly already stable enough. Might be in Beta. rebuild your Vite app and the PyWebView page will reload.
48-
- `package.json` containing everything like Project and such.
49-
- We're planning on something like this, but `pyder-project.json` instead.
50-
- It'll contain something like
51-
```json
52-
{
53-
"projectName": "pyder-project",
54-
"domainSystem": "io.github.pinpointtools",
55-
}
56-
```
48+
- Option to add AGENT.md
49+
- For the people who code with LLMs (I'm one of them)

src/initialize.py

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ class Initialize:
1010
def __init__(
1111
self,
1212
projectName,
13+
projectID,
1314
domainSystem,
1415
qtorgtk,
1516
framework,
1617
variant,
1718
packageManager,
1819
):
20+
1921
self.projectName = projectName
22+
self.projectID = projectID
2023
self.domainSystem = domainSystem
2124
self.framework = framework
2225
self.variant = variant
@@ -37,10 +40,10 @@ def getPythonExecutable(self):
3740
)
3841

3942
def fileSystem(self):
40-
os.makedirs(self.projectName)
41-
os.makedirs(f"{self.projectName}/icon")
42-
os.makedirs(f"{self.projectName}/src/backend")
43-
os.makedirs(f"{self.projectName}/src/frontend")
43+
os.makedirs(self.projectID)
44+
os.makedirs(f"{self.projectID}/icon")
45+
os.makedirs(f"{self.projectID}/src/backend")
46+
os.makedirs(f"{self.projectID}/src/frontend")
4447

4548
def copyIcons(self):
4649
if getattr(sys, "frozen", False):
@@ -49,7 +52,7 @@ def copyIcons(self):
4952
resourceRoot = str(SOURCE_ROOT)
5053

5154
sourceDir = Path(resourceRoot) / "icon"
52-
destinationDir = Path(self.projectName) / "icon"
55+
destinationDir = Path(self.projectID) / "icon"
5356

5457
for iconName in ("512.png", "512.ico", "512.icns"):
5558
shutil.copy2(sourceDir / iconName, destinationDir / iconName)
@@ -58,7 +61,7 @@ def copyIcons(self):
5861

5962
def startPackageManager(self):
6063
print.log(f"Installing frontend with {self.packageManager}...")
61-
frontendDir = os.path.join(self.projectName, "src", "frontend")
64+
frontendDir = os.path.join(self.projectID, "src", "frontend")
6265
templateMap = {
6366
("Vanilla", "JavaScript"): "vanilla",
6467
("Vanilla", "TypeScript"): "vanilla-ts",
@@ -93,7 +96,7 @@ def startPackageManager(self):
9396
"--no-interactive",
9497
]
9598

96-
subprocess.run(command, cwd=self.projectName, check=True)
99+
subprocess.run(command, cwd=self.projectID, check=True)
97100
print.success(f"Frontend scaffolded in {frontendDir}")
98101

99102
def startPython(self):
@@ -117,6 +120,7 @@ def mainScript():
117120
from pathlib import Path
118121
import window as w
119122
import time
123+
from pyder import *
120124
121125
projectRoot = Path(__file__).resolve().parent
122126
frontendDir = projectRoot / "src" / "frontend"
@@ -145,7 +149,7 @@ def compileApp():
145149
"--noconfirm",
146150
"--windowed",
147151
"--name",
148-
"{self.projectName}",
152+
pyder_projectID,
149153
"--add-data",
150154
dataArg,
151155
"--add-data",
@@ -173,27 +177,28 @@ def main():
173177
time.sleep(1)
174178
w.startWindow(True)
175179
finally:
176-
devServer.terminate()
180+
devServer.kill()
177181
178182
if __name__ == "__main__":
179183
try:
180184
main()
181185
except KeyboardInterrupt:
182186
print("Interrupted by user")
183187
exit(1)"""
184-
with open(f"{self.projectName}/run.py", "w") as f:
188+
with open(f"{self.projectID}/run.py", "w") as f:
185189
f.write(script)
186190
##########################################################################################
187191

188192
#################################### API SCRIPT ##################################
189-
apiScript = f"""import webview as wv
193+
apiScript = """import webview as wv
190194
import sys
191195
import os
196+
from pyder import *
192197
193198
class API:
194199
def __init__(self):
195200
self.window = wv.active_window()
196-
self.appID = "{self.domainSystem}.{self.projectName}"
201+
self.appID = f"{pyder_domainSystem}.{pyder_projectID}"
197202
198203
def getConfigPath(self):
199204
if sys.platform == "win32":
@@ -205,13 +210,15 @@ def getConfigPath(self):
205210
else:
206211
configPath = os.path.join(os.getenv("HOME"), ".config", self.appID)
207212
return configPath"""
208-
with open(f"{self.projectName}/src/backend/api.py", "w") as f:
213+
with open(f"{self.projectID}/src/backend/api.py", "w") as f:
209214
f.write(apiScript)
210215
##########################################################################################
211216

212217
################################# WINDOW SCRIPT ########################################
213-
windowScript = f"""import os
218+
windowScript = """import os
214219
import sys
220+
import json
221+
from pyder import *
215222
216223
import webview as wv
217224
from src.backend.api import API
@@ -244,11 +251,11 @@ def startWindow(dev):
244251
)
245252
246253
wv.create_window(
247-
title="{self.projectName}",
254+
title=pyder_projectName,
248255
url=str(pathToApp),
249256
js_api=API(),
250-
width=800,
251-
height=600,
257+
width=pyder_window_initSize_v1,
258+
height=pyder_window_initSize_v2,
252259
)
253260
254261
wv.start(
@@ -260,7 +267,7 @@ def startWindow(dev):
260267
261268
if __name__ == "__main__":
262269
startWindow(False)"""
263-
with open(f"{self.projectName}/window.py", "w") as f:
270+
with open(f"{self.projectID}/window.py", "w") as f:
264271
f.write(windowScript)
265272
##########################################################################################
266273

@@ -269,6 +276,7 @@ def startWindow(dev):
269276
__pycache__
270277
*.pyc
271278
build
279+
dist
272280
*venv*
273281
274282
# npm
@@ -280,38 +288,66 @@ def startWindow(dev):
280288
281289
# misc
282290
.env"""
283-
with open(f"{self.projectName}/.gitignore", "w") as f:
291+
with open(f"{self.projectID}/.gitignore", "w") as f:
284292
f.write(gitIgnore)
293+
##########################################################################################
285294

295+
##################################### PYDER PYTHON #################################
296+
pyderProject = f"""_pyder_project = [
297+
{{
298+
"projectName": "{self.projectName}",
299+
"domainSystem": "{self.domainSystem}",
300+
"projectID": "{self.projectID}",
301+
"version": "0.1.0",
302+
"window": {{
303+
"minSize": [800, 600],
304+
"maxSize": [1280, 720],
305+
"initSize": [800, 600]
306+
}}
307+
}}
308+
]
309+
310+
pyder_projectName = _pyder_project[0]["projectName"]
311+
pyder_domainSystem = _pyder_project[0]["domainSystem"]
312+
pyder_projectID = _pyder_project[0]["projectID"]
313+
pyder_version = _pyder_project[0]["version"]
314+
315+
pyder_window = _pyder_project[0]["window"]
316+
pyder_window_minSize_v1, pyder_window_minSize_v2 = pyder_window["minSize"]
317+
pyder_window_maxSize_v1, pyder_window_maxSize_v2 = pyder_window["maxSize"]
318+
pyder_window_initSize_v1, pyder_window_initSize_v2 = pyder_window["initSize"]"""
319+
with open(f"{self.projectID}/pyder.py", "w") as f:
320+
f.write(pyderProject)
286321
##########################################################################################
287322

288-
with open(f"{self.projectName}/requirements.txt", "w") as f:
323+
with open(f"{self.projectID}/requirements.txt", "w") as f:
289324
for lib in libraries():
290325
f.write(f"{lib}\n")
291326

292327
mainScript()
293328
pythonExecutable = self.getPythonExecutable()
294-
subprocess.run([pythonExecutable, "-m", "venv", "venv"], cwd=self.projectName, check=True)
329+
subprocess.run([pythonExecutable, "-m", "venv", "venv"], cwd=self.projectID, check=True)
295330

296331
if sys.platform == "win32":
297332
venvPython = ".\\venv\\Scripts\\python"
298333
subprocess.run(
299334
[venvPython, "-m", "pip", "install", "-r", "requirements.txt"],
300-
cwd=self.projectName,
335+
cwd=self.projectID,
301336
check=True,
302337
)
303338
else:
304339
venvPython = "./venv/bin/python"
305340
subprocess.run(
306341
[venvPython, "-m", "pip", "install", "-r", "requirements.txt"],
307-
cwd=self.projectName,
342+
cwd=self.projectID,
308343
check=True,
309344
)
310345

311-
print.success(f"Backend scaffolded in {self.projectName}/src/backend")
346+
print.success(f"Backend scaffolded in {self.projectID}/src/backend")
312347

313348
def start(
314349
projectName,
350+
projectID,
315351
domainSystem,
316352
qtorgtk,
317353
framework,
@@ -320,6 +356,7 @@ def start(
320356
):
321357
init = Initialize(
322358
projectName,
359+
projectID,
323360
domainSystem,
324361
qtorgtk,
325362
framework,
@@ -332,19 +369,19 @@ def start(
332369
init.startPython()
333370

334371
# yap yap
335-
print.success(f"Project initialized in {projectName}")
336-
print.log(f"Before you run the app, make sure you've installed the required dependencies at `{projectName}/src/frontend/`")
337-
print.log(f"The reason why this wasn't installed automatically is because of subprocess being a bitch because it can't run `{packageManager} install` @ `{projectName}/src/frontend/`")
338-
print.log(f"For python libraries @ `{projectName}/requirements.txt`, it's already installed in a virtual environment. Just activate it with `source venv/bin/activate` (Linux/macOS) or `venv\\Scripts\\activate` (Windows)")
372+
print.success(f"Project initialized in {projectID}")
373+
print.log(f"Before you run the app, make sure you've installed the required dependencies at `{projectID}/src/frontend/`")
374+
print.log(f"The reason why this wasn't installed automatically is because of subprocess being a bitch because it can't run `{packageManager} install` @ `{projectID}/src/frontend/`")
375+
print.log(f"For python libraries @ `{projectID}/requirements.txt`, it's already installed in a virtual environment. Just activate it with `source venv/bin/activate` (Linux/macOS) or `venv\\Scripts\\activate` (Windows)")
339376
print.log("To run the app, use `python run.py test`. This command will build Vite, and then launch `window.py`.")
340377
print.log("To open the already-built app directly, use `python window.py`.")
341378
print.log("To compile the app, use `python run.py compile`. This command will build Vite and package `window.py` with PyInstaller.")
342379
print.empty()
343380

344381
print.log("If you're lazy (like me), just copy this code below. This for macOS/Linux.")
345-
print.log(f" cd {projectName}/src/frontend/ && {packageManager} install && cd ../.. && venv/bin/python run.py dev")
382+
print.log(f" cd {projectID}/src/frontend/ && {packageManager} install && cd ../.. && venv/bin/python run.py dev")
346383
print.log("For windows powershell.")
347-
print.log(f" cd {projectName}\\src\\frontend\\ && {packageManager} install && cd ..\\.. && venv\\Scripts\\python run.py dev")
384+
print.log(f" cd {projectID}\\src\\frontend\\ && {packageManager} install && cd ..\\.. && venv\\Scripts\\python run.py dev")
348385
print.empty()
349386

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

src/interactive.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@ def projectName(self):
1919
print.error("Project name cannot be empty.")
2020
exit()
2121

22-
return projectName
22+
# check if `projectName` has spaces, special characters and/or caps
23+
if " " in projectName or not projectName.isalnum() or not projectName.islower():
24+
# convert:
25+
# - spaces -> dashes
26+
# - remove special characters
27+
# - lowercase everything
28+
projectID = "".join(
29+
c.lower() if c.isalnum() else "-" if c == " " else ""
30+
for c in projectName
31+
).strip("-")
32+
33+
print.log(f"`{projectName}` has been converted to `{projectID}` for projectID.")
34+
else:
35+
projectID = projectName
36+
37+
return projectName, projectID
2338

2439
def domainSystem(self):
2540
domainSystem = inquirer.text(
@@ -109,13 +124,13 @@ def python(self):
109124
def inOrder():
110125
calls = Calls()
111126

112-
projectName = calls.projectName()
127+
projectName, projectID = calls.projectName()
113128
domainSystem = calls.domainSystem()
114129
qtorgtk = calls.qtorgtk()
115130
framework = calls.framework()
116131
variant = calls.variant()
117132
packageManager = calls.packageManager()
118-
return projectName, domainSystem, qtorgtk, framework, variant, packageManager
133+
return projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager
119134

120135
def check(packageManager):
121136
check = Checks()
@@ -130,7 +145,7 @@ def check(packageManager):
130145
check.python()
131146

132147
def start():
133-
projectName, domainSystem, qtorgtk, framework, variant, packageManager = inOrder()
148+
projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager = inOrder()
134149
print.empty()
135150
check(packageManager)
136151

@@ -140,6 +155,6 @@ def start():
140155
).execute()
141156

142157
if _continue:
143-
initialize.start(projectName, domainSystem, qtorgtk, framework, variant, packageManager)
158+
initialize.start(projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager)
144159
else:
145160
print.log("Pyder selection cancelled.")

tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
def startTest():
44
init.start(
5-
"projectTest",
5+
"Project Test",
6+
"project-test",
67
"io.github.pinpointtools",
78
"GTK",
89
"React",

0 commit comments

Comments
 (0)