Skip to content

Commit f58a54f

Browse files
ntBreAlexWaygood
andauthored
Move red_knot_python_semantic::PythonVersion to the ruff_python_ast crate (#16147)
## Summary This PR moves the `PythonVersion` struct from the `red_knot_python_semantic` crate to the `ruff_python_ast` crate so that it can be used more easily in the syntax error detection work. Compared to that [prototype](#16090) these changes reduce us from 2 `PythonVersion` structs to 1. This does not unify any of the `PythonVersion` *enums*, but I hope to make some progress on that in a follow-up. ## Test Plan Existing tests, this should not change any external behavior. --------- Co-authored-by: Alex Waygood <[email protected]>
1 parent fa28dc5 commit f58a54f

File tree

27 files changed

+62
-59
lines changed

27 files changed

+62
-59
lines changed

Cargo.lock

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

crates/red_knot/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ red_knot_python_semantic = { workspace = true }
1616
red_knot_project = { workspace = true, features = ["zstd"] }
1717
red_knot_server = { workspace = true }
1818
ruff_db = { workspace = true, features = ["os", "cache"] }
19+
ruff_python_ast = { workspace = true }
1920

2021
anyhow = { workspace = true }
2122
chrono = { workspace = true }

crates/red_knot/src/python_version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl std::fmt::Display for PythonVersion {
4040
}
4141
}
4242

43-
impl From<PythonVersion> for red_knot_python_semantic::PythonVersion {
43+
impl From<PythonVersion> for ruff_python_ast::python_version::PythonVersion {
4444
fn from(value: PythonVersion) -> Self {
4545
match value {
4646
PythonVersion::Py37 => Self::PY37,
@@ -61,8 +61,8 @@ mod tests {
6161
#[test]
6262
fn same_default_as_python_version() {
6363
assert_eq!(
64-
red_knot_python_semantic::PythonVersion::from(PythonVersion::default()),
65-
red_knot_python_semantic::PythonVersion::default()
64+
ruff_python_ast::python_version::PythonVersion::from(PythonVersion::default()),
65+
ruff_python_ast::python_version::PythonVersion::default()
6666
);
6767
}
6868
}

crates/red_knot/tests/file_watching.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ use red_knot_project::metadata::pyproject::{PyProject, Tool};
99
use red_knot_project::metadata::value::{RangedValue, RelativePathBuf};
1010
use red_knot_project::watch::{directory_watcher, ChangeEvent, ProjectWatcher};
1111
use red_knot_project::{Db, ProjectDatabase, ProjectMetadata};
12-
use red_knot_python_semantic::{resolve_module, ModuleName, PythonPlatform, PythonVersion};
12+
use red_knot_python_semantic::{resolve_module, ModuleName, PythonPlatform};
1313
use ruff_db::files::{system_path_to_file, File, FileError};
1414
use ruff_db::source::source_text;
1515
use ruff_db::system::{
1616
OsSystem, System, SystemPath, SystemPathBuf, UserConfigDirectoryOverrideGuard,
1717
};
1818
use ruff_db::Upcast;
19+
use ruff_python_ast::python_version::PythonVersion;
1920

2021
struct TestCase {
2122
db: ProjectDatabase,

crates/red_knot_project/src/combine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::{collections::HashMap, hash::BuildHasher};
22

3-
use red_knot_python_semantic::{PythonPlatform, PythonVersion, SitePackages};
3+
use red_knot_python_semantic::{PythonPlatform, SitePackages};
44
use ruff_db::system::SystemPathBuf;
5+
use ruff_python_ast::python_version::PythonVersion;
56

67
/// Combine two values, preferring the values in `self`.
78
///

crates/red_knot_project/src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ mod tests {
309309
310310
use anyhow::{anyhow, Context};
311311
use insta::assert_ron_snapshot;
312-
use red_knot_python_semantic::PythonVersion;
313312
use ruff_db::system::{SystemPathBuf, TestSystem};
313+
use ruff_python_ast::python_version::PythonVersion;
314314

315315
use crate::{ProjectDiscoveryError, ProjectMetadata};
316316

crates/red_knot_project/src/metadata/options.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::metadata::value::{RangedValue, RelativePathBuf, ValueSource, ValueSourceGuard};
22
use crate::Db;
33
use red_knot_python_semantic::lint::{GetLintError, Level, LintSource, RuleSelection};
4-
use red_knot_python_semantic::{
5-
ProgramSettings, PythonPlatform, PythonVersion, SearchPathSettings, SitePackages,
6-
};
4+
use red_knot_python_semantic::{ProgramSettings, PythonPlatform, SearchPathSettings, SitePackages};
75
use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity, Span};
86
use ruff_db::files::system_path_to_file;
97
use ruff_db::system::{System, SystemPath};
108
use ruff_macros::Combine;
9+
use ruff_python_ast::python_version::PythonVersion;
1110
use rustc_hash::FxHashMap;
1211
use serde::{Deserialize, Serialize};
1312
use std::borrow::Cow;

crates/red_knot_project/src/metadata/pyproject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::metadata::options::Options;
22
use crate::metadata::value::{RangedValue, ValueSource, ValueSourceGuard};
33
use pep440_rs::{release_specifiers_to_ranges, Version, VersionSpecifiers};
4-
use red_knot_python_semantic::PythonVersion;
4+
use ruff_python_ast::python_version::PythonVersion;
55
use serde::{Deserialize, Deserializer, Serialize};
66
use std::collections::Bound;
77
use std::ops::Deref;

crates/red_knot_python_semantic/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub(crate) mod tests {
1919
use std::sync::Arc;
2020

2121
use crate::program::{Program, SearchPathSettings};
22-
use crate::python_version::PythonVersion;
2322
use crate::{default_lint_registry, ProgramSettings, PythonPlatform};
2423

2524
use super::Db;
@@ -29,6 +28,7 @@ pub(crate) mod tests {
2928
use ruff_db::system::{DbWithTestSystem, System, SystemPathBuf, TestSystem};
3029
use ruff_db::vendored::VendoredFileSystem;
3130
use ruff_db::{Db as SourceDb, Upcast};
31+
use ruff_python_ast::python_version::PythonVersion;
3232

3333
#[salsa::db]
3434
#[derive(Clone)]

crates/red_knot_python_semantic/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub use module_name::ModuleName;
99
pub use module_resolver::{resolve_module, system_module_search_paths, KnownModule, Module};
1010
pub use program::{Program, ProgramSettings, SearchPathSettings, SitePackages};
1111
pub use python_platform::PythonPlatform;
12-
pub use python_version::PythonVersion;
1312
pub use semantic_model::{HasType, SemanticModel};
1413

1514
pub mod ast_node_ref;
@@ -20,7 +19,6 @@ mod module_resolver;
2019
mod node_key;
2120
mod program;
2221
mod python_platform;
23-
mod python_version;
2422
pub mod semantic_index;
2523
mod semantic_model;
2624
pub(crate) mod site_packages;

0 commit comments

Comments
 (0)