Add --app and --lib options to uv init (#6689)

Changes the `uv init` experience with a focus on working for more
use-cases out of the box.

- Adds `--app` and `--lib` options to control the created project style
- Changes the default from a library with `src/` and a build backend
(`--lib`) to an application that is not packaged (`--app`)
- Hides the `--virtual` option and replaces it with `--package` and
`--no-package`
- `--no-package` is not allowed with `--lib` right now, but it could be
in the future once we understand a use-case
- Creates a runnable project
- Applications have a `hello.py` file which you can run with `uv run
hello.py`
- Packaged applications, e.g., `uv init --app --package` create a
package and script entrypoint, which you can run with `uv run hello`
- Libraries provide a demo API function, e.g., `uv run python -c "import
name; print(name.hello())"` — this is unchanged

Closes #6471
This commit is contained in:
Zanie Blue 2024-08-27 13:08:09 -05:00 committed by GitHub
parent 8d466db080
commit bc5b069a61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 726 additions and 120 deletions

View file

@ -2101,13 +2101,47 @@ pub struct InitArgs {
/// Create a virtual project, rather than a package.
///
/// A virtual project is a project that is not intended to be built as a Python package,
/// such as a project that only contains scripts or other application code.
///
/// Virtual projects themselves are not installed into the Python environment.
#[arg(long)]
/// This option is deprecated and will be removed in a future release.
#[arg(long, hide = true, conflicts_with = "package")]
pub r#virtual: bool,
/// Set up the project to be built as a Python package.
///
/// Defines a `[build-system]` for the project.
///
/// This is the default behavior when using `--lib`.
///
/// When using `--app`, this will include a `[project.scripts]` entrypoint and use a `src/`
/// project structure.
#[arg(long, overrides_with = "no_package")]
pub r#package: bool,
/// Do not set up the project to be built as a Python package.
///
/// Does not include a `[build-system]` for the project.
///
/// This is the default behavior when using `--app`.
#[arg(long, overrides_with = "package", conflicts_with = "lib")]
pub r#no_package: bool,
/// Create a project for an application.
///
/// This is the default behavior if `--lib` is not requested.
///
/// This project kind is for web servers, scripts, and command-line interfaces.
///
/// By default, an application is not intended to be built and distributed as a Python package.
/// The `--package` option can be used to create an application that is distributable, e.g., if
/// you want to distribute a command-line interface via PyPI.
#[arg(long, alias = "application", conflicts_with = "lib")]
pub r#app: bool,
/// Create a project for a library.
///
/// A library is a project that is intended to be built and distributed as a Python package.
#[arg(long, alias = "library", conflicts_with = "app")]
pub r#lib: bool,
/// Do not create a `README.md` file.
#[arg(long)]
pub no_readme: bool,