Add --bare option to uv init (#11192)

People are looking for a less opinionated version of `uv init`. The goal
here is to create a `pyproject.toml` and nothing else. With the `--lib`
or `--package` flags, we'll still configure a build backend but we won't
create the source tree. This disables things like the default
`description`, author behavior, and VCS.

See

- https://github.com/astral-sh/uv/issues/8178
- https://github.com/astral-sh/uv/issues/7181
- https://github.com/astral-sh/uv/issues/6750
This commit is contained in:
Zanie Blue
2025-02-05 10:12:27 -06:00
committed by GitHub
parent 989b103171
commit acbbb2b82a
7 changed files with 311 additions and 13 deletions

View File

@@ -295,3 +295,39 @@ Hello from example-ext!
Changes to the extension code in `lib.rs` or `main.cpp` will require running `--reinstall` to
rebuild them.
## Creating a minimal project
If you only want to create a `pyproject.toml`, use the `--bare` option:
```console
$ uv init example --bare
```
uv will skip creating a Python version pin file, a README, and any source directories or files.
Additionally, uv will not initialize a version control system (i.e., `git`).
```console
$ tree example-bare
example-bare
└── pyproject.toml
```
uv will also not add extra metadata to the `pyproject.toml`, such as the `description` or `authors`.
```toml
[project]
name = "example"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = []
```
The `--bare` option can be used with other options like `--lib` or `--build-backend` — in these
cases uv will still configure a build system but will not create the expected file structure.
When `--bare` is used, additional features can still be used opt-in:
```console
$ uv init example --description "Hello world" --author-from git --vcs git
```

View File

@@ -555,6 +555,10 @@ uv init [OPTIONS] [PATH]
<li><code>none</code>: Do not infer the author information</li>
</ul>
</dd><dt><code>--bare</code></dt><dd><p>Only create a <code>pyproject.toml</code>.</p>
<p>Disables creating extra files like <code>README.md</code>, the <code>src/</code> tree, <code>.python-version</code> files, etc.</p>
</dd><dt><code>--build-backend</code> <i>build-backend</i></dt><dd><p>Initialize a build-backend of choice for the project.</p>
<p>Implicitly sets <code>--package</code>.</p>
@@ -632,6 +636,8 @@ uv init [OPTIONS] [PATH]
<p>Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.</p>
<p>May also be set with the <code>UV_NO_CONFIG</code> environment variable.</p>
</dd><dt><code>--no-description</code></dt><dd><p>Disable the description for the project</p>
</dd><dt><code>--no-package</code></dt><dd><p>Do not set up the project to be built as a Python package.</p>
<p>Does not include a <code>[build-system]</code> for the project.</p>