1
- import datetime
2
1
import json
3
2
from pathlib import Path
4
3
from typing import Optional
5
4
6
5
import jinja2
6
+ import requests
7
7
import toml
8
8
9
9
from pyscript import LATEST_PYSCRIPT_VERSION , config
@@ -19,7 +19,7 @@ def create_project_html(
19
19
python_file_path : str ,
20
20
config_file_path : str ,
21
21
output_file_path : Path ,
22
- pyscript_version : str = LATEST_PYSCRIPT_VERSION ,
22
+ pyscript_version : str ,
23
23
template : str = "basic.html" ,
24
24
) -> None :
25
25
"""Write a Python script string to an HTML file template.
@@ -54,9 +54,9 @@ def save_config_file(config_file: Path, configuration: dict):
54
54
55
55
Params:
56
56
57
- - config_file(Path): path configuration file. (i.e.: "pyscript.toml"). Supported
58
- formats: `toml` and `json`.
59
- - configuration(dict): app configuration to be saved
57
+ - config_file(Path): path configuration file. (i.e.: "pyscript.toml"). Supported
58
+ formats: `toml` and `json`.
59
+ - configuration(dict): app configuration to be saved
60
60
61
61
Return:
62
62
(None)
@@ -73,7 +73,7 @@ def create_project(
73
73
app_description : str ,
74
74
author_name : str ,
75
75
author_email : str ,
76
- pyscript_version : str = LATEST_PYSCRIPT_VERSION ,
76
+ pyscript_version : Optional [ str ] = None ,
77
77
project_type : str = "app" ,
78
78
wrap : bool = False ,
79
79
command : Optional [str ] = None ,
@@ -86,7 +86,6 @@ def create_project(
86
86
main.py - a "Hello world" python starter module
87
87
index.html - start page for the project
88
88
"""
89
- date_stamp = datetime .date .today ()
90
89
91
90
if wrap :
92
91
if command :
@@ -107,13 +106,16 @@ def create_project(
107
106
# was complaining so let's add a default
108
107
app_name = app_or_file_name or "my-pyscript-app"
109
108
109
+ if not pyscript_version :
110
+ pyscript_version = _get_latest_pyscript_version ()
111
+
110
112
context = {
111
113
"name" : app_name ,
112
114
"description" : app_description ,
113
115
"type" : "app" ,
114
116
"author_name" : author_name ,
115
117
"author_email" : author_email ,
116
- "version" : f" { date_stamp . year } . { '{:02d}' . format ( date_stamp . month ) } .1 " ,
118
+ "version" : "v0 " ,
117
119
}
118
120
119
121
app_dir = Path ("." ) / app_name
@@ -155,3 +157,21 @@ def create_project(
155
157
pyscript_version = pyscript_version ,
156
158
template = template ,
157
159
)
160
+
161
+
162
+ def _get_latest_pyscript_version () -> str :
163
+ """Get the latest version of PyScript from GitHub."""
164
+ url = "https://api.github.com/repos/pyscript/pyscript/releases/latest"
165
+ try :
166
+ response = requests .get (url )
167
+
168
+ if not response .ok :
169
+ pyscript_version = LATEST_PYSCRIPT_VERSION
170
+ else :
171
+
172
+ data = response .json ()
173
+ pyscript_version = data ["tag_name" ]
174
+ except Exception :
175
+ pyscript_version = LATEST_PYSCRIPT_VERSION
176
+
177
+ return pyscript_version
0 commit comments