1- import datetime
21import json
32from pathlib import Path
43from typing import Optional
54
65import jinja2
6+ import requests
77import toml
88
99from pyscript import LATEST_PYSCRIPT_VERSION , config
@@ -19,7 +19,7 @@ def create_project_html(
1919 python_file_path : str ,
2020 config_file_path : str ,
2121 output_file_path : Path ,
22- pyscript_version : str = LATEST_PYSCRIPT_VERSION ,
22+ pyscript_version : str ,
2323 template : str = "basic.html" ,
2424) -> None :
2525 """Write a Python script string to an HTML file template.
@@ -54,9 +54,9 @@ def save_config_file(config_file: Path, configuration: dict):
5454
5555 Params:
5656
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
6060
6161 Return:
6262 (None)
@@ -73,7 +73,7 @@ def create_project(
7373 app_description : str ,
7474 author_name : str ,
7575 author_email : str ,
76- pyscript_version : str = LATEST_PYSCRIPT_VERSION ,
76+ pyscript_version : Optional [ str ] = None ,
7777 project_type : str = "app" ,
7878 wrap : bool = False ,
7979 command : Optional [str ] = None ,
@@ -86,7 +86,6 @@ def create_project(
8686 main.py - a "Hello world" python starter module
8787 index.html - start page for the project
8888 """
89- date_stamp = datetime .date .today ()
9089
9190 if wrap :
9291 if command :
@@ -107,13 +106,16 @@ def create_project(
107106 # was complaining so let's add a default
108107 app_name = app_or_file_name or "my-pyscript-app"
109108
109+ if not pyscript_version :
110+ pyscript_version = _get_latest_pyscript_version ()
111+
110112 context = {
111113 "name" : app_name ,
112114 "description" : app_description ,
113115 "type" : "app" ,
114116 "author_name" : author_name ,
115117 "author_email" : author_email ,
116- "version" : f" { date_stamp . year } . { '{:02d}' . format ( date_stamp . month ) } .1 " ,
118+ "version" : "v0 " ,
117119 }
118120
119121 app_dir = Path ("." ) / app_name
@@ -155,3 +157,21 @@ def create_project(
155157 pyscript_version = pyscript_version ,
156158 template = template ,
157159 )
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