-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fallback to requires-python
in certain cases when target-version
is not found
#16319
Changes from 1 commit
7bbda72
186235a
92bc35a
7c2c9b1
812fb20
759c0ba
cc7d0bb
c8c10cd
3c3c812
9fbe52a
4a2d9e1
cd37ed8
7f4403f
3613121
1b52717
e2b30e9
9039594
7e1f777
0d99dba
081518a
3c45426
2a20b69
123006f
513b1c8
5f3ec8c
2d22b76
511129e
ac55239
54acafa
a1a7548
b098255
229e905
6093d74
f5d0203
49a593e
dc26d44
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 |
---|---|---|
|
@@ -6,9 +6,11 @@ use std::sync::Arc; | |
|
||
use anyhow::Context; | ||
use ignore::{WalkBuilder, WalkState}; | ||
use ruff_python_ast::PythonVersion; | ||
|
||
use ruff_linter::settings::types::GlobPath; | ||
use ruff_linter::{settings::types::FilePattern, settings::types::PreviewMode}; | ||
use ruff_workspace::pyproject::find_fallback_target_version; | ||
use ruff_workspace::resolver::match_exclusion; | ||
use ruff_workspace::Settings; | ||
use ruff_workspace::{ | ||
|
@@ -83,8 +85,13 @@ impl RuffSettings { | |
/// Constructs [`RuffSettings`] by merging the editor-defined settings with the | ||
/// default configuration. | ||
fn editor_only(editor_settings: &ResolvedEditorSettings, root: &Path) -> RuffSettings { | ||
let mut config = Configuration::default(); | ||
if let Some(fallback_version) = find_fallback_target_version(root) { | ||
config.target_version = Some(PythonVersion::from(fallback_version)); | ||
}; | ||
|
||
let settings = EditorConfigurationTransformer(editor_settings, root) | ||
.transform(Configuration::default()) | ||
.transform(config) | ||
.into_settings(root) | ||
.expect("editor configuration should merge successfully with default configuration"); | ||
|
||
|
@@ -292,7 +299,10 @@ impl RuffSettingsIndex { | |
} | ||
} | ||
} | ||
Ok(None) => {} | ||
Ok(None) => { | ||
let settings = RuffSettings::editor_only(editor_settings, &directory); | ||
index.write().unwrap().insert(directory, Arc::new(settings)); | ||
} | ||
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. If I'm understanding this change correctly, we'd now have a fallback settings for every directory in the project. I think this might create an unexpected behavior because for a file in a nested directory, it would use this fallback settings instead of the settings from the project root? Let me test this out. 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. Yeah, I tested out, I think this is an incorrect fix. Consider the following directory structure:
The 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's not entirely clear to me why the change here is necessary. Shouldn't the changes above be sufficient? |
||
Err(err) => { | ||
tracing::error!("{err:#}"); | ||
has_error.store(true, Ordering::Relaxed); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean that we'll pick up the
requires-python
constraint even if a user useseditor-only
in their settings. I'd be a bit confused ifeditor-only
loads any project settings. @dhruvmanila what's your take on this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't think we should be looking at any of the config files if the configuration preference is
editorOnly
unless the user has explicitly asks us using theruff.configuration
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we won't have gotten this far in the code in that case, though, right? We exited earlier here:
ruff/crates/ruff_server/src/session/index/ruff_settings.rs
Lines 114 to 123 in dd2313a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That branch will be calling
RuffSettings::editor_only
to create a default configuration so we'll be getting there in this case.