From a2a2662d43df593b7eb0fd38cc65706de9a58844 Mon Sep 17 00:00:00 2001 From: Kevin Marchais Date: Tue, 7 Jan 2025 18:07:44 +0100 Subject: [PATCH] Fix ruff linting warnings from generated template files for extension modules (#10371) ## Summary This PR fixes two ruff linting issues in the generated template files when using: `uv init --build-backend` for extension modules. 1. Removes unnecessary `from __future__ import annotations` imports from generated .pyi files ([PYI044](https://docs.astral.sh/ruff/rules/future-annotations-in-stub/)) 2. Adds missing blank line after `hello_from_bin` import to comply with isort formatting ([I001](https://docs.astral.sh/ruff/rules/unsorted-imports/)) ## Test Plan ```bash cargo run -- init --build-backend scikit-build-core example-ext uvx ruff check example-ext --select ALL cargo run -- init --build-backend maturin example-ext uvx ruff check example-ext --select ALL ``` ## Remaining warnings There are still warnings remainings in the generated `__init__.py` files: - [D104](https://docs.astral.sh/ruff/rules/undocumented-public-package/) Missing docstring in public package - [D103](https://docs.astral.sh/ruff/rules/undocumented-public-function/) Missing docstring in public function - [T201](https://docs.astral.sh/ruff/rules/print/) `print` found --- crates/uv/src/commands/project/init.rs | 4 ++-- crates/uv/tests/it/init.rs | 12 ++++-------- docs/concepts/projects/init.md | 1 + 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/uv/src/commands/project/init.rs b/crates/uv/src/commands/project/init.rs index 88e33a41b..faa330249 100644 --- a/crates/uv/src/commands/project/init.rs +++ b/crates/uv/src/commands/project/init.rs @@ -1055,6 +1055,7 @@ fn generate_package_scripts( indoc::formatdoc! {r#" from {module_name}._core import hello_from_bin + def hello() -> str: return hello_from_bin() "#} @@ -1062,6 +1063,7 @@ fn generate_package_scripts( indoc::formatdoc! {r#" from {module_name}._core import hello_from_bin + def main() -> None: print(hello_from_bin()) "#} @@ -1069,8 +1071,6 @@ fn generate_package_scripts( // .pyi file for binary script let pyi_contents = indoc::indoc! {r" - from __future__ import annotations - def hello_from_bin() -> str: ... "}; diff --git a/crates/uv/tests/it/init.rs b/crates/uv/tests/it/init.rs index 969aa8d3a..9157d2f67 100644 --- a/crates/uv/tests/it/init.rs +++ b/crates/uv/tests/it/init.rs @@ -2764,6 +2764,7 @@ fn init_app_build_backend_maturin() -> Result<()> { init, @r###" from foo._core import hello_from_bin + def main() -> None: print(hello_from_bin()) "### @@ -2776,8 +2777,6 @@ fn init_app_build_backend_maturin() -> Result<()> { }, { assert_snapshot!( pyi_contents, @r###" - from __future__ import annotations - def hello_from_bin() -> str: ... "### ); @@ -2894,6 +2893,7 @@ fn init_app_build_backend_scikit() -> Result<()> { init, @r###" from foo._core import hello_from_bin + def main() -> None: print(hello_from_bin()) "### @@ -2906,8 +2906,6 @@ fn init_app_build_backend_scikit() -> Result<()> { }, { assert_snapshot!( pyi_contents, @r###" - from __future__ import annotations - def hello_from_bin() -> str: ... "### ); @@ -3017,6 +3015,7 @@ fn init_lib_build_backend_maturin() -> Result<()> { init, @r###" from foo._core import hello_from_bin + def hello() -> str: return hello_from_bin() "### @@ -3029,8 +3028,6 @@ fn init_lib_build_backend_maturin() -> Result<()> { }, { assert_snapshot!( pyi_contents, @r###" - from __future__ import annotations - def hello_from_bin() -> str: ... "### ); @@ -3144,6 +3141,7 @@ fn init_lib_build_backend_scikit() -> Result<()> { init, @r###" from foo._core import hello_from_bin + def hello() -> str: return hello_from_bin() "### @@ -3156,8 +3154,6 @@ fn init_lib_build_backend_scikit() -> Result<()> { }, { assert_snapshot!( pyi_contents, @r###" - from __future__ import annotations - def hello_from_bin() -> str: ... "### ); diff --git a/docs/concepts/projects/init.md b/docs/concepts/projects/init.md index 30c4ee4ba..a237af7f5 100644 --- a/docs/concepts/projects/init.md +++ b/docs/concepts/projects/init.md @@ -279,6 +279,7 @@ And the Python module imports it: ```python title="src/example_ext/__init__.py" from example_ext._core import hello_from_bin + def main() -> None: print(hello_from_bin()) ```