@@ -524,7 +524,6 @@ async fn init_project(
524
524
name,
525
525
path,
526
526
& requires_python,
527
- python_request. as_ref ( ) ,
528
527
vcs,
529
528
build_backend,
530
529
author_from,
@@ -571,6 +570,40 @@ async fn init_project(
571
570
workspace. install_path( ) . simplified_display( ) . cyan( )
572
571
) ?;
573
572
}
573
+ // Write .python-version if it doesn't exist in the workspace or if the version differs
574
+ if let Some ( python_request) = python_request {
575
+ if PythonVersionFile :: discover ( path, & VersionFileDiscoveryOptions :: default ( ) )
576
+ . await ?
577
+ . filter ( |file| {
578
+ file. version ( )
579
+ . is_some_and ( |version| * version == python_request)
580
+ && file. path ( ) . parent ( ) . is_some_and ( |parent| {
581
+ parent == workspace. install_path ( ) || parent == path
582
+ } )
583
+ } )
584
+ . is_none ( )
585
+ {
586
+ PythonVersionFile :: new ( path. join ( ".python-version" ) )
587
+ . with_versions ( vec ! [ python_request. clone( ) ] )
588
+ . write ( )
589
+ . await ?;
590
+ }
591
+ }
592
+ } else {
593
+ // Write .python-version if it doesn't exist in the project directory.
594
+ if let Some ( python_request) = python_request {
595
+ if PythonVersionFile :: discover ( path, & VersionFileDiscoveryOptions :: default ( ) )
596
+ . await ?
597
+ . filter ( |file| file. version ( ) . is_some ( ) )
598
+ . filter ( |file| file. path ( ) . parent ( ) . is_some_and ( |parent| parent == path) )
599
+ . is_none ( )
600
+ {
601
+ PythonVersionFile :: new ( path. join ( ".python-version" ) )
602
+ . with_versions ( vec ! [ python_request. clone( ) ] )
603
+ . write ( )
604
+ . await ?;
605
+ }
606
+ }
574
607
}
575
608
576
609
Ok ( ( ) )
@@ -615,7 +648,6 @@ impl InitProjectKind {
615
648
name : & PackageName ,
616
649
path : & Path ,
617
650
requires_python : & RequiresPython ,
618
- python_request : Option < & PythonRequest > ,
619
651
vcs : Option < VersionControlSystem > ,
620
652
build_backend : Option < ProjectBuildBackend > ,
621
653
author_from : Option < AuthorFrom > ,
@@ -628,7 +660,6 @@ impl InitProjectKind {
628
660
name,
629
661
path,
630
662
requires_python,
631
- python_request,
632
663
vcs,
633
664
build_backend,
634
665
author_from,
@@ -642,7 +673,6 @@ impl InitProjectKind {
642
673
name,
643
674
path,
644
675
requires_python,
645
- python_request,
646
676
vcs,
647
677
build_backend,
648
678
author_from,
@@ -660,7 +690,6 @@ impl InitProjectKind {
660
690
name : & PackageName ,
661
691
path : & Path ,
662
692
requires_python : & RequiresPython ,
663
- python_request : Option < & PythonRequest > ,
664
693
vcs : Option < VersionControlSystem > ,
665
694
build_backend : Option < ProjectBuildBackend > ,
666
695
author_from : Option < AuthorFrom > ,
@@ -716,21 +745,6 @@ impl InitProjectKind {
716
745
}
717
746
fs_err:: write ( path. join ( "pyproject.toml" ) , pyproject) ?;
718
747
719
- // Write .python-version if it doesn't exist in the target or is empty.
720
- if let Some ( python_request) = python_request {
721
- if PythonVersionFile :: discover ( path, & VersionFileDiscoveryOptions :: default ( ) )
722
- . await ?
723
- . filter ( |file| file. version ( ) . is_some ( ) )
724
- . filter ( |file| file. path ( ) . parent ( ) . is_some_and ( |parent| parent == path) )
725
- . is_none ( )
726
- {
727
- PythonVersionFile :: new ( path. join ( ".python-version" ) )
728
- . with_versions ( vec ! [ python_request. clone( ) ] )
729
- . write ( )
730
- . await ?;
731
- }
732
- }
733
-
734
748
// Initialize the version control system.
735
749
init_vcs ( path, vcs) ?;
736
750
@@ -743,7 +757,6 @@ impl InitProjectKind {
743
757
name : & PackageName ,
744
758
path : & Path ,
745
759
requires_python : & RequiresPython ,
746
- python_request : Option < & PythonRequest > ,
747
760
vcs : Option < VersionControlSystem > ,
748
761
build_backend : Option < ProjectBuildBackend > ,
749
762
author_from : Option < AuthorFrom > ,
@@ -772,19 +785,6 @@ impl InitProjectKind {
772
785
// Generate `src` files
773
786
generate_package_scripts ( name, path, build_backend, true ) ?;
774
787
775
- // Write .python-version if it doesn't exist.
776
- if let Some ( python_request) = python_request {
777
- if PythonVersionFile :: discover ( path, & VersionFileDiscoveryOptions :: default ( ) )
778
- . await ?
779
- . is_none ( )
780
- {
781
- PythonVersionFile :: new ( path. join ( ".python-version" ) )
782
- . with_versions ( vec ! [ python_request. clone( ) ] )
783
- . write ( )
784
- . await ?;
785
- }
786
- }
787
-
788
788
// Initialize the version control system.
789
789
init_vcs ( path, vcs) ?;
790
790
0 commit comments