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

✨ How to define custom commands like tool.rye.scripts #6302

Closed
jd-solanki opened this issue Aug 21, 2024 · 9 comments
Closed

✨ How to define custom commands like tool.rye.scripts #6302

jd-solanki opened this issue Aug 21, 2024 · 9 comments
Labels
enhancement New feature or improvement to existing functionality projects Related to project management capabilities

Comments

@jd-solanki
Copy link

Hi πŸ‘‹πŸ»

I'm really happy for UV. I always wanted better python ecosystem thanks all of you for your efforts.

I want to migrate from rye to UV as I'm starting new project and wanted to add custom command like uv run dev that executes uv run fastapi dev src/backend/main.py for me.

In Rye, I used to define it under scripts section:

[tool.rye.scripts]
dev = "uvicorn aitools.main:app --reload"
migration = "alembic revision --autogenerate -m"
migrate = "alembic upgrade head"
downgrade = "alembic downgrade -1"

However, It looks like UV don't have this feature or isn't documented yet.

@captnswing
Copy link

I think this is done in the [project.scripts] table.

See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#creating-executable-scripts

@jorgebodega
Copy link

jorgebodega commented Aug 21, 2024

It is not exactly the same. [project.scripts] requires a python file to be created to execute something.

To achieve this, I'm still using poethepoet inherited from poetry, and it just works.

But yes, this would be great to have inside uv.

@patrick91
Copy link

pdm does it like this:

[tool.pdm.scripts]
start = "flask run -p 54321"

@zanieb
Copy link
Member

zanieb commented Aug 21, 2024

Yeah we don't support this yet, but we plan to in some way.

@zanieb zanieb added enhancement New feature or improvement to existing functionality projects Related to project management capabilities labels Aug 21, 2024
@anthonycorletti
Copy link

this sounds really useful.

my solution for this right now is leaving scripts in a bin directory which does the trick because i don't have to remember commands or reverse-i-search forever. would love to have something like this:

# ...

[tool.uv.scripts]
clean = "rm -rf build dist *_cache"
format = "ruff format"
check = "ruff check"
test = "pytest"
dev = "uvicorn app.main:app --reload"

[tool.uv.scripts.combos]
ok = ["clean", "format", "check", "test"]

# ...

@patrick91
Copy link

patrick91 commented Aug 23, 2024

@anthonycorletti the combo stuff is interesting, mise does it like this:

[tasks.fetch-openapi]
run = "curl localhost:8000/api/v1/openapi.json -O"

[tasks.modify-openapi]
run = "node modify-openapi-operationids.js"
depends = ["fetch-openapi"]

but I wonder if this is scope creep :D

@ion-elgreco
Copy link

This would be nice to have so I don't need to have separate make/just files

@my1e5
Copy link
Contributor

my1e5 commented Aug 27, 2024

Duplicate of #5903

@jd-solanki jd-solanki closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
@phihung
Copy link

phihung commented Oct 30, 2024

Hi. I created a small, dependency-free tool to manage scripts directly from pyproject.toml:
https://github.com/phihung/tomlscript

It works with all dependencies management tools. Tested with uv, pip and poetry.

Configuration example

[tool.tomlscript]
# Start dev server ==> this line is the documentation of the command
dev = "uv run uvicorn --port {port:5001} myapp:app --reload"

# Linter and test 
test = """
uv run ruff check
uv run pytest --inline-snapshot=review
"""

# Generate pyi stubs (python function) ==> Execute python function
gen_pyi = "mypackage.typing:generate_pyi"

setup_dev = """
uv sync
uv run mypy --install-types--non-interactive
aws s3 cp s3://my-bucket/model ./models
"""

Usage

alias tom="uvx tomlscript"

tom  # list commands
tom setup_dev # Setup dev env, install dependencies, etc
tom dev --port 8000
tom gen_pyi  --mode all  # execute python function with arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality projects Related to project management capabilities
Projects
None yet
Development

No branches or pull requests

9 participants