@@ -17,6 +17,7 @@ use crate::package_version::{
1717use crate :: project_info:: { ProjectInfo , ProjectManager } ;
1818use crate :: python_files:: generate_python_files;
1919use crate :: rust_files:: { save_cargo_toml_file, save_lib_file} ;
20+ use crate :: utils:: is_python_312_or_greater;
2021
2122fn create_directories ( project_info : & ProjectInfo ) -> Result < ( ) > {
2223 let module = project_info. source_dir . replace ( [ ' ' , '-' ] , "_" ) ;
@@ -268,7 +269,8 @@ fn save_pre_commit_file(project_info: &ProjectInfo) -> Result<()> {
268269fn build_latest_dev_dependencies (
269270 download_latest_packages : bool ,
270271 project_manager : & ProjectManager ,
271- ) -> String {
272+ min_python_version : & str ,
273+ ) -> Result < String > {
272274 let mut version_string = String :: new ( ) ;
273275 let mut packages = vec ! [
274276 PythonPackageVersion :: new( PythonPackage :: MyPy ) ,
@@ -278,11 +280,17 @@ fn build_latest_dev_dependencies(
278280 PythonPackageVersion :: new( PythonPackage :: Ruff ) ,
279281 ] ;
280282
281- match project_manager {
282- ProjectManager :: Maturin => packages. push ( PythonPackageVersion :: new ( PythonPackage :: Maturin ) ) ,
283- ProjectManager :: Poetry => packages. push ( PythonPackageVersion :: new ( PythonPackage :: Tomli ) ) ,
284- ProjectManager :: Setuptools => ( ) ,
285- } ;
283+ if !is_python_312_or_greater ( min_python_version) ? {
284+ match project_manager {
285+ ProjectManager :: Maturin => {
286+ packages. push ( PythonPackageVersion :: new ( PythonPackage :: Maturin ) )
287+ }
288+ ProjectManager :: Poetry => {
289+ packages. push ( PythonPackageVersion :: new ( PythonPackage :: Tomli ) )
290+ }
291+ ProjectManager :: Setuptools => ( ) ,
292+ } ;
293+ }
286294
287295 if download_latest_packages {
288296 packages. par_iter_mut ( ) . for_each ( |package| {
@@ -313,14 +321,14 @@ fn build_latest_dev_dependencies(
313321 }
314322
315323 if let ProjectManager :: Poetry = project_manager {
316- version_string. trim ( ) . to_string ( )
324+ Ok ( version_string. trim ( ) . to_string ( ) )
317325 } else {
318326 version_string. push_str ( "-e .\n " ) ;
319- version_string
327+ Ok ( version_string)
320328 }
321329}
322330
323- fn create_pyproject_toml ( project_info : & ProjectInfo ) -> String {
331+ fn create_pyproject_toml ( project_info : & ProjectInfo ) -> Result < String > {
324332 let module = project_info. source_dir . replace ( [ ' ' , '-' ] , "_" ) ;
325333 let pyupgrade_version = & project_info. min_python_version . replace ( [ '.' , '^' ] , "" ) ;
326334 let license_text = license_str ( & project_info. license ) ;
@@ -442,7 +450,7 @@ ignore=[
442450"# ,
443451 ) ;
444452
445- render ! (
453+ Ok ( render ! (
446454 & pyproject,
447455 project_name => module. replace( '_' , "-" ) ,
448456 version => project_info. version,
@@ -451,17 +459,17 @@ ignore=[
451459 creator_email => project_info. creator_email,
452460 license => license_text,
453461 min_python_version => project_info. min_python_version,
454- dev_dependencies => build_latest_dev_dependencies( project_info. download_latest_packages, & project_info. project_manager) ,
462+ dev_dependencies => build_latest_dev_dependencies( project_info. download_latest_packages, & project_info. project_manager, & project_info . min_python_version ) ? ,
455463 max_line_length => project_info. max_line_length,
456464 module => module,
457465 is_application => project_info. is_application,
458466 pyupgrade_version => pyupgrade_version,
459- )
467+ ) )
460468}
461469
462470fn save_pyproject_toml_file ( project_info : & ProjectInfo ) -> Result < ( ) > {
463471 let file_path = project_info. base_dir ( ) . join ( "pyproject.toml" ) ;
464- let content = create_pyproject_toml ( project_info) ;
472+ let content = create_pyproject_toml ( project_info) ? ;
465473
466474 save_file_with_content ( & file_path, & content) ?;
467475
@@ -473,7 +481,8 @@ fn save_dev_requirements(project_info: &ProjectInfo) -> Result<()> {
473481 let content = build_latest_dev_dependencies (
474482 project_info. download_latest_packages ,
475483 & project_info. project_manager ,
476- ) ;
484+ & project_info. min_python_version ,
485+ ) ?;
477486
478487 save_file_with_content ( & file_path, & content) ?;
479488
0 commit comments