Skip to content

Commit cef0ebd

Browse files
committed
Rename src.root to environment.root
1 parent cb512ba commit cef0ebd

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
@@ -876,3 +876,123 @@ fn check_conda_prefix_var_to_resolve_path() -> anyhow::Result<()> {
876876

877877
Ok(())
878878
}
879+
880+
#[test]
881+
fn src_root_deprecation_warning() -> anyhow::Result<()> {
882+
let case = CliTest::with_files([
883+
(
884+
"pyproject.toml",
885+
r#"
886+
[tool.ty.src]
887+
root = "./src"
888+
"#,
889+
),
890+
("src/test.py", ""),
891+
])?;
892+
893+
assert_cmd_snapshot!(case.command(), @r#"
894+
success: true
895+
exit_code: 0
896+
----- stdout -----
897+
warning[deprecated-setting]: The `src.root` setting is deprecated. Use `environment.root` instead.
898+
--> pyproject.toml:3:8
899+
|
900+
2 | [tool.ty.src]
901+
3 | root = "./src"
902+
| ^^^^^^^
903+
|
904+
905+
Found 1 diagnostic
906+
907+
----- stderr -----
908+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
909+
"#);
910+
911+
Ok(())
912+
}
913+
914+
#[test]
915+
fn src_root_deprecation_warning_with_environment_root() -> anyhow::Result<()> {
916+
let case = CliTest::with_files([
917+
(
918+
"pyproject.toml",
919+
r#"
920+
[tool.ty.src]
921+
root = "./src"
922+
923+
[tool.ty.environment]
924+
root = "./app"
925+
"#,
926+
),
927+
("app/test.py", ""),
928+
])?;
929+
930+
assert_cmd_snapshot!(case.command(), @r#"
931+
success: true
932+
exit_code: 0
933+
----- stdout -----
934+
warning[deprecated-setting]: The `src.root` setting is deprecated. Use `environment.root` instead.
935+
--> pyproject.toml:3:8
936+
|
937+
2 | [tool.ty.src]
938+
3 | root = "./src"
939+
| ^^^^^^^
940+
4 |
941+
5 | [tool.ty.environment]
942+
|
943+
info: The `src.root` is ignored in favor of the `environment.root` setting
944+
945+
Found 1 diagnostic
946+
947+
----- stderr -----
948+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
949+
"#);
950+
951+
Ok(())
952+
}
953+
954+
#[test]
955+
fn environment_root_takes_precedence_over_src_root() -> anyhow::Result<()> {
956+
let case = CliTest::with_files([
957+
(
958+
"pyproject.toml",
959+
r#"
960+
[tool.ty.src]
961+
root = "./src"
962+
963+
[tool.ty.environment]
964+
root = "./app"
965+
"#,
966+
),
967+
("src/test.py", "import my_module"),
968+
(
969+
"app/my_module.py",
970+
"# This module exists in app/ but not src/",
971+
),
972+
])?;
973+
974+
// The test should pass because environment.root points to ./app where my_module.py exists
975+
// If src.root took precedence, it would fail because my_module.py doesn't exist in ./src
976+
assert_cmd_snapshot!(case.command(), @r#"
977+
success: true
978+
exit_code: 0
979+
----- stdout -----
980+
warning[deprecated-setting]: The `src.root` setting is deprecated. Use `environment.root` instead.
981+
--> pyproject.toml:3:8
982+
|
983+
2 | [tool.ty.src]
984+
3 | root = "./src"
985+
| ^^^^^^^
986+
4 |
987+
5 | [tool.ty.environment]
988+
|
989+
info: The `src.root` is ignored in favor of the `environment.root` setting
990+
991+
Found 1 diagnostic
992+
993+
----- stderr -----
994+
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
995+
"#);
996+
997+
Ok(())
998+
}

0 commit comments

Comments
 (0)