Skip to content

Commit 7e0ef53

Browse files
committed
Merge branch 'main' into alex/eager-scopes
* main: add diagnostic `Span` (couples `File` and `TextRange`) (#16101) Remove `Hash` and `Eq` from `AstNodeRef` for types not implementing `Eq` or `Hash` (#16100) Fix release build warning about unused todo type message (#16102) [`pydocstyle`] Handle arguments with the same names as sections (`D417`) (#16011) [red-knot] Reduce usage of `From<Type>` implementations when working with `Symbol`s (#16076) Transition to salsa coarse-grained tracked structs (#15763) [`pyupgrade`] Handle micro version numbers correctly (`UP036`) (#16091) [red-knot] `T | object == object` (#16088) [`ruff`] Skip singleton starred expressions for `incorrectly-parenthesized-tuple-in-subscript` (`RUF031`) (#16083) Delete left-over `verbosity.rs (#16081) [red-knot] User-level configuration (#16021) Add `user_configuration_directory` to `System` (#16020)
2 parents 54efbbe + 6e34f74 commit 7e0ef53

File tree

73 files changed

+1437
-690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1437
-690
lines changed

Cargo.lock

+15-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ rayon = { version = "1.10.0" }
123123
regex = { version = "1.10.2" }
124124
rustc-hash = { version = "2.0.0" }
125125
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
126-
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "88a1d7774d78f048fbd77d40abca9ebd729fd1f0" }
126+
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "351d9cf0037be949d17800d0c7b4838e533c2ed6" }
127127
schemars = { version = "0.8.16" }
128128
seahash = { version = "4.1.0" }
129129
serde = { version = "1.0.197", features = ["derive"] }

crates/red_knot/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use salsa::plumbing::ZalsaDatabase;
2222
mod args;
2323
mod logging;
2424
mod python_version;
25-
mod verbosity;
2625
mod version;
2726

2827
#[allow(clippy::print_stdout, clippy::unnecessary_wraps, clippy::print_stderr)]
@@ -99,10 +98,11 @@ fn run_check(args: CheckCommand) -> anyhow::Result<ExitStatus> {
9998
let exit_zero = args.exit_zero;
10099

101100
let cli_options = args.into_options();
102-
let mut workspace_metadata = ProjectMetadata::discover(system.current_directory(), &system)?;
103-
workspace_metadata.apply_cli_options(cli_options.clone());
101+
let mut project_metadata = ProjectMetadata::discover(system.current_directory(), &system)?;
102+
project_metadata.apply_cli_options(cli_options.clone());
103+
project_metadata.apply_configuration_files(&system)?;
104104

105-
let mut db = ProjectDatabase::new(workspace_metadata, system)?;
105+
let mut db = ProjectDatabase::new(project_metadata, system)?;
106106

107107
let (main_loop, main_loop_cancellation_token) = MainLoop::new(cli_options);
108108

crates/red_knot/src/verbosity.rs

-1
This file was deleted.

crates/red_knot/tests/cli.rs

+107-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn cli_arguments_are_relative_to_the_current_directory() -> anyhow::Result<()> {
9898
])?;
9999

100100
// Make sure that the CLI fails when the `libs` directory is not in the search path.
101-
assert_cmd_snapshot!(case.command().current_dir(case.project_dir().join("child")), @r###"
101+
assert_cmd_snapshot!(case.command().current_dir(case.root().join("child")), @r###"
102102
success: false
103103
exit_code: 1
104104
----- stdout -----
@@ -115,7 +115,7 @@ fn cli_arguments_are_relative_to_the_current_directory() -> anyhow::Result<()> {
115115
----- stderr -----
116116
"###);
117117

118-
assert_cmd_snapshot!(case.command().current_dir(case.project_dir().join("child")).arg("--extra-search-path").arg("../libs"), @r"
118+
assert_cmd_snapshot!(case.command().current_dir(case.root().join("child")).arg("--extra-search-path").arg("../libs"), @r"
119119
success: true
120120
exit_code: 0
121121
----- stdout -----
@@ -167,7 +167,7 @@ fn paths_in_configuration_files_are_relative_to_the_project_root() -> anyhow::Re
167167
),
168168
])?;
169169

170-
assert_cmd_snapshot!(case.command().current_dir(case.project_dir().join("child")), @r"
170+
assert_cmd_snapshot!(case.command().current_dir(case.root().join("child")), @r"
171171
success: true
172172
exit_code: 0
173173
----- stdout -----
@@ -717,6 +717,109 @@ fn exit_code_exit_zero_is_true() -> anyhow::Result<()> {
717717
Ok(())
718718
}
719719

720+
#[test]
721+
fn user_configuration() -> anyhow::Result<()> {
722+
let case = TestCase::with_files([
723+
(
724+
"project/knot.toml",
725+
r#"
726+
[rules]
727+
division-by-zero = "warn"
728+
"#,
729+
),
730+
(
731+
"project/main.py",
732+
r#"
733+
y = 4 / 0
734+
735+
for a in range(0, y):
736+
x = a
737+
738+
print(x)
739+
"#,
740+
),
741+
])?;
742+
743+
let config_directory = case.root().join("home/.config");
744+
let config_env_var = if cfg!(windows) {
745+
"APPDATA"
746+
} else {
747+
"XDG_CONFIG_HOME"
748+
};
749+
750+
assert_cmd_snapshot!(
751+
case.command().current_dir(case.root().join("project")).env(config_env_var, config_directory.as_os_str()),
752+
@r###"
753+
success: true
754+
exit_code: 0
755+
----- stdout -----
756+
warning: lint:division-by-zero
757+
--> <temp_dir>/project/main.py:2:5
758+
|
759+
2 | y = 4 / 0
760+
| ----- Cannot divide object of type `Literal[4]` by zero
761+
3 |
762+
4 | for a in range(0, y):
763+
|
764+
765+
warning: lint:possibly-unresolved-reference
766+
--> <temp_dir>/project/main.py:7:7
767+
|
768+
5 | x = a
769+
6 |
770+
7 | print(x)
771+
| - Name `x` used when possibly not defined
772+
|
773+
774+
775+
----- stderr -----
776+
"###
777+
);
778+
779+
// The user-level configuration promotes `possibly-unresolved-reference` to an error.
780+
// Changing the level for `division-by-zero` has no effect, because the project-level configuration
781+
// has higher precedence.
782+
case.write_file(
783+
config_directory.join("knot/knot.toml"),
784+
r#"
785+
[rules]
786+
division-by-zero = "error"
787+
possibly-unresolved-reference = "error"
788+
"#,
789+
)?;
790+
791+
assert_cmd_snapshot!(
792+
case.command().current_dir(case.root().join("project")).env(config_env_var, config_directory.as_os_str()),
793+
@r###"
794+
success: false
795+
exit_code: 1
796+
----- stdout -----
797+
warning: lint:division-by-zero
798+
--> <temp_dir>/project/main.py:2:5
799+
|
800+
2 | y = 4 / 0
801+
| ----- Cannot divide object of type `Literal[4]` by zero
802+
3 |
803+
4 | for a in range(0, y):
804+
|
805+
806+
error: lint:possibly-unresolved-reference
807+
--> <temp_dir>/project/main.py:7:7
808+
|
809+
5 | x = a
810+
6 |
811+
7 | print(x)
812+
| ^ Name `x` used when possibly not defined
813+
|
814+
815+
816+
----- stderr -----
817+
"###
818+
);
819+
820+
Ok(())
821+
}
822+
720823
struct TestCase {
721824
_temp_dir: TempDir,
722825
_settings_scope: SettingsBindDropGuard,
@@ -784,7 +887,7 @@ impl TestCase {
784887
Ok(())
785888
}
786889

787-
fn project_dir(&self) -> &Path {
890+
fn root(&self) -> &Path {
788891
&self.project_dir
789892
}
790893

0 commit comments

Comments
 (0)