Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged

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

merged 1 commit into from
Aug 27, 2024

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Aug 27, 2024

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

@zanieb zanieb added the cli Related to the command line interface label Aug 27, 2024
@zanieb zanieb changed the base branch from main to charlie/virtual August 27, 2024 14:05
@zanieb zanieb changed the base branch from charlie/virtual to charlie/virtuals August 27, 2024 14:05
@zanieb zanieb changed the title zb/init app lib Add --app and --lib options to uv init* Aug 27, 2024
@zanieb zanieb changed the title Add --app and --lib options to uv init* Add --app and --lib options to uv init Aug 27, 2024
@zanieb zanieb force-pushed the zb/init-app-lib branch 4 times, most recently from 1aec5d5 to 43ee4a0 Compare August 27, 2024 15:42
@zanieb
Copy link
Member Author

zanieb commented Aug 27, 2024

Instead of hello.py I explored app/__main__.py and uv run python -m app. I'm not sure what's better, but we might want to go with the simplest possible option? Thoughts? Seems nice to have some namespacing? Maybe we can do something different depending on if the directory is empty or not?

@zanieb zanieb force-pushed the zb/init-app-lib branch 3 times, most recently from 6e356b3 to fe1a11f Compare August 27, 2024 17:21
@zanieb zanieb marked this pull request as ready for review August 27, 2024 17:37
Base automatically changed from charlie/virtuals to main August 27, 2024 17:42
Changes the default from a library with `src/` to an application that is not packaged
@zanieb zanieb enabled auto-merge (squash) August 27, 2024 18:02
@zanieb zanieb merged commit bc5b069 into main Aug 27, 2024
56 checks passed
@zanieb zanieb deleted the zb/init-app-lib branch August 27, 2024 18:08
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 30, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | minor | `0.3.5` -> `0.4.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.4.0`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#040)

[Compare Source](astral-sh/uv@0.3.5...0.4.0)

This release adds first-class support for Python projects that are not designed as Python packages (e.g., web applications, data science projects, etc.).

In doing so, it includes some breaking changes around uv's handling of projects. Previously, uv required that all projects could be built into distributable Python packages, and installed them into the virtual environment. Projects created by `uv init` always included a `[build-system]` definition and existing projects that did not define a `[build-system]` would use the legacy setuptools build backend by default.

Most users are not developing libraries that need to be packaged and published to PyPI. Instead, they're building applications using web frameworks, or running collections of Python scripts in the project's root directory. In these cases, requiring a `[build-system]` was confusing and error-prone. In this release, uv changes the default behavior to orient around these common use cases.

In summary, the major changes are:

-   uv no longer attempts to package and install projects that do not define a `[build-system]`.
    -   While the project itself will not be installed into the virtual environment, its dependencies will still be included.
    -   The previous behavior can be recovered by setting `package = true` in the `[tool.uv]` section of your `pyproject.toml`.
-   `uv init` no longer creates a `src/` directory or defines a `[build-system]` by default.
    -   The previous behavior can be recovered with `uv init --lib` or `uv init --app --package`.
-   uv allows and recommends including `[project]` definitions in virtual workspace roots.
    -   Previously, the uv required the `[project]` section to be omitted.
-   uv allows disabling packaging of projects, even if they define a `[build-system]`, by setting `package = false` in the `[tool.uv]` section of your `pyproject.toml`.

See the latest documentation on [build systems in projects](http://docs.astral.sh/uv/concepts/projects/#build-systems) for more details.

##### Enhancements

-   Add first-class support for non-packaged projects ([#&#8203;6585](astral-sh/uv#6585))
-   Add `--app` and `--lib` options to `uv init` ([#&#8203;6689](astral-sh/uv#6689))
-   Use `virtual` source label in lockfile for non-packaged dependencies ([#&#8203;6728](astral-sh/uv#6728))
-   Read hash from URL fragment if `--hashes` are omitted  ([#&#8203;6731](astral-sh/uv#6731))
-   Support `{package}@&#8203;{version}` in `uv tool install` ([#&#8203;6762](astral-sh/uv#6762))
-   Publish additional Docker tags without patch version ([#&#8203;6734](astral-sh/uv#6734))

##### Bug fixes

-   Accept either strings or structs for hosts ([#&#8203;6763](astral-sh/uv#6763))
-   Avoid including non-excluded members in parent workspaces ([#&#8203;6735](astral-sh/uv#6735))
-   Avoid reading stale `.egg-info` from mutable sources ([#&#8203;6714](astral-sh/uv#6714))
-   Avoid writing invalid PEP 723 scripts on `tool.uv.sources` ([#&#8203;6706](astral-sh/uv#6706))
-   Compare virtual members when invalidating lockfile ([#&#8203;6754](astral-sh/uv#6754))
-   Do not require workspace members to sync with `--frozen` ([#&#8203;6737](astral-sh/uv#6737))
-   Implement deserialization for trusted host ([#&#8203;6716](astral-sh/uv#6716))
-   Avoid showing duplicate paths in `uv python list` ([#&#8203;6740](astral-sh/uv#6740))
-   Raise an error for unclosed script tags in PEP 723 scripts ([#&#8203;6704](astral-sh/uv#6704))

##### Documentation

-   Add dependabot and renovate documentation page ([#&#8203;6236](astral-sh/uv#6236))
-   Bind to the host to allow connections in FastAPI Docker example ([#&#8203;6753](astral-sh/uv#6753))
-   Fix some broken links ([#&#8203;6705](astral-sh/uv#6705))
-   Update FastAPI guide for virtual projects and use `uv init` to create the `pyproject.toml` ([#&#8203;6752](astral-sh/uv#6752))
-   Update project documentation for the application / library concepts ([#&#8203;6718](astral-sh/uv#6718))
-   Update workspace documentation to remove legacy virtual projects ([#&#8203;6720](astral-sh/uv#6720))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants