@@ -15,7 +15,7 @@ use uv_python::{
15
15
} ;
16
16
use uv_resolver:: RequiresPython ;
17
17
use uv_workspace:: pyproject_mut:: { DependencyTarget , PyProjectTomlMut } ;
18
- use uv_workspace:: { check_nested_workspaces , DiscoveryOptions , Workspace , WorkspaceError } ;
18
+ use uv_workspace:: { DiscoveryOptions , Workspace , WorkspaceError } ;
19
19
20
20
use crate :: commands:: project:: find_requires_python;
21
21
use crate :: commands:: reporters:: PythonDownloadReporter ;
@@ -69,24 +69,21 @@ pub(crate) async fn init(
69
69
}
70
70
} ;
71
71
72
- if r#virtual {
73
- init_virtual_workspace ( & path, no_workspace) ?;
74
- } else {
75
- init_project (
76
- & path,
77
- & name,
78
- no_readme,
79
- python,
80
- no_workspace,
81
- python_preference,
82
- python_downloads,
83
- connectivity,
84
- native_tls,
85
- cache,
86
- printer,
87
- )
88
- . await ?;
89
- }
72
+ init_project (
73
+ & path,
74
+ & name,
75
+ r#virtual,
76
+ no_readme,
77
+ python,
78
+ no_workspace,
79
+ python_preference,
80
+ python_downloads,
81
+ connectivity,
82
+ native_tls,
83
+ cache,
84
+ printer,
85
+ )
86
+ . await ?;
90
87
91
88
// Create the `README.md` if it does not already exist.
92
89
if !no_readme {
@@ -126,29 +123,12 @@ pub(crate) async fn init(
126
123
Ok ( ExitStatus :: Success )
127
124
}
128
125
129
- /// Initialize a virtual workspace at the given path.
130
- fn init_virtual_workspace ( path : & Path , no_workspace : bool ) -> Result < ( ) > {
131
- // Ensure that we aren't creating a nested workspace.
132
- if !no_workspace {
133
- check_nested_workspaces ( path, & DiscoveryOptions :: default ( ) ) ;
134
- }
135
-
136
- // Create the `pyproject.toml`.
137
- let pyproject = indoc:: indoc! { r"
138
- [tool.uv.workspace]
139
- members = []
140
- " } ;
141
-
142
- fs_err:: create_dir_all ( path) ?;
143
- fs_err:: write ( path. join ( "pyproject.toml" ) , pyproject) ?;
144
-
145
- Ok ( ( ) )
146
- }
147
-
148
126
/// Initialize a project (and, implicitly, a workspace root) at the given path.
127
+ #[ allow( clippy:: fn_params_excessive_bools) ]
149
128
async fn init_project (
150
129
path : & Path ,
151
130
name : & PackageName ,
131
+ r#virtual : bool ,
152
132
no_readme : bool ,
153
133
python : Option < String > ,
154
134
no_workspace : bool ,
@@ -265,38 +245,56 @@ async fn init_project(
265
245
RequiresPython :: greater_than_equal_version ( & interpreter. python_minor_version ( ) )
266
246
} ;
267
247
268
- // Create the `pyproject.toml`.
269
- let pyproject = indoc:: formatdoc! { r#"
270
- [project]
271
- name = "{name}"
272
- version = "0.1.0"
273
- description = "Add your description here"{readme}
274
- requires-python = "{requires_python}"
275
- dependencies = []
248
+ if r#virtual {
249
+ // Create the `pyproject.toml`, but omit `[build-system]`.
250
+ let pyproject = indoc:: formatdoc! { r#"
251
+ [project]
252
+ name = "{name}"
253
+ version = "0.1.0"
254
+ description = "Add your description here"{readme}
255
+ requires-python = "{requires_python}"
256
+ dependencies = []
257
+ "# ,
258
+ readme = if no_readme { "" } else { "\n readme = \" README.md\" " } ,
259
+ requires_python = requires_python. specifiers( ) ,
260
+ } ;
276
261
277
- [build-system]
278
- requires = ["hatchling"]
279
- build-backend = "hatchling.build"
280
- "# ,
281
- readme = if no_readme { "" } else { "\n readme = \" README.md\" " } ,
282
- requires_python = requires_python. specifiers( ) ,
283
- } ;
262
+ fs_err:: create_dir_all ( path) ?;
263
+ fs_err:: write ( path. join ( "pyproject.toml" ) , pyproject) ?;
264
+ } else {
265
+ // Create the `pyproject.toml`.
266
+ let pyproject = indoc:: formatdoc! { r#"
267
+ [project]
268
+ name = "{name}"
269
+ version = "0.1.0"
270
+ description = "Add your description here"{readme}
271
+ requires-python = "{requires_python}"
272
+ dependencies = []
273
+
274
+ [build-system]
275
+ requires = ["hatchling"]
276
+ build-backend = "hatchling.build"
277
+ "# ,
278
+ readme = if no_readme { "" } else { "\n readme = \" README.md\" " } ,
279
+ requires_python = requires_python. specifiers( ) ,
280
+ } ;
284
281
285
- fs_err:: create_dir_all ( path) ?;
286
- fs_err:: write ( path. join ( "pyproject.toml" ) , pyproject) ?;
282
+ fs_err:: create_dir_all ( path) ?;
283
+ fs_err:: write ( path. join ( "pyproject.toml" ) , pyproject) ?;
287
284
288
- // Create `src/{name}/__init__.py`, if it doesn't exist already.
289
- let src_dir = path. join ( "src" ) . join ( & * name. as_dist_info_name ( ) ) ;
290
- let init_py = src_dir. join ( "__init__.py" ) ;
291
- if !init_py. try_exists ( ) ? {
292
- fs_err:: create_dir_all ( & src_dir) ?;
293
- fs_err:: write (
294
- init_py,
295
- indoc:: formatdoc! { r#"
285
+ // Create `src/{name}/__init__.py`, if it doesn't exist already.
286
+ let src_dir = path. join ( "src" ) . join ( & * name. as_dist_info_name ( ) ) ;
287
+ let init_py = src_dir. join ( "__init__.py" ) ;
288
+ if !init_py. try_exists ( ) ? {
289
+ fs_err:: create_dir_all ( & src_dir) ?;
290
+ fs_err:: write (
291
+ init_py,
292
+ indoc:: formatdoc! { r#"
296
293
def hello() -> str:
297
294
return "Hello from {name}!"
298
295
"# } ,
299
- ) ?;
296
+ ) ?;
297
+ }
300
298
}
301
299
302
300
if let Some ( workspace) = workspace {
0 commit comments