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
This commit is contained in:
Kevin Marchais 2025-01-07 18:07:44 +01:00 committed by GitHub
parent c8b3e8523c
commit a2a2662d43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 10 deletions

View file

@ -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: ...
"};

View file

@ -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: ...
"###
);

View file

@ -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())
```