astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
27.89k stars 802 forks source link

`uv init` should autofill the `authors` field in pyproject.toml #7718

Closed Ravencentric closed 1 month ago

Ravencentric commented 2 months ago

Feature Request

poetry init autofills the authors field:

❯ cat .\pyproject.toml
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["Ravencentric <my@example.email>"]

I find this quite helpful. This is usually boiler-plate that I'll have to fill anyway and not something that frequently changes so I doubt this will be controversial either. Would love to see this in uv init.

Wish

I would also like it if uv init would autofill license field. MIT seems to be the popular option as of 2018. This might be harder to get a consensus on so I don't mind if this gets rejected. This can also be tied to a specific mode, like say --package and --lib but not with --app since the former two are supposed to be published and the latter isn't. Prior art example for this would be hatch which upon hatch new creates this:

[project]
name = "hello"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
keywords = []
authors = [
  { name = "Ravencentric", email = "my@example.email" },
]
classifiers = [
  "Development Status :: 4 - Beta",
  "Programming Language :: Python",
  "Programming Language :: Python :: 3.8",
  "Programming Language :: Python :: 3.9",
  "Programming Language :: Python :: 3.10",
  "Programming Language :: Python :: 3.11",
  "Programming Language :: Python :: 3.12",
  "Programming Language :: Python :: Implementation :: CPython",
  "Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []

along with the license.txt

hello
├── src
│   └── hello
│       ├── __about__.py
│       └── __init__.py
├── tests
│   └── __init__.py
├── LICENSE.txt
├── README.md
└── pyproject.toml
charliermarsh commented 2 months ago

How would we determine the authors in this case?

Ravencentric commented 2 months ago

So I just checked poetry, pdm, and hatch. Both poetry and hatch pull the author from git. pdm is an exception here since pdm's init interactively asks the user for author instead.

Case 1: No git on the system OR unconfigured git

You can check that git (if installed) doesn't have a configured author by running:

$ git config user.name # no output
$ git config user.email # no output

Both hatch and poetry use a placeholder in this case:

Case 2: Configured git exists on the system

Configure git:

$ git config --global user.name "raven"
$ git config --global user.email "raven@email.com"
$ git config user.name
raven
$ git config user.email
raven@email.com

Now both poetry and hatch will pull the author field from the above git configuration:

Ravencentric commented 2 months ago

Relevant poetry snippet: https://github.com/python-poetry/poetry/blob/150ff09e5609f9ea9f5502e7f8b4720458e5126b/src/poetry/console/commands/init.py#L152-L157

Relevant hatch snippet(s): https://github.com/pypa/hatch/blob/5352e4422636cf1238017a74f0c67d689ccee558/src/hatch/config/model.py#L460-L483 https://github.com/pypa/hatch/blob/5352e4422636cf1238017a74f0c67d689ccee558/src/hatch/config/model.py#L491-L514

FishAlchemist commented 2 months ago

As I prefer not to expose my personal email in the Git commit history, I usually set up accounts with email addresses like @users.noreply.github.com and @users.noreply.gitlab.com. Therefore, I hope that when encountering these two types of email addresses, they won't be set as the author's email, or a warning will be initialized.

dpprdan commented 2 months ago

How would we determine the authors in this case?

pdm's init interactively asks the user for author instead.

I'd prefer pdm's approach (also w.r.t. @FishAlchemist's comment), plus a way to store this info in the user-level configuration (e.g., ~/.config/uv/uv.toml).

For a non-Python precedent see use_description() from the {usethis} R 📦 (especially the paragraph starting with "If you create a lot of packages, ..."). lt can also set a licence and package (or project) language. (In R, the DESCRIPTION file is the equivalent to pyproject.toml.)

Ravencentric commented 2 months ago

I like the idea of being able to define commonly shared project metadata in user level uv.toml

zanieb commented 1 month ago

Defining metadata in the uv.toml seems nice, as does reading from git by default. I think that we won't make this command interactive just for this feature, but I think an --interactive / -i flag would be nice in the future.