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

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

Open
Ravencentric opened this issue Sep 26, 2024 · 6 comments · May be fixed by #7756
Open

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

Ravencentric opened this issue Sep 26, 2024 · 6 comments · May be fixed by #7756

Comments

@Ravencentric
Copy link

Ravencentric commented Sep 26, 2024

Feature Request

poetry init autofills the authors field:

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

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 = "[email protected]" },
]
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
@Ravencentric Ravencentric changed the title uv init should add author field in pyproject.toml uv init should autofill the authors field in pyproject.toml Sep 26, 2024
@charliermarsh
Copy link
Member

How would we determine the authors in this case?

@Ravencentric
Copy link
Author

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:

  • poetry

    $ poetry new --src hello-poetry && cat hello-poetry/pyproject.toml
    
    [tool.poetry]
    name = "hello-poetry"
    version = "0.1.0"
    description = ""
    authors = ["Your Name <[email protected]>"]
    readme = "README.md"
    packages = [{include = "hello_poetry", from = "src"}]
    
    [tool.poetry.dependencies]
    python = "^3.12"
    
    
    [build-system]
    requires = ["poetry-core"]
    build-backend = "poetry.core.masonry.api"
  • hatch

    $ hatch new hello-hatch && cat hello-hatch/pyproject.toml
    [build-system]
    requires = ["hatchling"]
    build-backend = "hatchling.build"
    
    [project]
    name = "hello-hatch"
    dynamic = ["version"]
    description = ''
    readme = "README.md"
    requires-python = ">=3.8"
    license = "MIT"
    keywords = []
    authors = [
    { name = "U.N. Owen", email = "[email protected]" },
    ]
    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 = []

Case 2: Configured git exists on the system

Configure git:

$ git config --global user.name "raven"
$ git config --global user.email "[email protected]"
$ git config user.name
raven
$ git config user.email
[email protected]

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

  • poetry

    $ poetry new --src hello-poetry && cat hello-poetry/pyproject.toml
    [tool.poetry]
    name = "hello-poetry"
    version = "0.1.0"
    description = ""
    authors = ["raven <[email protected]>"]
    readme = "README.md"
    packages = [{include = "hello_poetry", from = "src"}]
    
    [tool.poetry.dependencies]
    python = "^3.12"
    
    
    [build-system]
    requires = ["poetry-core"]
    build-backend = "poetry.core.masonry.api"
  • hatch

    $ hatch new hello-hatch && cat hello-hatch/pyproject.toml
    [build-system]
    requires = ["hatchling"]
    build-backend = "hatchling.build"
    
    [project]
    name = "hello-hatch"
    dynamic = ["version"]
    description = ''
    readme = "README.md"
    requires-python = ">=3.8"
    license = "MIT"
    keywords = []
    authors = [
    { name = "raven", email = "[email protected]" },
    ]
    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 = []

@j178 j178 linked a pull request Sep 28, 2024 that will close this issue
@FishAlchemist
Copy link
Contributor

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

dpprdan commented Sep 28, 2024

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.

@Ravencentric
Copy link
Author

Ravencentric commented Sep 28, 2024

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

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 a pull request may close this issue.

4 participants