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

Create app.py instead of hello.py in uv init #10369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,13 @@ impl InitProjectKind {
// Generate `src` files
generate_package_scripts(name, path, build_backend, false)?;
} else {
// Create `hello.py` if it doesn't exist
// TODO(zanieb): Only create `hello.py` if there are no other Python files?
let hello_py = path.join("hello.py");
if !hello_py.try_exists()? {
// Create `app.py` if it doesn't exist
// (This isn't intended to be a particularly special or magical filename, just nice)
// TODO(zanieb): Only create `app.py` if there are no other Python files?
let app_py = path.join("app.py");
if !app_py.try_exists()? {
fs_err::write(
path.join("hello.py"),
path.join("app.py"),
indoc::formatdoc! {r#"
def main():
print("Hello from {name}!")
Expand Down
36 changes: 18 additions & 18 deletions crates/uv/tests/it/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn init_application() -> Result<()> {
child.create_dir_all()?;

let pyproject_toml = child.join("pyproject.toml");
let hello_py = child.join("hello.py");
let app_py = child.join("app.py");

uv_snapshot!(context.filters(), context.init().current_dir(&child).arg("--app"), @r###"
success: true
Expand Down Expand Up @@ -101,7 +101,7 @@ fn init_application() -> Result<()> {
);
});

let hello = fs_err::read_to_string(hello_py)?;
let hello = fs_err::read_to_string(app_py)?;
insta::with_settings!({
filters => context.filters(),
}, {
Expand All @@ -117,7 +117,7 @@ fn init_application() -> Result<()> {
);
});

uv_snapshot!(context.filters(), context.run().current_dir(&child).arg("hello.py"), @r###"
uv_snapshot!(context.filters(), context.run().current_dir(&child).arg("app.py"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand All @@ -134,7 +134,7 @@ fn init_application() -> Result<()> {
Ok(())
}

/// When `hello.py` already exists, we don't create it again
/// When `app.py` already exists, we don't create it again
#[test]
fn init_application_hello_exists() -> Result<()> {
let context = TestContext::new("3.12");
Expand All @@ -143,8 +143,8 @@ fn init_application_hello_exists() -> Result<()> {
child.create_dir_all()?;

let pyproject_toml = child.join("pyproject.toml");
let hello_py = child.child("hello.py");
hello_py.touch()?;
let app_py = child.child("app.py");
app_py.touch()?;

uv_snapshot!(context.filters(), context.init().current_dir(&child).arg("--app"), @r###"
success: true
Expand Down Expand Up @@ -172,7 +172,7 @@ fn init_application_hello_exists() -> Result<()> {
);
});

let hello = fs_err::read_to_string(hello_py)?;
let hello = fs_err::read_to_string(app_py)?;
insta::with_settings!({
filters => context.filters(),
}, {
Expand All @@ -184,7 +184,7 @@ fn init_application_hello_exists() -> Result<()> {
Ok(())
}

/// When other Python files already exists, we still create `hello.py`
/// When other Python files already exists, we still create `app.py`
#[test]
fn init_application_other_python_exists() -> Result<()> {
let context = TestContext::new("3.12");
Expand All @@ -193,7 +193,7 @@ fn init_application_other_python_exists() -> Result<()> {
child.create_dir_all()?;

let pyproject_toml = child.join("pyproject.toml");
let hello_py = child.join("hello.py");
let app_py = child.join("app.py");
let other_py = child.child("foo.py");
other_py.touch()?;

Expand Down Expand Up @@ -223,7 +223,7 @@ fn init_application_other_python_exists() -> Result<()> {
);
});

let hello = fs_err::read_to_string(hello_py)?;
let hello = fs_err::read_to_string(app_py)?;
insta::with_settings!({
filters => context.filters(),
}, {
Expand Down Expand Up @@ -407,15 +407,15 @@ fn init_script() -> Result<()> {
let child = context.temp_dir.child("foo");
child.create_dir_all()?;

let script = child.join("hello.py");
let script = child.join("app.py");

uv_snapshot!(context.filters(), context.init().current_dir(&child).arg("--script").arg("hello.py"), @r###"
uv_snapshot!(context.filters(), context.init().current_dir(&child).arg("--script").arg("app.py"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Initialized script at `hello.py`
Initialized script at `app.py`
"###);

let script = fs_err::read_to_string(&script)?;
Expand All @@ -431,7 +431,7 @@ fn init_script() -> Result<()> {


def main() -> None:
print("Hello from hello.py!")
print("Hello from app.py!")


if __name__ == "__main__":
Expand All @@ -440,11 +440,11 @@ fn init_script() -> Result<()> {
);
});

uv_snapshot!(context.filters(), context.run().current_dir(&child).arg("python").arg("hello.py"), @r###"
uv_snapshot!(context.filters(), context.run().current_dir(&child).arg("python").arg("app.py"), @r###"
success: true
exit_code: 0
----- stdout -----
Hello from hello.py!
Hello from app.py!

----- stderr -----
"###);
Expand Down Expand Up @@ -818,7 +818,7 @@ fn init_application_current_dir() -> Result<()> {
"###);

let pyproject = fs_err::read_to_string(dir.join("pyproject.toml"))?;
let hello_py = fs_err::read_to_string(dir.join("hello.py"))?;
let app_py = fs_err::read_to_string(dir.join("app.py"))?;

insta::with_settings!({
filters => context.filters(),
Expand All @@ -840,7 +840,7 @@ fn init_application_current_dir() -> Result<()> {
filters => context.filters(),
}, {
assert_snapshot!(
hello_py, @r###"
app_py, @r###"
def main():
print("Hello from foo!")

Expand Down
8 changes: 4 additions & 4 deletions docs/concepts/projects/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Applications are the default target for `uv init`, but can also be specified wit
$ uv init example-app
```

The project includes a `pyproject.toml`, a sample file (`hello.py`), a readme, and a Python version
The project includes a `pyproject.toml`, a sample file (`app.py`), a readme, and a Python version
pin file (`.python-version`).

```console
$ tree example-app
example-app
├── .python-version
├── README.md
├── hello.py
├── app.py
└── pyproject.toml
```

Expand All @@ -49,7 +49,7 @@ dependencies = []

The sample file defines a `main` function with some standard boilerplate:

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

Expand All @@ -61,7 +61,7 @@ if __name__ == "__main__":
Python files can be executed with `uv run`:

```console
$ uv run hello.py
$ uv run app.py
Hello from example-project!
```

Expand Down
8 changes: 4 additions & 4 deletions docs/guides/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ uv will create the following files:
.
├── .python-version
├── README.md
├── hello.py
├── app.py
└── pyproject.toml
```

The `hello.py` file contains a simple "Hello world" program. Try it out with `uv run`:
The `app.py` file contains a simple "Hello world" program. Try it out with `uv run`:

```console
$ uv run hello.py
$ uv run app.py
Hello from hello-world!
```

Expand All @@ -53,7 +53,7 @@ A complete listing would look like:
│   └── pyvenv.cfg
├── .python-version
├── README.md
├── hello.py
├── app.py
├── pyproject.toml
└── uv.lock
```
Expand Down
Loading