-
Notifications
You must be signed in to change notification settings - Fork 877
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
Fill in authors
filed during uv init
#7756
Conversation
a654f16
to
249b8fb
Compare
fs_err::create_dir_all(path)?; | ||
|
||
// Get the author information from git configuration. | ||
let author = if no_authors { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! For non-packaged application project types, I would probably end up deleting the author info most of the time.
What do you think about only adding it for libraries + package=true app types? ie: Putting this block inside an if package
conditional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable to me, I think. If we do this, we should add an --authors
flag too and allow it to force them to be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding --authors
, shoule we enable it to accept a value? For example: uv init --authors 'Alice <alice@exmaple.org>'
or uv init --authors Alice
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's... a good question. It makes sense to allow providing the authors, but also it breaks our typical --no-<flag>
/ --<flag>
pattern. I think we'd need like... --authors git
as a special value that says fetch from git?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or rename this flag as something like --fill-authors
/ --no-fill-authors
and keep --authors
for future usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to introduce a bunch of flags for this. I'll do some thinking out loud. Typically, we use singular names for options that can be repeated so... --author <name> --author <another name>
makes sense to me. Then... --no-authors
with a --no-author
alias to disable detection? Then we're left with "I want the author to be derived from somewhere even if it's an app" which could be like --force-author
or we can reuse --author
and add a special key like auto
. This is sort of nice because we can add more special keys like git
, os
, etc. for various author sources? This would let you force read from a source e.g. uv init --vcs git --author os
which would otherwise be another new flag like --author-from
? I think collisions are pretty unlikely but it does make the flag less self-documenting.
I shall seek another opinion here. cc @BurntSushi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my initial reaction here is that it's not worth changing this flag's behavior based on library versus application. It's not immediately obvious to me why we would make that distinction by default. If folks don't want author information, then instead of deleting it after-the-fact, they can do --no-authors
.
Otherwise, how far do we want to go with uv init
being an interface for writing metadata values to pyproject.toml
? If we just want it to be something that tries to infer things with reasonable defaults, then we might not need to expose functionality like --author BurntSushi
.
Failing all of that, I like your approach @zanieb. I might use infer-git
instead of just git
for example. Or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my initial reaction here is that it's not worth changing this flag's behavior based on library versus application. It's not immediately obvious to me why we would make that distinction by default
I guess I like sensible defaults. I don't think the default has much bearing on the flag name though, we still need both toggles for consistency with the rest of our CLI.
Right now we don't really support passing metadata directly, but I think we generally should in the future so I want to design in a way that we won't regret.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my initial reaction here is that it's not worth changing this flag's behavior based on library versus application. It's not immediately obvious to me why we would make that distinction by default. If folks don't want author information, then instead of deleting it after-the-fact, they can do
--no-authors
.
For me, the reason why I wouldn't want authors (or any other optional fields related to packaging) defined in a pyproject.toml
for an app project type, is that if the package doesn't have a build backend and isn't being published to PyPI, then it's extra clutter/something to understand/keep up to date that isn't adding any value. (So really this is more about build backend/publishing vs not, rather than app vs library.)
Users could of course delete those fields afterwards, but they'd have to know that they were optional or else be willing to try deleting them and seeing if something breaks (and hoping that the tool's schema validation is solid enough that it gives me a suitable upfront error message rather than something silently breaking later).
Would a compromise that could keep uv init
simpler (and avoid the need to support multiple VCSes and OS username lookup etc) be to instead not populate authors at all in uv init
and instead have uv publish
handle making the package "publish ready" wrt best practices etc (eg prompting if metadata not filled out).
let author = if no_authors { | ||
Author::default() | ||
} else { | ||
get_author_from_git(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the VCS isn't Git?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just use Git as a source of information (a common one), it is valid information even if current VCS is not Git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's valuable to use the information from the relevant VCS — so if you say not to use Git we shouldn't fetch information from it or if you say to use Mercurial the author information should come from there.
We could consider adding OS-level author information fetches, but let's do that separately than this.
This comment was marked as outdated.
This comment was marked as outdated.
I'll go with #[derive(Debug, Default, Copy, Clone, clap::ValueEnum)]
pub enum AuthorFrom {
/// Fetch the author information from some sources (e.g., Git) automatically.
#[default]
Auto,
/// Fetch the author information for Git configuration only.
Git,
/// Do not infer the author information.
None,
} |
f9045ef
to
5f10876
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I am trying to get the dan@DP:~/projects/test-uv$ uv version
uv 0.4.20
dan@DP:~/projects/test-uv$ git config --get user.name
Daniel Possenriede
dan@DP:~/projects/test-uv$ ls -a
. ..
dan@DP:~/projects/test-uv$ uv init --author-from auto
Initialized project `test-uv`
dan@DP:~/projects/test-uv$ cat pyproject.toml
[project]
name = "test-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
dan@DP:~/projects/test-uv$ rm -r {*,.*}
dan@DP:~/projects/test-uv$ uv init --lib
Initialized project `test-uv`
dan@DP:~/projects/test-uv$ cat pyproject.toml
[project]
name = "test-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build" |
@dpprdan Can you show the output of |
@j178 Sure dan@DP:~/projects/test-uv$ uv init -v --lib
DEBUG uv 0.4.20
DEBUG Searching for default Python interpreter in managed installations or system path
DEBUG Searching for managed installations at `/home/dan/.local/share/uv/python`
DEBUG Found `cpython-3.12.3-linux-x86_64-gnu` at `/usr/bin/python3` (search path)
WARN Failed to get author from git: No author information found
DEBUG Writing Python versions to `/home/dan/projects/test-uv/.python-version`
Initialized project `test-uv`
dan@DP:~/projects/test-uv$ git --version
git version 2.43.0
dan@DP:~/projects/test-uv$ git config --global user.name
Daniel Possenriede
dan@DP:~/projects/test-uv$ git config --global user.email
me@example.com |
FWIW this is on Ubuntu 24.04 on WSL. |
Seems like the git config --get/git config get command is not a stable interface - or Compare |
I think that's it. With v2.43.0 I see dan@DP:~/projects/test-uv$ git config get user.name
fatal: not in a git directory # well of course, it is not yet initialised.
dan@DP:~/projects/test-uv$ git config --get user.name
Daniel Possenriede So better use |
On it! |
…compatibility (#8101) See #7756 (comment)
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.4.18` -> `0.4.20` | 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.20`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0420) [Compare Source](astral-sh/uv@0.4.19...0.4.20) ##### Enhancements - Add managed downloads for CPython 3.13.0 (final) ([#​8010](astral-sh/uv#8010)) - Python 3.13 is the default version for `uv python install` ([#​8010](astral-sh/uv#8010)) - Hint at wrong endpoint in `uv publish` failures ([#​7872](astral-sh/uv#7872)) - List available scripts when a command is not specified for `uv run` ([#​7687](astral-sh/uv#7687)) - Fill in `authors` field during `uv init` ([#​7756](astral-sh/uv#7756)) ##### Documentation - Add snapshot testing to contribution guide ([#​7882](astral-sh/uv#7882)) - Fix and improve GitLab integration docs ([#​8000](astral-sh/uv#8000)) ### [`v0.4.19`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0419) [Compare Source](astral-sh/uv@0.4.18...0.4.19) ##### Enhancements - Add managed downloads for CPython 3.13.0rc3 and 3.12.7 ([#​7880](astral-sh/uv#7880)) - Display the target virtual environment path if non-default ([#​7850](astral-sh/uv#7850)) - Preserve case-insensitive sorts in `uv add` ([#​7864](astral-sh/uv#7864)) - Respect project upper bounds when filtering wheels on `requires-python` ([#​7904](astral-sh/uv#7904)) - Add `--script` to `uv run` to treat an input as PEP 723 regardless of extension ([#​7739](astral-sh/uv#7739)) - Improve legibility of build failure errors ([#​7854](astral-sh/uv#7854)) - Show interpreter source during Python discovery query errors ([#​7928](astral-sh/uv#7928)) ##### Configuration - Add `UV_FIND_LINKS` environment variable for `--find-links` ([#​7912](astral-sh/uv#7912)) - Ignore empty string values for `UV_PYTHON` environment variable ([#​7878](astral-sh/uv#7878)) ##### Bug fixes - Allow `py3x-none` tags in newer than Python 3.x ([#​7867](astral-sh/uv#7867)) - Allow self-dependencies in the `dev` section ([#​7943](astral-sh/uv#7943)) - Always ignore `cp2` wheels in resolution ([#​7902](astral-sh/uv#7902)) - Clear the publish progress bar on retry ([#​7921](astral-sh/uv#7921)) - Fix parsing of `gnueabi` libc variants in Python version requests ([#​7975](astral-sh/uv#7975)) - Simplify supported environments when comparing to lockfile ([#​7894](astral-sh/uv#7894)) - Trim commits when reading from Git refs ([#​7922](astral-sh/uv#7922)) - Use a higher HTTP read timeout when publishing packages ([#​7923](astral-sh/uv#7923)) - Remove the first empty line for `uv tree --package foo` ([#​7885](astral-sh/uv#7885)) ##### Documentation - Add 3.13 support to the platform reference ([#​7971](astral-sh/uv#7971)) - Clarify project environment creation ([#​7941](astral-sh/uv#7941)) - Fix code block title in Gitlab integration docs ([#​7861](astral-sh/uv#7861)) - Fix project guide section on adding a Git dependency ([#​7916](astral-sh/uv#7916)) - Fix uninstallation command for Windows ([#​7944](astral-sh/uv#7944)) - Clearly specify the minimum supported Windows Server version ([#​7946](astral-sh/uv#7946)) ##### Rust API - Remove unused `Sha256Reader` ([#​7929](astral-sh/uv#7929)) - Remove unnecessary `Deserialize` derives on settings ([#​7856](astral-sh/uv#7856)) </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=-->
Summary
Fill in the
authors
field ofpyproject.toml
by fetching author info from Git.Resolves #7718