@@ -125,13 +125,6 @@ def _python_identifier(name: str) -> str:
125125 return sanitized
126126
127127
128- def title () -> None :
129- header = Text ()
130- header .append ("Python Project Generator" , style = "bold magenta" )
131- console .print (header )
132- console .print (Text ("═" * 48 , style = "magenta" ))
133-
134-
135128python_version_choices = [
136129 ("3.8" , "Python 3.8" ),
137130 ("3.9" , "Python 3.9" ),
@@ -192,6 +185,29 @@ def questions(env: Environment, destination: Path) -> list[Question]:
192185
193186 suggested_package = _python_identifier (destination .name )
194187
188+ def version_tuple (value : str | None ) -> tuple [int , int ] | None :
189+ if not value :
190+ return None
191+ major , minor = value .split ("." )
192+ return int (major ), int (minor )
193+
194+ def filtered_version_choices (
195+ * ,
196+ min_version : str | None = None ,
197+ max_version : str | None = None ,
198+ ) -> list [tuple [str , str ]]:
199+ min_tuple = version_tuple (min_version )
200+ max_tuple = version_tuple (max_version )
201+ choices : list [tuple [str , str ]] = []
202+ for value , label in python_version_choices :
203+ current_tuple = version_tuple (value )
204+ if min_tuple and current_tuple and current_tuple < min_tuple :
205+ continue
206+ if max_tuple and current_tuple and current_tuple > max_tuple :
207+ continue
208+ choices .append ((value , label ))
209+ return choices
210+
195211 def default_package_name (answers : dict [str , Any ]) -> str :
196212 return suggested_package
197213
@@ -205,6 +221,45 @@ def default_repository_url(answers: dict[str, Any]) -> str:
205221 username = env .globals .get ("github_username" ) or "my-user"
206222 return f"https://github.com/{ username } /{ repo } "
207223
224+ def python_max_version_choices (answers : dict [str , Any ]) -> list [tuple [str , str ]]:
225+ min_version = answers .get ("python_min_version" )
226+ return filtered_version_choices (min_version = min_version )
227+
228+ def default_python_max_version (answers : dict [str , Any ]) -> str :
229+ choices = python_max_version_choices (answers )
230+ preferred = "3.13"
231+ available_values = [value for value , _ in choices ]
232+ if preferred in available_values :
233+ return preferred
234+ if available_values :
235+ return available_values [- 1 ]
236+ return preferred
237+
238+ def python_default_version_choices (
239+ answers : dict [str , Any ],
240+ ) -> list [tuple [str , str ]]:
241+ min_version = answers .get ("python_min_version" )
242+ max_version = answers .get ("python_max_version" )
243+ return filtered_version_choices (
244+ min_version = min_version , max_version = max_version
245+ )
246+
247+ def default_python_default_version (answers : dict [str , Any ]) -> str :
248+ choices = python_default_version_choices (answers )
249+ preferred = "3.12"
250+ available_values = [value for value , _ in choices ]
251+ if preferred in available_values :
252+ return preferred
253+ for key in (
254+ answers .get ("python_max_version" ),
255+ answers .get ("python_min_version" ),
256+ ):
257+ if key in available_values :
258+ return str (key )
259+ if available_values :
260+ return available_values [- 1 ]
261+ return preferred
262+
208263 return [
209264 Question (
210265 key = "package_name" ,
@@ -233,6 +288,8 @@ def default_repository_url(answers: dict[str, Any]) -> str:
233288 Question (
234289 key = "description" ,
235290 prompt = "Project description" ,
291+ default = " " ,
292+ parser = lambda value , answers : value .strip (),
236293 ),
237294 Question (
238295 key = "repository_url" ,
@@ -249,15 +306,15 @@ def default_repository_url(answers: dict[str, Any]) -> str:
249306 Question (
250307 key = "python_max_version" ,
251308 prompt = "Maximum supported Python version" ,
252- choices = python_version_choices ,
253- default = "3.13" ,
309+ choices = python_max_version_choices ,
310+ default = default_python_max_version ,
254311 validators = [validate_versions ],
255312 ),
256313 Question (
257314 key = "python_default_version" ,
258315 prompt = "Default development Python version" ,
259- choices = python_version_choices ,
260- default = "3.12" ,
316+ choices = python_default_version_choices ,
317+ default = default_python_default_version ,
261318 validators = [validate_versions ],
262319 ),
263320 Question (
0 commit comments