@@ -109,7 +109,7 @@ fn init_bare() {
109109 } ) ;
110110}
111111
112- /// Run `uv init --app` to create an application project
112+ /// Run `uv init --app` to create a packaged application project
113113#[ test]
114114fn init_application ( ) -> Result < ( ) > {
115115 let context = uv_test:: test_context!( "3.12" ) ;
@@ -118,7 +118,7 @@ fn init_application() -> Result<()> {
118118 child. create_dir_all ( ) ?;
119119
120120 let pyproject_toml = child. join ( "pyproject.toml" ) ;
121- let main_py = child. join ( "main .py" ) ;
121+ let init_py = child. join ( "src" ) . join ( "foo" ) . join ( "__init__ .py") ;
122122
123123 uv_snapshot ! ( context. filters( ) , context. init( ) . current_dir( & child) . arg( "--app" ) , @"
124124 exit_code: 0 (success)
@@ -139,27 +139,30 @@ fn init_application() -> Result<()> {
139139 readme = "README.md"
140140 requires-python = ">=3.12"
141141 dependencies = []
142+
143+ [project.scripts]
144+ foo = "foo:main"
145+
146+ [build-system]
147+ requires = ["uv_build>=[CURRENT_VERSION],<[NEXT_BREAKING]"]
148+ build-backend = "uv_build"
142149 "#
143150 ) ;
144151 } ) ;
145152
146- let hello = fs_err:: read_to_string ( main_py ) ?;
153+ let init = fs_err:: read_to_string ( init_py ) ?;
147154 insta:: with_settings!( {
148155 filters => context. filters( ) ,
149156 } , {
150157 assert_snapshot!(
151- hello , @r#"
152- def main():
158+ init , @r#"
159+ def main() -> None :
153160 print("Hello from foo!")
154-
155-
156- if __name__ == "__main__":
157- main()
158161 "#
159162 ) ;
160163 } ) ;
161164
162- uv_snapshot ! ( context. filters( ) , context. run( ) . current_dir( & child) . arg( "main.py " ) , @"
165+ uv_snapshot ! ( context. filters( ) , context. run( ) . current_dir( & child) . arg( "foo " ) , @"
163166 exit_code: 0 (success)
164167 ----- stdout -----
165168 Hello from foo!
@@ -169,15 +172,17 @@ fn init_application() -> Result<()> {
169172 Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
170173 Creating virtual environment at: .venv
171174 Resolved 1 package in [TIME]
172- Checked in [TIME]
175+ Prepared 1 package in [TIME]
176+ Installed 1 package in [TIME]
177+ + foo==0.1.0 (from file://[TEMP_DIR]/foo)
173178 " ) ;
174179
175180 Ok ( ( ) )
176181}
177182
178- /// When `main.py` already exists, we don't create it again
183+ /// When `main.py` already exists in an unpackaged application , we don't create it again
179184#[ test]
180- fn init_application_hello_exists ( ) -> Result < ( ) > {
185+ fn init_application_no_package_main_exists ( ) -> Result < ( ) > {
181186 let context = uv_test:: test_context!( "3.12" ) ;
182187
183188 let child = context. temp_dir . child ( "foo" ) ;
@@ -187,7 +192,7 @@ fn init_application_hello_exists() -> Result<()> {
187192 let main_py = child. child ( "main.py" ) ;
188193 main_py. touch ( ) ?;
189194
190- uv_snapshot ! ( context. filters( ) , context. init( ) . current_dir( & child) . arg( "--app" ) , @"
195+ uv_snapshot ! ( context. filters( ) , context. init( ) . current_dir( & child) . arg( "--app" ) . arg ( "--no-package" ) , @"
191196 exit_code: 0 (success)
192197 ----- stderr -----
193198 Initialized project `foo`
@@ -222,9 +227,9 @@ fn init_application_hello_exists() -> Result<()> {
222227 Ok ( ( ) )
223228}
224229
225- /// When other Python files already exists , we still create `main.py`
230+ /// When other Python files already exist in an unpackaged application , we still create `main.py`
226231#[ test]
227- fn init_application_other_python_exists ( ) -> Result < ( ) > {
232+ fn init_application_no_package_other_python_exists ( ) -> Result < ( ) > {
228233 let context = uv_test:: test_context!( "3.12" ) ;
229234
230235 let child = context. temp_dir . child ( "foo" ) ;
@@ -235,7 +240,7 @@ fn init_application_other_python_exists() -> Result<()> {
235240 let other_py = child. child ( "foo.py" ) ;
236241 other_py. touch ( ) ?;
237242
238- uv_snapshot ! ( context. filters( ) , context. init( ) . current_dir( & child) . arg( "--app" ) , @"
243+ uv_snapshot ! ( context. filters( ) , context. init( ) . current_dir( & child) . arg( "--app" ) . arg ( "--no-package" ) , @"
239244 exit_code: 0 (success)
240245 ----- stderr -----
241246 Initialized project `foo`
@@ -1232,7 +1237,7 @@ fn init_application_current_dir() -> Result<()> {
12321237 " ) ;
12331238
12341239 let pyproject = fs_err:: read_to_string ( dir. join ( "pyproject.toml" ) ) ?;
1235- let main_py = fs_err:: read_to_string ( dir. join ( "main .py" ) ) ?;
1240+ let init_py = fs_err:: read_to_string ( dir. join ( "src/foo/__init__ .py" ) ) ?;
12361241
12371242 insta:: with_settings!( {
12381243 filters => context. filters( ) ,
@@ -1246,6 +1251,13 @@ fn init_application_current_dir() -> Result<()> {
12461251 readme = "README.md"
12471252 requires-python = ">=3.12"
12481253 dependencies = []
1254+
1255+ [project.scripts]
1256+ foo = "foo:main"
1257+
1258+ [build-system]
1259+ requires = ["uv_build>=[CURRENT_VERSION],<[NEXT_BREAKING]"]
1260+ build-backend = "uv_build"
12491261 "#
12501262 ) ;
12511263 } ) ;
@@ -1254,13 +1266,9 @@ fn init_application_current_dir() -> Result<()> {
12541266 filters => context. filters( ) ,
12551267 } , {
12561268 assert_snapshot!(
1257- main_py , @r#"
1258- def main():
1269+ init_py , @r#"
1270+ def main() -> None :
12591271 print("Hello from foo!")
1260-
1261-
1262- if __name__ == "__main__":
1263- main()
12641272 "#
12651273 ) ;
12661274 } ) ;
@@ -1734,6 +1742,7 @@ fn init_normalized_names() -> Result<()> {
17341742
17351743 let child = context. temp_dir . child ( "bar_baz" ) ;
17361744 let pyproject = fs_err:: read_to_string ( child. join ( "pyproject.toml" ) ) ?;
1745+ let _ = fs_err:: read_to_string ( child. join ( "src/bar_baz/__init__.py" ) ) ?;
17371746
17381747 insta:: with_settings!( {
17391748 filters => context. filters( ) ,
@@ -1747,6 +1756,13 @@ fn init_normalized_names() -> Result<()> {
17471756 readme = "README.md"
17481757 requires-python = ">=3.12"
17491758 dependencies = []
1759+
1760+ [project.scripts]
1761+ bar-baz = "bar_baz:main"
1762+
1763+ [build-system]
1764+ requires = ["uv_build>=[CURRENT_VERSION],<[NEXT_BREAKING]"]
1765+ build-backend = "uv_build"
17501766 "#
17511767 ) ;
17521768 } ) ;
0 commit comments