Skip to content
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

Create main.py instead of hello.py in uv init #10369

Merged
merged 2 commits into from
Feb 13, 2025
Merged

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Jan 7, 2025

Initially it seemed like app.py might be slightly more desirable but people seem to overwhelmingly favour main.py as a good "generic" name.

Fixes #7782

@Gankra
Copy link
Contributor Author

Gankra commented Jan 7, 2025

The only concern I have with this is it changes intro docs, so there will be an awkward period where people have older versions of uv that make hello.py but the guide says they make app.py. Dunno if we want to make the docs hedge for a bit or what.

@zanieb
Copy link
Member

zanieb commented Jan 7, 2025

The only concern I have with this is it changes intro docs, so there will be an awkward period where people have older versions of uv that make hello.py but the guide says they make app.py. Dunno if we want to make the docs hedge for a bit or what.

I'd just go for it — you could add an admonition about older versions if you want though.

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Jan 7, 2025
@zanieb
Copy link
Member

zanieb commented Jan 7, 2025

Arguably this is sort of breaking, though I'm not sure we consider uv init to be a typical programmatic interface. @charliermarsh thoughts?

If we decide it's breaking, we'll just hold it until 0.6.0 (for which there is a milestone to track other breaking changes).

@Gankra Gankra changed the title rename hello.py to app.py Create app.py instead of hello.py in uv init Jan 7, 2025
@charliermarsh
Copy link
Member

It probably makes sense to defer this to v0.6. We could do a v0.6 in the near future though.

@zanieb zanieb added this to the v0.6.0 milestone Jan 7, 2025
@zanieb zanieb added the breaking A breaking change label Jan 7, 2025
@zanieb
Copy link
Member

zanieb commented Jan 7, 2025

Sorry for giving you an unmergable task!

@Bengt
Copy link

Bengt commented Jan 24, 2025

  1. For reference,
  1. In Python, default file names vary a bit with the domain, and hence one's expectations might be shaped in various ways. app.py is indeed common, with currently about 721.000 app.py files on GitHub.

  2. Still, main.py is an even more common name. At the time of writing, there are 2.2 million main.py files on GitHub. Interestingly, this is exactly because 'main' is a commonly used name in the Python world, like main(), __main__, or __main__.py. To adhere to this pythonic naming scheme and avoid surprises, main.py should in my opinion be default in uv init.

  3. I do not feel like there is one, universally accepted best practice for naming your first file. I think we would therefore need a command line argument for naming the default file. The command line option should also include a way to disable creating a default file altogether. Currently, one needs to advise uv init && rm hello.py, which seems unnecessarily convoluted and is not portable to PowerShell, so portable instructions require duplication. m(

  4. The default file is handy if one starts from scratch, but cumbersome if there is an existing codebase. With an existing code base, the use case is to introduce uv to it, not build something new. In projects with preexisting code, uv would ideally detect the presence of a codebase and not create a default file. This should be equivalent to using the deactivation functionality mentioned in 4.

@Gankra
Copy link
Contributor Author

Gankra commented Jan 24, 2025

Wow, thanks for all the great insight! That all seems pretty agreeable.

@zanieb
Copy link
Member

zanieb commented Jan 24, 2025

We are already tracking (5) in #6750

@charliermarsh charliermarsh mentioned this pull request Feb 8, 2025
@charliermarsh
Copy link
Member

It seems like FastAPI generally recommends main.py, at least here, though in my testing fastpi dev auto-detects both main.py and app.py (but not hello.py). Here's the full list: https://github.com/fastapi/fastapi-cli/blob/9a4741816dc288bbd931e693166117d98ee14dea/src/fastapi_cli/discover.py#L19-L26.

On the other hand, it looks like Flask auto-detects app.py, but not main.py (https://flask.palletsprojects.com/en/stable/cli/).

@Gankra Gankra force-pushed the gankra/apppy_juice branch from 88a360f to 16cded0 Compare February 11, 2025 17:45
@Gankra Gankra changed the base branch from main to tracking/060 February 11, 2025 17:45
@Gankra Gankra changed the title Create app.py instead of hello.py in uv init Create main.py instead of hello.py in uv init Feb 11, 2025
From the discussion, it seems like app.py maybe has one benefit (at least one tool seems to autodetect it) and main.py maybe has one downside (__main__ is already a thing and people might think this is related or get confused). So on balance if we have to pick one, app.py seems a bit better.
@zanieb zanieb force-pushed the gankra/apppy_juice branch from d655ef0 to 7a4a5b0 Compare February 13, 2025 21:46
@zanieb zanieb merged commit 697ada2 into tracking/060 Feb 13, 2025
73 checks passed
@zanieb zanieb deleted the gankra/apppy_juice branch February 13, 2025 21:58
zanieb pushed a commit that referenced this pull request Feb 13, 2025
Initially it seemed like `app.py` might be slightly more desirable but
people seem to overwhelmingly favour `main.py` as a good "generic" name.

Fixes #7782
zanieb pushed a commit that referenced this pull request Feb 13, 2025
Initially it seemed like `app.py` might be slightly more desirable but
people seem to overwhelmingly favour `main.py` as a good "generic" name.

Fixes #7782
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 17, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | minor | `0.5.31` -> `0.6.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.6.0`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#060)

[Compare Source](astral-sh/uv@0.5.31...0.6.0)

There have been 31 releases and 1135 pull requests since [0.5.0](https://github.com/astral-sh/uv/releases/tag/0.5.0), our last release with breaking changes. As before, we've accumulated various changes that improve correctness and user experience, but could break some workflows. This release contains those changes; many have been marked as breaking out of an abundance of caution. We expect most users to be able to upgrade without making changes.

##### Breaking changes

-   **Create `main.py` instead of `hello.py` in `uv init`** ([#&#8203;10369](astral-sh/uv#10369))

    Previously, `uv init` created a `hello.py` sample file. Now, `uv init` will create `main.py` instead — which aligns with expectations from user feedback. The `--bare` option can be used to avoid creating the file altogether.

-   **Respect `UV_PYTHON` in `uv python install`** ([#&#8203;11487](astral-sh/uv#11487))

    Previously, `uv python install` did not read this environment variable; now it does. We believe this matches user expectations, however, this will take priority over `.python-version` files which could be considered breaking.

-   **Set `UV` to the uv executable path** ([#&#8203;11326](astral-sh/uv#11326))

    When uv spawns a subprocess, it will now have the `UV` environment variable set to the `uv` binary path. This change is breaking if you are setting the `UV` environment variable yourself, as we will overwrite its value.

    Additionally, this change requires marking the uv Rust entrypoint (`uv::main`) as `unsafe` to avoid unsoundness — this is only relevant if you are invoking uv using Rust. See the [Rust documentation](https://doc.rust-lang.org/std/env/fn.set_var.html#safety) for details about the safety of updating a process' environment.

-   **Error on non-existent extras, e.g., in `uv sync`** ([#&#8203;11426](astral-sh/uv#11426))

    Previously, uv would silently ignore non-existent extras requested on the command-line (e.g., via `uv sync --extra foo`). This is *generally* correct behavior when resolving requests for package extras, because an extra may be present on one compatible version of a package but not another. However, this flexibility doesn't need to apply to the local project and it's less surprising to error here.

-   **Error on missing dependency groups when `--frozen` is provided** ([#&#8203;11499](astral-sh/uv#11499))

    Previously, uv would not validate that the requested dependency groups were present in the lockfile when the `--frozen` flag was used. Now, an error will be raised if a requested dependency group is not present.

-   **Change `-p` to a `--python` alias in `uv pip compile`** ([#&#8203;11486](astral-sh/uv#11486))

    In `uv pip compile`, `-p` was an alias for `--python-version` while everywhere else in uv's interface it is an alias for `--python`. Additionally, `uv pip compile` did not respect the `UV_PYTHON` environment variable. Now, the semantics of this flag have been updated for parity with the rest of the CLI.

    However, `--python-version` is unique: if we cannot find an interpreter with the given version, we will not fail. Instead, we'll use an alternative interpreter and override its version tags with the requested version during package resolution. This behavior is retained here for backwards compatibility, `--python <version>` / `-p <version>` will not fail if the version cannot be found. However, if a specific interpreter is requested, e.g., with `--python <path>` or `--python pypy`, and cannot be found — uv will exit with an error.

    The breaking changes here are that `UV_PYTHON` is respected and `--python <version>` will no longer fail if the version cannot be found.

-   **Bump `alpine` default tag to 3.21 for derived Docker images** ([#&#8203;11157](astral-sh/uv#11157))

    Alpine 3.21 was released in Dec 2024 and is used in the official Alpine-based Python images. Our `uv:python3.x-alpine` images have been using 3.21 since uv v0.5.8. However, now the the `uv:alpine` image will use 3.21 instead of 3.20 and `uv:alpine3.20` will no longer be updated.

-   **Use files instead of junctions on Windows** ([#&#8203;11269](astral-sh/uv#11269))

    Previously, we used junctions for atomic replacement of cache entries on Windows. Now, we use a file with a pointer to the cache entry instead. This resolves various edge-case behaviors with junctions. These files are only intended to be consumed by uv and the cache version has been bumped. We do not think this change will affect workflows.

##### Stabilizations

-   **`uv publish` is no longer in preview** ([#&#8203;11032](astral-sh/uv#11032))

    This does not come with any behavior changes. You will no longer see an experimental warning when using `uv publish`. See the linked pull request for a report on the stabilization.

##### Enhancements

-   Support `--active` for PEP 723 script environments ([#&#8203;11433](astral-sh/uv#11433))
-   Add `revision` to the lockfile to allow backwards-compatible metadata changes ([#&#8203;11500](astral-sh/uv#11500))

##### Bug fixes

-   Avoid reading metadata from `.egg-info` files ([#&#8203;11395](astral-sh/uv#11395))
-   Include archive bucket version in archive pointers ([#&#8203;11306](astral-sh/uv#11306))
-   Omit lockfile version when additional fields are dynamic ([#&#8203;11468](astral-sh/uv#11468))
-   Respect executable name in `uvx --from tool@latest` ([#&#8203;11465](astral-sh/uv#11465))

##### Documentation

-   The `CHANGELOG.md` is now split into separate files for each "major" version to fix rendering ([#&#8203;11510](astral-sh/uv#11510))

</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:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNzAuMSIsInVwZGF0ZWRJblZlciI6IjM5LjE3MC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
@Kludex
Copy link

Kludex commented Feb 18, 2025

main is far better choice than any alternative. Good job.

@zanieb
Copy link
Member

zanieb commented Feb 18, 2025

:D thanks Marcelo

loic-lescoat pushed a commit to loic-lescoat/uv that referenced this pull request Mar 2, 2025
Initially it seemed like `app.py` might be slightly more desirable but
people seem to overwhelmingly favour `main.py` as a good "generic" name.

Fixes astral-sh#7782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A breaking change enhancement New feature or improvement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: uv init option to specify alternative filename to hello.py
5 participants