Skip to content

Commit 0194452

Browse files
[ty] Rename src.root setting to environment.root (#18760)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 2c4c015 commit 0194452

7 files changed

Lines changed: 281 additions & 50 deletions

File tree

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,9 @@ pub enum DiagnosticId {
735735
/// # no `[overrides.rules]`
736736
/// ```
737737
UselessOverridesSection,
738+
739+
/// Use of a deprecated setting.
740+
DeprecatedSetting,
738741
}
739742

740743
impl DiagnosticId {
@@ -773,6 +776,7 @@ impl DiagnosticId {
773776
DiagnosticId::EmptyInclude => "empty-include",
774777
DiagnosticId::UnnecessaryOverridesSection => "unnecessary-overrides-section",
775778
DiagnosticId::UselessOverridesSection => "useless-overrides-section",
779+
DiagnosticId::DeprecatedSetting => "deprecated-setting",
776780
}
777781
}
778782

crates/ruff_macros/src/combine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenS
2020
Ok(quote! {
2121
#[automatically_derived]
2222
impl crate::combine::Combine for #ident {
23+
#[allow(deprecated)]
2324
fn combine_with(&mut self, other: Self) {
2425
#(
2526
#output

crates/ty/docs/configuration.md

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty/src/args.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl CheckCommand {
193193
.map(RelativePathBuf::cli)
194194
.collect()
195195
}),
196+
..EnvironmentOptions::default()
196197
}),
197198
terminal: Some(TerminalOptions {
198199
output_format: self

crates/ty/tests/cli/python_environment.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,3 +929,123 @@ fn check_conda_prefix_var_to_resolve_path() -> anyhow::Result<()> {
929929

930930
Ok(())
931931
}
932+
933+
#[test]
934+
fn src_root_deprecation_warning() -> anyhow::Result<()> {
935+
let case = CliTest::with_files([
936+
(
937+
"pyproject.toml",
938+
r#"
939+
[tool.ty.src]
940+
root = "./src"
941+
"#,
942+
),
943+
("src/test.py", ""),
944+
])?;
945+
946+
assert_cmd_snapshot!(case.command(), @r#"
947+
success: true
948+
exit_code: 0
949+
----- stdout -----
950+
warning[deprecated-setting]: The `src.root` setting is deprecated. Use `environment.root` instead.
951+
--> pyproject.toml:3:8
952+
|
953+
2 | [tool.ty.src]
954+
3 | root = "./src"
955+
| ^^^^^^^
956+
|
957+
958+
Found 1 diagnostic
959+
960+
----- stderr -----
961+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
962+
"#);
963+
964+
Ok(())
965+
}
966+
967+
#[test]
968+
fn src_root_deprecation_warning_with_environment_root() -> anyhow::Result<()> {
969+
let case = CliTest::with_files([
970+
(
971+
"pyproject.toml",
972+
r#"
973+
[tool.ty.src]
974+
root = "./src"
975+
976+
[tool.ty.environment]
977+
root = "./app"
978+
"#,
979+
),
980+
("app/test.py", ""),
981+
])?;
982+
983+
assert_cmd_snapshot!(case.command(), @r#"
984+
success: true
985+
exit_code: 0
986+
----- stdout -----
987+
warning[deprecated-setting]: The `src.root` setting is deprecated. Use `environment.root` instead.
988+
--> pyproject.toml:3:8
989+
|
990+
2 | [tool.ty.src]
991+
3 | root = "./src"
992+
| ^^^^^^^
993+
4 |
994+
5 | [tool.ty.environment]
995+
|
996+
info: The `src.root` setting was ignored in favor of the `environment.root` setting
997+
998+
Found 1 diagnostic
999+
1000+
----- stderr -----
1001+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
1002+
"#);
1003+
1004+
Ok(())
1005+
}
1006+
1007+
#[test]
1008+
fn environment_root_takes_precedence_over_src_root() -> anyhow::Result<()> {
1009+
let case = CliTest::with_files([
1010+
(
1011+
"pyproject.toml",
1012+
r#"
1013+
[tool.ty.src]
1014+
root = "./src"
1015+
1016+
[tool.ty.environment]
1017+
root = "./app"
1018+
"#,
1019+
),
1020+
("src/test.py", "import my_module"),
1021+
(
1022+
"app/my_module.py",
1023+
"# This module exists in app/ but not src/",
1024+
),
1025+
])?;
1026+
1027+
// The test should pass because environment.root points to ./app where my_module.py exists
1028+
// If src.root took precedence, it would fail because my_module.py doesn't exist in ./src
1029+
assert_cmd_snapshot!(case.command(), @r#"
1030+
success: true
1031+
exit_code: 0
1032+
----- stdout -----
1033+
warning[deprecated-setting]: The `src.root` setting is deprecated. Use `environment.root` instead.
1034+
--> pyproject.toml:3:8
1035+
|
1036+
2 | [tool.ty.src]
1037+
3 | root = "./src"
1038+
| ^^^^^^^
1039+
4 |
1040+
5 | [tool.ty.environment]
1041+
|
1042+
info: The `src.root` setting was ignored in favor of the `environment.root` setting
1043+
1044+
Found 1 diagnostic
1045+
1046+
----- stderr -----
1047+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
1048+
"#);
1049+
1050+
Ok(())
1051+
}

0 commit comments

Comments
 (0)