Skip to content

Commit

Permalink
init: Use main as default function in packaged app
Browse files Browse the repository at this point in the history
Create a function main as the default for a packaged app.
Configure the default executable as:

example-packaged-app = "example_packaged_app:main"

Which is often what you want - the executable has the same name as the
app.
  • Loading branch information
bluss committed Sep 24, 2024
1 parent e6cd6c9 commit f349bf6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl InitProjectKind {
if package {
// Since it'll be packaged, we can add a `[project.scripts]` entry
pyproject.push('\n');
pyproject.push_str(&pyproject_project_scripts(name, "hello", "hello"));
pyproject.push_str(&pyproject_project_scripts(name, name.as_str(), "main"));

// Add a build system
pyproject.push('\n');
Expand All @@ -479,7 +479,7 @@ impl InitProjectKind {
fs_err::write(
init_py,
indoc::formatdoc! {r#"
def hello() -> None:
def main() -> None:
print("Hello from {name}!")
"#},
)?;
Expand Down
6 changes: 3 additions & 3 deletions docs/concepts/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ example-packaged-app
But the module defines a CLI function:

```python title="__init__.py"
def hello() -> None:
def main() -> None:
print("Hello from example-packaged-app!")
```

Expand All @@ -247,7 +247,7 @@ requires-python = ">=3.11"
dependencies = []

[project.scripts]
hello = "example_packaged_app:hello"
example-packaged-app = "example_packaged_app:hello"

[build-system]
requires = ["hatchling"]
Expand All @@ -257,7 +257,7 @@ build-backend = "hatchling.build"
Which can be executed with `uv run`:

```console
$ uv run hello
$ uv run example-packaged-app
Hello from example-packaged-app!
```

Expand Down

0 comments on commit f349bf6

Please sign in to comment.