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

packaged app: use executable named for the project and main function #7670

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 6 additions & 6 deletions crates/uv/tests/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn init_application_package() -> Result<()> {
dependencies = []

[project.scripts]
hello = "foo:hello"
foo = "foo:main"

[build-system]
requires = ["hatchling"]
Expand All @@ -294,13 +294,13 @@ fn init_application_package() -> Result<()> {
}, {
assert_snapshot!(
init, @r###"
def hello() -> None:
def main() -> None:
print("Hello from foo!")
"###
);
});

uv_snapshot!(context.filters(), context.run().current_dir(&child).arg("hello"), @r###"
uv_snapshot!(context.filters(), context.run().current_dir(&child).arg("foo"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -1423,7 +1423,7 @@ fn init_virtual_project() -> Result<()> {
dependencies = []

[project.scripts]
hello = "foo:hello"
foo = "foo:main"
Copy link
Contributor Author

@bluss bluss Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm mistaken here, but I think this test shows that uv init --virtual is already creating something with a build system and executable, this is fishy.

Copy link
Member

@zanieb zanieb Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is fishy — --virtual is legacy now but shouldn't be doing this. Let's tackle it separately though.


[build-system]
requires = ["hatchling"]
Expand Down Expand Up @@ -1457,7 +1457,7 @@ fn init_virtual_project() -> Result<()> {
dependencies = []

[project.scripts]
hello = "foo:hello"
foo = "foo:main"

[build-system]
requires = ["hatchling"]
Expand Down Expand Up @@ -1552,7 +1552,7 @@ fn init_nested_virtual_workspace() -> Result<()> {
dependencies = []

[project.scripts]
hello = "foo:hello"
foo = "foo:main"

[build-system]
requires = ["hatchling"]
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:main"

[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
Loading