Skip to content

Commit a2a2662

Browse files
authored
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
1 parent c8b3e85 commit a2a2662

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

crates/uv/src/commands/project/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,22 +1055,22 @@ fn generate_package_scripts(
10551055
indoc::formatdoc! {r#"
10561056
from {module_name}._core import hello_from_bin
10571057
1058+
10581059
def hello() -> str:
10591060
return hello_from_bin()
10601061
"#}
10611062
} else {
10621063
indoc::formatdoc! {r#"
10631064
from {module_name}._core import hello_from_bin
10641065
1066+
10651067
def main() -> None:
10661068
print(hello_from_bin())
10671069
"#}
10681070
};
10691071

10701072
// .pyi file for binary script
10711073
let pyi_contents = indoc::indoc! {r"
1072-
from __future__ import annotations
1073-
10741074
def hello_from_bin() -> str: ...
10751075
"};
10761076

crates/uv/tests/it/init.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,7 @@ fn init_app_build_backend_maturin() -> Result<()> {
27642764
init, @r###"
27652765
from foo._core import hello_from_bin
27662766
2767+
27672768
def main() -> None:
27682769
print(hello_from_bin())
27692770
"###
@@ -2776,8 +2777,6 @@ fn init_app_build_backend_maturin() -> Result<()> {
27762777
}, {
27772778
assert_snapshot!(
27782779
pyi_contents, @r###"
2779-
from __future__ import annotations
2780-
27812780
def hello_from_bin() -> str: ...
27822781
"###
27832782
);
@@ -2894,6 +2893,7 @@ fn init_app_build_backend_scikit() -> Result<()> {
28942893
init, @r###"
28952894
from foo._core import hello_from_bin
28962895
2896+
28972897
def main() -> None:
28982898
print(hello_from_bin())
28992899
"###
@@ -2906,8 +2906,6 @@ fn init_app_build_backend_scikit() -> Result<()> {
29062906
}, {
29072907
assert_snapshot!(
29082908
pyi_contents, @r###"
2909-
from __future__ import annotations
2910-
29112909
def hello_from_bin() -> str: ...
29122910
"###
29132911
);
@@ -3017,6 +3015,7 @@ fn init_lib_build_backend_maturin() -> Result<()> {
30173015
init, @r###"
30183016
from foo._core import hello_from_bin
30193017
3018+
30203019
def hello() -> str:
30213020
return hello_from_bin()
30223021
"###
@@ -3029,8 +3028,6 @@ fn init_lib_build_backend_maturin() -> Result<()> {
30293028
}, {
30303029
assert_snapshot!(
30313030
pyi_contents, @r###"
3032-
from __future__ import annotations
3033-
30343031
def hello_from_bin() -> str: ...
30353032
"###
30363033
);
@@ -3144,6 +3141,7 @@ fn init_lib_build_backend_scikit() -> Result<()> {
31443141
init, @r###"
31453142
from foo._core import hello_from_bin
31463143
3144+
31473145
def hello() -> str:
31483146
return hello_from_bin()
31493147
"###
@@ -3156,8 +3154,6 @@ fn init_lib_build_backend_scikit() -> Result<()> {
31563154
}, {
31573155
assert_snapshot!(
31583156
pyi_contents, @r###"
3159-
from __future__ import annotations
3160-
31613157
def hello_from_bin() -> str: ...
31623158
"###
31633159
);

docs/concepts/projects/init.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ And the Python module imports it:
279279
```python title="src/example_ext/__init__.py"
280280
from example_ext._core import hello_from_bin
281281

282+
282283
def main() -> None:
283284
print(hello_from_bin())
284285
```

0 commit comments

Comments
 (0)