-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Allow uv format in unmanaged projects
#15553
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
Changes from all commits
9b6901a
29d1bd6
df90d32
d949171
186ad3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,108 @@ fn format_project() -> Result<()> { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn format_missing_pyproject_toml() -> Result<()> { | ||
| let context = TestContext::new_with_versions(&[]); | ||
|
|
||
| // Create an unformatted Python file | ||
| let main_py = context.temp_dir.child("main.py"); | ||
| main_py.write_str(indoc! {r" | ||
| x = 1 | ||
| "})?; | ||
|
|
||
| uv_snapshot!(context.filters(), context.format(), @r" | ||
| success: true | ||
| exit_code: 0 | ||
| ----- stdout ----- | ||
| 1 file reformatted | ||
|
|
||
| ----- stderr ----- | ||
| warning: `uv format` is experimental and may change without warning. Pass `--preview-features format` to disable this warning. | ||
| "); | ||
|
|
||
| // Check that the file was formatted | ||
| let formatted_content = fs_err::read_to_string(&main_py)?; | ||
| assert_snapshot!(formatted_content, @r" | ||
| x = 1 | ||
| "); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn format_missing_project_in_pyproject_toml() -> Result<()> { | ||
| let context = TestContext::new_with_versions(&[]); | ||
|
|
||
| // Create an empty pyproject.toml with no [project] section | ||
| context.temp_dir.child("pyproject.toml"); | ||
|
|
||
| // Create an unformatted Python file | ||
| let main_py = context.temp_dir.child("main.py"); | ||
| main_py.write_str(indoc! {r" | ||
| x = 1 | ||
| "})?; | ||
|
|
||
| uv_snapshot!(context.filters(), context.format(), @r" | ||
| success: true | ||
| exit_code: 0 | ||
| ----- stdout ----- | ||
| 1 file reformatted | ||
|
|
||
| ----- stderr ----- | ||
| warning: `uv format` is experimental and may change without warning. Pass `--preview-features format` to disable this warning. | ||
| "); | ||
|
|
||
| // Check that the file was formatted | ||
| let formatted_content = fs_err::read_to_string(&main_py)?; | ||
| assert_snapshot!(formatted_content, @r" | ||
| x = 1 | ||
| "); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn format_unmanaged_project() -> Result<()> { | ||
| let context = TestContext::new_with_versions(&[]); | ||
|
|
||
| let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
| pyproject_toml.write_str(indoc! {r#" | ||
| [project] | ||
| name = "project" | ||
| version = "0.1.0" | ||
| requires-python = ">=3.12" | ||
| dependencies = [] | ||
|
|
||
| [tool.uv] | ||
| managed = false | ||
| "#})?; | ||
|
|
||
| // Create an unformatted Python file | ||
| let main_py = context.temp_dir.child("main.py"); | ||
| main_py.write_str(indoc! {r" | ||
| x = 1 | ||
| "})?; | ||
|
|
||
| uv_snapshot!(context.filters(), context.format(), @r" | ||
| success: true | ||
| exit_code: 0 | ||
| ----- stdout ----- | ||
| 1 file reformatted | ||
|
|
||
| ----- stderr ----- | ||
| warning: `uv format` is experimental and may change without warning. Pass `--preview-features format` to disable this warning. | ||
| "); | ||
|
|
||
| // Check that the file was formatted | ||
| let formatted_content = fs_err::read_to_string(&main_py)?; | ||
| assert_snapshot!(formatted_content, @r" | ||
| x = 1 | ||
| "); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn format_from_project_root() -> Result<()> { | ||
| let context = TestContext::new_with_versions(&[]); | ||
|
|
@@ -135,6 +237,50 @@ fn format_relative_project() -> Result<()> { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn format_fails_malformed_pyproject() -> Result<()> { | ||
| let context = TestContext::new_with_versions(&[]); | ||
|
|
||
| let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
| pyproject_toml.write_str("malformed pyproject.toml")?; | ||
|
|
||
| // Create an unformatted Python file | ||
| let main_py = context.temp_dir.child("main.py"); | ||
| main_py.write_str(indoc! {r" | ||
| x = 1 | ||
| "})?; | ||
|
|
||
| uv_snapshot!(context.filters(), context.format(), @r" | ||
| success: false | ||
| exit_code: 2 | ||
| ----- stdout ----- | ||
|
|
||
| ----- stderr ----- | ||
| warning: Failed to parse `pyproject.toml` during settings discovery: | ||
| TOML parse error at line 1, column 11 | ||
| | | ||
| 1 | malformed pyproject.toml | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is weird that this error is reported twice... But I see this same happens in other failing tests, is this intended?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the second parse error from ruff?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, from the err propagation at
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would presume the first one is when we load global settings? It seems problematic, but out of scope for fixing here if there are other snapshots with the same problem.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay! I'll debug that later and if I found which is the origi, I'll create an issue for it! (ping me if you create it first) |
||
| | ^ | ||
| key with no value, expected `=` | ||
|
|
||
| warning: `uv format` is experimental and may change without warning. Pass `--preview-features format` to disable this warning. | ||
| error: Failed to parse: `pyproject.toml` | ||
| Caused by: TOML parse error at line 1, column 11 | ||
| | | ||
| 1 | malformed pyproject.toml | ||
| | ^ | ||
| key with no value, expected `=` | ||
| "); | ||
|
|
||
| // Check that the file is not formatted | ||
| let formatted_content = fs_err::read_to_string(&main_py)?; | ||
| assert_snapshot!(formatted_content, @r" | ||
| x = 1 | ||
| "); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn format_check() -> Result<()> { | ||
| let context = TestContext::new_with_versions(&[]); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.