Skip to content

Poetry VS Pixi when building Python CLI apps #2392

Answered by jesserobertson
T145 asked this question in Q&A
Discussion options

You must be logged in to vote

FWIW I found this a bit non-obvious, although a combo of stackoverflow and hatchling docs got me there in the end.

In case it helps someone looking for the magic commands to include, here's what worked for me. If I have a hello world CLI in src/PACKAGE/cli.py:

# file: src/PACKAGE/cli.py
import typer

cli = typer.Typer()

@cli.command()
def hello(name: str):
    typer.echo(f"Hello {name}")

if __name__ == "__main__":
    cli()

...then this is what I put in the pyproject.toml:

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

[project.scripts]
pkg_cli = "PACKAGE.cli:cli"
# ...

...and I can just run the command in the pixi shell (or when it gets installed etc):

$…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@T145
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by T145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants