astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
12.08k stars 425 forks source link

Add [project.scripts] to initial pyproject.toml #1165

Open noamraph opened 1 week ago

noamraph commented 1 week ago

I think this was the behavior in previous versions, I don't know why it was changed.

I suggest to have a section [project.scripts] in the initial pyproject.toml, which will call the already-created hello function.

Currently when I do rye init the pyproject.toml doesn't have this section, and I have to google to find what to add.

Thanks!

Details:

Version:

rye 0.34.0
commit: 0.34.0 (d31340178 2024-05-20)
platform: linux (x86_64)
self-python: cpython@3.12.0
symlink support: true
uv enabled: true

pyproject.toml created after running rye init tmpproj:

[project]
name = "tmpproj"
version = "0.1.0"
description = "Add your description here"
authors = [
    { name = "Noam Yorav-Raphael", email = "noamraph@gmail.com" }
]
dependencies = []
readme = "README.md"
requires-python = ">= 3.8"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = []

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src/tmpproj"]

When adding this:

[project.scripts]
tmpproj = "tmpproj:hello"

I can run:

❯ rye run tmpproj
Hello from tmpproj!
my1e5 commented 1 week ago

rye init tmpproj creates a library project by default. What you want is rye init --script tmpproj which creates a project that is intended to be executable. Using the --script flag will create an __init__.py file and __main__.py file and also add

[project.scripts]
"tmpproj" = "tmpproj:main"

in your pyproject.toml file. And you can run

❯ rye run tmpproj
Hello from tmpproj!