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

Detect imports in src layouts by default #12848

Merged
merged 1 commit into from
Aug 14, 2024
Merged

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Aug 12, 2024

Summary

Occasionally, we receive bug reports that imports in src directories aren't correctly detected. The root of the problem is that we default to src = ["."], so users have to set src = ["src"] explicitly. This PR extends the default to cover both of them: src = [".", "src"].

Closes #12454.

Test Plan

I replicated the structure described in #12453, and verified that the imports were considered sorted, but that adding src = ["."] showed an error.

@charliermarsh charliermarsh added breaking Breaking API change isort Related to import sorting labels Aug 12, 2024
@charliermarsh charliermarsh changed the base branch from main to ruff-0.6 August 12, 2024 17:36
Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the ecosystem tests will provide some test coverage?

Copy link

codspeed-hq bot commented Aug 12, 2024

CodSpeed Performance Report

Merging #12848 will not alter performance

Comparing charlie/src (c936eb8) with ruff-0.6 (f7b1152)

Summary

✅ 32 untouched benchmarks

Copy link
Contributor

github-actions bot commented Aug 13, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+202 -675 violations, +0 -0 fixes in 14 projects; 40 projects unchanged)

DisnakeDev/disnake (+1 -0 violations, +0 -0 fixes)

+ disnake/utils.py:1161:56: RUF101 [*] `PGH001` is a redirect to `S307`

RasaHQ/rasa (+1 -0 violations, +0 -0 fixes)

+ tests/graph_components/validators/test_default_recipe_validator.py:815:72: RUF101 [*] `RUF011` is a redirect to `B035`

Snowflake-Labs/snowcli (+181 -2 violations, +0 -0 fixes)

+ src/snowflake/cli/_app/cli_app.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/commands_registration/command_plugins_loader.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/commands_registration/typer_registration.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/dev/docs/commands_docs_generator.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/dev/docs/generator.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/dev/docs/project_definition_docs_generator.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/loggers.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/main_typer.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/printing.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/snow_connector.py:15:1: I001 [*] Import block is un-sorted or un-formatted
... 173 additional changes omitted for project

PlasmaPy/PlasmaPy (+0 -33 violations, +0 -0 fixes)

- src/plasmapy/analysis/time_series/running_moments.py:61:5: PLR6104 Use `-=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:440:13: PLR6104 Use `/=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:446:13: PLR6104 Use `/=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:777:9: PLR6104 Use `+=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/langmuir.py:1398:5: PLR6104 Use `/=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/langmuir.py:809:9: PLR6104 Use `-=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/thomson.py:199:5: PLR6104 Use `/=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/thomson.py:553:5: PLR6104 Use `/=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/thomson.py:554:5: PLR6104 Use `/=` to perform an augmented assignment directly
- src/plasmapy/diagnostics/thomson.py:933:5: PLR6104 Use `/=` to perform an augmented assignment directly
... 23 additional changes omitted for project

apache/airflow (+0 -44 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-preview --select ALL

- airflow/io/path.py:292:13: PLR6104 Use `/=` to perform an augmented assignment directly
- airflow/io/path.py:294:13: PLR6104 Use `/=` to perform an augmented assignment directly
- airflow/jobs/scheduler_job_runner.py:869:37: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/kubernetes/pre_7_4_0_compatibility/kube_client.py:89:5: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/kubernetes/pre_7_4_0_compatibility/kube_client.py:90:5: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/amazon/aws/hooks/eks.py:546:13: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/amazon/aws/hooks/eks.py:549:13: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/cncf/kubernetes/kube_client.py:90:5: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/cncf/kubernetes/kube_client.py:91:5: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/teradata/transfers/s3_to_teradata.py:106:21: PLR6104 Use `+=` to perform an augmented assignment directly
... 34 additional changes omitted for project

apache/superset (+0 -24 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-preview --select ALL

- scripts/build_docker.py:284:9: PLR6104 Use `+=` to perform an augmented assignment directly
- superset/advanced_data_type/plugins/internet_address.py:93:17: PLR6104 Use `|=` to perform an augmented assignment directly
- superset/common/query_context_processor.py:618:17: PLR6104 Use `+=` to perform an augmented assignment directly
- superset/db_engine_specs/base.py:1156:13: PLR6104 Use `+=` to perform an augmented assignment directly
- superset/migrations/shared/security_converge.py:259:13: PLR6104 Use `+=` to perform an augmented assignment directly
- superset/migrations/shared/security_converge.py:272:17: PLR6104 Use `+=` to perform an augmented assignment directly
- superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:57:17: PLR6104 Use `*=` to perform an augmented assignment directly
- superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:58:17: PLR6104 Use `*=` to perform an augmented assignment directly
- superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:60:17: PLR6104 Use `*=` to perform an augmented assignment directly
- superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:79:17: PLR6104 Use `/=` to perform an augmented assignment directly
... 14 additional changes omitted for project

aws/aws-sam-cli (+0 -128 violations, +0 -0 fixes)

- samcli/commands/_utils/table_print.py:46:9: PLR6104 Use `-=` to perform an augmented assignment directly
- samcli/commands/init/interactive_event_bridge_flow.py:174:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/build/bundler.py:178:13: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/deploy/deployer.py:468:17: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/deploy/deployer.py:820:13: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:27:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:34:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:38:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:42:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:59:9: PLR6104 Use `-=` to perform an augmented assignment directly
... 118 additional changes omitted for project

bokeh/bokeh (+18 -318 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-preview --select ALL

- docs/bokeh/docserver.py:31:1: I001 [*] Import block is un-sorted or un-formatted
- docs/bokeh/source/conf.py:9:1: I001 [*] Import block is un-sorted or un-formatted
- docs/bokeh/source/docs/first_steps/examples/first_steps_5_vectorize_color_and_size.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/advanced/extensions/wrapping.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/advanced/integration/d3-voronoi.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/band.py:11:1: I001 [*] Import block is un-sorted or un-formatted
... 292 additional changes omitted for rule I001
- src/bokeh/resources.py:379:13: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/server/util.py:96:9: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/util/token.py:308:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ tests/integration/models/test_plot.py:27:28: TCH001 Move application import `bokeh.document.Document` into a type-checking block
- tests/integration/models/test_plot.py:27:28: TCH002 Move third-party import `bokeh.document.Document` into a type-checking block
+ tests/integration/tools/test_box_edit_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_box_edit_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/tools/test_box_zoom_tool.py:21:30: TCH001 Move application import `bokeh.core.enums.DimensionsType` into a type-checking block
- tests/integration/tools/test_box_zoom_tool.py:21:30: TCH002 Move third-party import `bokeh.core.enums.DimensionsType` into a type-checking block
+ tests/integration/tools/test_freehand_draw_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_freehand_draw_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/tools/test_pan_tool.py:21:30: TCH001 Move application import `bokeh.core.enums.DimensionsType` into a type-checking block
- tests/integration/tools/test_pan_tool.py:21:30: TCH002 Move third-party import `bokeh.core.enums.DimensionsType` into a type-checking block
... 317 additional changes omitted for project

freedomofpress/securedrop (+0 -1 violations, +0 -0 fixes)

- securedrop/tests/test_journalist.py:1864:9: PLR6104 Use `+=` to perform an augmented assignment directly

ibis-project/ibis (+0 -6 violations, +0 -0 fixes)

- ibis/backends/bigquery/tests/unit/udf/test_usage.py:25:5: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/backends/pandas/executor.py:718:17: PLR6104 Use `&=` to perform an augmented assignment directly
- ibis/common/tests/test_numeric.py:63:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/tests/test_numeric.py:68:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/tests/test_numeric.py:75:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/expr/tests/test_api.py:171:9: PLR6104 Use `+=` to perform an augmented assignment directly

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (5 rules affected)

code total + violation - violation + fix - fix
I001 480 181 299 0 0
PLR6104 358 0 358 0 0
TCH001 18 18 0 0 0
TCH002 18 0 18 0 0
RUF101 3 3 0 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+199 -317 violations, +0 -0 fixes in 2 projects; 52 projects unchanged)

Snowflake-Labs/snowcli (+181 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ src/snowflake/cli/_app/cli_app.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/commands_registration/command_plugins_loader.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/commands_registration/typer_registration.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/dev/docs/commands_docs_generator.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/dev/docs/generator.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/dev/docs/project_definition_docs_generator.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/loggers.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/main_typer.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/printing.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/snow_connector.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_app/telemetry.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_plugins/connection/commands.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_plugins/connection/util.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_plugins/cortex/commands.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_plugins/cortex/manager.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_plugins/git/commands.py:15:1: I001 [*] Import block is un-sorted or un-formatted
+ src/snowflake/cli/_plugins/init/commands.py:15:1: I001 [*] Import block is un-sorted or un-formatted
... 166 additional changes omitted for project

bokeh/bokeh (+18 -315 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- docs/bokeh/docserver.py:31:1: I001 [*] Import block is un-sorted or un-formatted
- docs/bokeh/source/conf.py:9:1: I001 [*] Import block is un-sorted or un-formatted
- docs/bokeh/source/docs/first_steps/examples/first_steps_5_vectorize_color_and_size.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/advanced/extensions/wrapping.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/advanced/integration/d3-voronoi.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/band.py:11:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/colorbar_log.py:9:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/legend.py:9:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/legend_label.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/legend_two_dimensions.py:9:1: I001 [*] Import block is un-sorted or un-formatted
- examples/basic/annotations/legends_item_visibility.py:9:1: I001 [*] Import block is un-sorted or un-formatted
... 287 additional changes omitted for rule I001
+ tests/integration/models/test_plot.py:27:28: TCH001 Move application import `bokeh.document.Document` into a type-checking block
- tests/integration/models/test_plot.py:27:28: TCH002 Move third-party import `bokeh.document.Document` into a type-checking block
+ tests/integration/tools/test_box_edit_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_box_edit_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/tools/test_box_zoom_tool.py:21:30: TCH001 Move application import `bokeh.core.enums.DimensionsType` into a type-checking block
- tests/integration/tools/test_box_zoom_tool.py:21:30: TCH002 Move third-party import `bokeh.core.enums.DimensionsType` into a type-checking block
+ tests/integration/tools/test_freehand_draw_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_freehand_draw_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/tools/test_pan_tool.py:21:30: TCH001 Move application import `bokeh.core.enums.DimensionsType` into a type-checking block
- tests/integration/tools/test_pan_tool.py:21:30: TCH002 Move third-party import `bokeh.core.enums.DimensionsType` into a type-checking block
+ tests/integration/tools/test_point_draw_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_point_draw_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/tools/test_poly_draw_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_poly_draw_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/tools/test_poly_edit_tool.py:24:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/tools/test_poly_edit_tool.py:24:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/widgets/test_autocomplete_input.py:25:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/widgets/test_autocomplete_input.py:25:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/widgets/test_numeric_input.py:21:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
- tests/integration/widgets/test_numeric_input.py:21:49: TCH002 Move third-party import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
+ tests/integration/widgets/test_password_input.py:21:49: TCH001 Move application import `bokeh.application.handlers.function.ModifyDoc` into a type-checking block
... 8 additional changes omitted for rule TCH001
... 301 additional changes omitted for project

Changes by rule (3 rules affected)

code total + violation - violation + fix - fix
I001 480 181 299 0 0
TCH001 18 18 0 0 0
TCH002 18 0 18 0 0

@charliermarsh
Copy link
Member Author

That's a lot of ecosystem changes, though I think they're correct / as-intended.

@charliermarsh
Copy link
Member Author

Well, I guess it's not "a lot of ecosystem changes" -- it's ecosystem changes in two projects, and for projects that are effected, it's a lot of changes.

@MichaReiser
Copy link
Member

Some of the changes also seem to be exclusively about the wording of the diagnostic and not that it is a different diagnostic.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @charliermarsh

Do we also need to change

src: vec![path_dedot::CWD.clone()],

crates/ruff_workspace/src/options.rs Outdated Show resolved Hide resolved
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than @MichaReiser's comments

@charliermarsh charliermarsh force-pushed the charlie/src branch 4 times, most recently from 5ab77ae to b036a38 Compare August 14, 2024 14:48
@charliermarsh charliermarsh merged commit 1be5212 into ruff-0.6 Aug 14, 2024
19 checks passed
@charliermarsh charliermarsh deleted the charlie/src branch August 14, 2024 14:54
@MichaReiser MichaReiser mentioned this pull request Aug 14, 2024
AlexWaygood pushed a commit that referenced this pull request Aug 14, 2024
## Summary

Occasionally, we receive bug reports that imports in `src` directories
aren't correctly detected. The root of the problem is that we default to
`src = ["."]`, so users have to set `src = ["src"]` explicitly. This PR
extends the default to cover _both_ of them: `src = [".", "src"]`.

Closes #12454.

## Test Plan

I replicated the structure described in
#12453, and verified that the
imports were considered sorted, but that adding `src = ["."]` showed an
error.
MichaReiser pushed a commit that referenced this pull request Aug 14, 2024
## Summary

Occasionally, we receive bug reports that imports in `src` directories
aren't correctly detected. The root of the problem is that we default to
`src = ["."]`, so users have to set `src = ["src"]` explicitly. This PR
extends the default to cover _both_ of them: `src = [".", "src"]`.

Closes #12454.

## Test Plan

I replicated the structure described in
#12453, and verified that the
imports were considered sorted, but that adding `src = ["."]` showed an
error.
MichaReiser pushed a commit that referenced this pull request Aug 14, 2024
## Summary

Occasionally, we receive bug reports that imports in `src` directories
aren't correctly detected. The root of the problem is that we default to
`src = ["."]`, so users have to set `src = ["src"]` explicitly. This PR
extends the default to cover _both_ of them: `src = [".", "src"]`.

Closes #12454.

## Test Plan

I replicated the structure described in
#12453, and verified that the
imports were considered sorted, but that adding `src = ["."]` showed an
error.
@NasaGeek
Copy link

NasaGeek commented Aug 26, 2024

Update to FAQ.md at https://github.com/astral-sh/ruff/blob/main/docs/faq.md is merited as a result of this change I think.

Specifically, the following bullet can be removed:

Depending on your project structure, Ruff and isort can differ in their detection of first-party code. (This is often solved by modifying the src property, e.g., to src = ["src"], if your code is nested in a src directory.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking API change isort Related to import sorting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "src" to src default
5 participants