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

Fill in authors filed during uv init #7756

Merged
merged 6 commits into from
Oct 8, 2024
Merged

Conversation

j178
Copy link
Contributor

@j178 j178 commented Sep 28, 2024

Summary

Fill in the authors field of pyproject.toml by fetching author info from Git.

Resolves #7718

@j178 j178 force-pushed the init-author branch 2 times, most recently from a654f16 to 249b8fb Compare September 28, 2024 12:43
@j178 j178 marked this pull request as ready for review September 28, 2024 12:54
fs_err::create_dir_all(path)?;

// Get the author information from git configuration.
let author = if no_authors {
Copy link
Contributor

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?

Copy link
Member

@zanieb zanieb Sep 29, 2024

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

@edmorley edmorley Oct 1, 2024

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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@j178 j178 Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worthwhile to add a new dependency like whoami or users to fetch the OS username as a fallabck method?

Copy link
Member

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.

@j178

This comment was marked as outdated.

@j178
Copy link
Contributor Author

j178 commented Oct 3, 2024

I'll go with --author-from auto|git|none:

#[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,
}

@j178 j178 requested a review from zanieb October 3, 2024 09:01
@j178 j178 force-pushed the init-author branch 4 times, most recently from f9045ef to 5f10876 Compare October 3, 2024 15:45
@zanieb zanieb self-assigned this Oct 3, 2024
Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@zanieb zanieb merged commit 15e5e3f into astral-sh:main Oct 8, 2024
61 checks passed
@dpprdan
Copy link
Contributor

dpprdan commented Oct 10, 2024

I am trying to get the authors field written by uv init, but without success so far. What am I doing wrong?

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"

@j178
Copy link
Contributor Author

j178 commented Oct 10, 2024

@dpprdan Can you show the output of uv init -v --lib and git --version?

@dpprdan
Copy link
Contributor

dpprdan commented Oct 10, 2024

@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

@dpprdan
Copy link
Contributor

dpprdan commented Oct 10, 2024

FWIW this is on Ubuntu 24.04 on WSL.

@bluss
Copy link
Contributor

bluss commented Oct 10, 2024

Seems like the git config --get/git config get command is not a stable interface - or --get is the variant that has been there longer.

Compare

@dpprdan
Copy link
Contributor

dpprdan commented Oct 10, 2024

I think that's it. git config get was apparently introduced in v2.46.0 (vs v.2.45.0).

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 git config --get for backwards compatibility?

@zanieb
Copy link
Member

zanieb commented Oct 10, 2024

On it!

zanieb added a commit that referenced this pull request Oct 10, 2024
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 11, 2024
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) ([#&#8203;8010](astral-sh/uv#8010))
-   Python 3.13 is the default version for `uv python install` ([#&#8203;8010](astral-sh/uv#8010))
-   Hint at wrong endpoint in `uv publish` failures ([#&#8203;7872](astral-sh/uv#7872))
-   List available scripts when a command is not specified for `uv run` ([#&#8203;7687](astral-sh/uv#7687))
-   Fill in `authors` field during `uv init` ([#&#8203;7756](astral-sh/uv#7756))

##### Documentation

-   Add snapshot testing to contribution guide ([#&#8203;7882](astral-sh/uv#7882))
-   Fix and improve GitLab integration docs ([#&#8203;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 ([#&#8203;7880](astral-sh/uv#7880))
-   Display the target virtual environment path if non-default ([#&#8203;7850](astral-sh/uv#7850))
-   Preserve case-insensitive sorts in `uv add` ([#&#8203;7864](astral-sh/uv#7864))
-   Respect project upper bounds when filtering wheels on `requires-python` ([#&#8203;7904](astral-sh/uv#7904))
-   Add `--script` to `uv run` to treat an input as PEP 723 regardless of extension ([#&#8203;7739](astral-sh/uv#7739))
-   Improve legibility of build failure errors ([#&#8203;7854](astral-sh/uv#7854))
-   Show interpreter source during Python discovery query errors ([#&#8203;7928](astral-sh/uv#7928))

##### Configuration

-   Add `UV_FIND_LINKS` environment variable for `--find-links` ([#&#8203;7912](astral-sh/uv#7912))
-   Ignore empty string values for `UV_PYTHON` environment variable ([#&#8203;7878](astral-sh/uv#7878))

##### Bug fixes

-   Allow `py3x-none` tags in newer than Python 3.x ([#&#8203;7867](astral-sh/uv#7867))
-   Allow self-dependencies in the `dev` section ([#&#8203;7943](astral-sh/uv#7943))
-   Always ignore `cp2` wheels in resolution ([#&#8203;7902](astral-sh/uv#7902))
-   Clear the publish progress bar on retry ([#&#8203;7921](astral-sh/uv#7921))
-   Fix parsing of `gnueabi` libc variants in Python version requests ([#&#8203;7975](astral-sh/uv#7975))
-   Simplify supported environments when comparing to lockfile ([#&#8203;7894](astral-sh/uv#7894))
-   Trim commits when reading from Git refs ([#&#8203;7922](astral-sh/uv#7922))
-   Use a higher HTTP read timeout when publishing packages ([#&#8203;7923](astral-sh/uv#7923))
-   Remove the first empty line for `uv tree --package foo` ([#&#8203;7885](astral-sh/uv#7885))

##### Documentation

-   Add 3.13 support to the platform reference ([#&#8203;7971](astral-sh/uv#7971))
-   Clarify project environment creation ([#&#8203;7941](astral-sh/uv#7941))
-   Fix code block title in Gitlab integration docs ([#&#8203;7861](astral-sh/uv#7861))
-   Fix project guide section on adding a Git dependency ([#&#8203;7916](astral-sh/uv#7916))
-   Fix uninstallation command for Windows ([#&#8203;7944](astral-sh/uv#7944))
-   Clearly specify the minimum supported Windows Server version ([#&#8203;7946](astral-sh/uv#7946))

##### Rust API

-   Remove unused `Sha256Reader` ([#&#8203;7929](astral-sh/uv#7929))
-   Remove unnecessary `Deserialize` derives on settings ([#&#8203;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=-->
@j178 j178 deleted the init-author branch October 13, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv init should autofill the authors field in pyproject.toml
6 participants