Skip to content

Commit 8ea3e35

Browse files
committed
move red_knot_python_semantic::PythonVersion to ruff_db
1 parent 6394094 commit 8ea3e35

File tree

26 files changed

+61
-78
lines changed

26 files changed

+61
-78
lines changed

Cargo.lock

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

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_db::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_db::python_version::PythonVersion::from(PythonVersion::default()),
65+
ruff_db::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,8 +9,9 @@ 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};
14+
use ruff_db::python_version::PythonVersion;
1415
use ruff_db::source::source_text;
1516
use ruff_db::system::{
1617
OsSystem, System, SystemPath, SystemPathBuf, UserConfigDirectoryOverrideGuard,

crates/red_knot_project/src/combine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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};
4+
use ruff_db::python_version::PythonVersion;
45
use ruff_db::system::SystemPathBuf;
56

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

crates/red_knot_project/src/metadata/options.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
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;
7+
use ruff_db::python_version::PythonVersion;
98
use ruff_db::system::{System, SystemPath};
109
use ruff_macros::Combine;
1110
use rustc_hash::FxHashMap;

crates/red_knot_python_semantic/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ 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;
2625
use crate::lint::{LintRegistry, RuleSelection};
2726
use anyhow::Context;
2827
use ruff_db::files::{File, Files};
28+
use ruff_db::python_version::PythonVersion;
2929
use ruff_db::system::{DbWithTestSystem, System, SystemPathBuf, TestSystem};
3030
use ruff_db::vendored::VendoredFileSystem;
3131
use ruff_db::{Db as SourceDb, Upcast};

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;

crates/red_knot_python_semantic/src/module_resolver/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,11 @@ impl PartialEq<SearchPath> for VendoredPathBuf {
630630

631631
#[cfg(test)]
632632
mod tests {
633+
use ruff_db::python_version::PythonVersion;
633634
use ruff_db::Db;
634635

635636
use crate::db::tests::TestDb;
636637
use crate::module_resolver::testing::{FileSpec, MockedTypeshed, TestCase, TestCaseBuilder};
637-
use crate::python_version::PythonVersion;
638638

639639
use super::*;
640640

crates/red_knot_python_semantic/src/module_resolver/resolver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use std::iter::FusedIterator;
44
use rustc_hash::{FxBuildHasher, FxHashSet};
55

66
use ruff_db::files::{File, FilePath, FileRootKind};
7+
use ruff_db::python_version::PythonVersion;
78
use ruff_db::system::{DirectoryEntry, System, SystemPath, SystemPathBuf};
89
use ruff_db::vendored::{VendoredFileSystem, VendoredPath};
910

1011
use crate::db::Db;
1112
use crate::module_name::ModuleName;
1213
use crate::module_resolver::typeshed::{vendored_typeshed_versions, TypeshedVersions};
1314
use crate::site_packages::VirtualEnvironment;
14-
use crate::{Program, PythonVersion, SearchPathSettings, SitePackages};
15+
use crate::{Program, SearchPathSettings, SitePackages};
1516

1617
use super::module::{Module, ModuleKind};
1718
use super::path::{ModulePath, SearchPath, SearchPathValidationError};
@@ -719,6 +720,7 @@ impl<'db> ResolverContext<'db> {
719720
#[cfg(test)]
720721
mod tests {
721722
use ruff_db::files::{system_path_to_file, File, FilePath};
723+
use ruff_db::python_version::PythonVersion;
722724
use ruff_db::system::DbWithTestSystem;
723725
use ruff_db::testing::{
724726
assert_const_function_query_was_not_run, assert_function_query_was_not_run,
@@ -729,7 +731,6 @@ mod tests {
729731
use crate::module_name::ModuleName;
730732
use crate::module_resolver::module::ModuleKind;
731733
use crate::module_resolver::testing::{FileSpec, MockedTypeshed, TestCase, TestCaseBuilder};
732-
use crate::PythonVersion;
733734
use crate::{ProgramSettings, PythonPlatform};
734735

735736
use super::*;

crates/red_knot_python_semantic/src/module_resolver/testing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use ruff_db::python_version::PythonVersion;
12
use ruff_db::system::{DbWithTestSystem, SystemPath, SystemPathBuf};
23
use ruff_db::vendored::VendoredPathBuf;
34

45
use crate::db::tests::TestDb;
56
use crate::program::{Program, SearchPathSettings};
6-
use crate::python_version::PythonVersion;
77
use crate::{ProgramSettings, PythonPlatform, SitePackages};
88

99
/// A test case for the module resolver.

crates/red_knot_python_semantic/src/module_resolver/typeshed.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use std::num::{NonZeroU16, NonZeroUsize};
44
use std::ops::{RangeFrom, RangeInclusive};
55
use std::str::FromStr;
66

7+
use ruff_db::python_version::PythonVersion;
78
use rustc_hash::FxHashMap;
89

910
use crate::db::Db;
1011
use crate::module_name::ModuleName;
11-
use crate::{Program, PythonVersion};
12+
use crate::Program;
1213

1314
pub(in crate::module_resolver) fn vendored_typeshed_versions(db: &dyn Db) -> TypeshedVersions {
1415
TypeshedVersions::from_str(
@@ -278,12 +279,12 @@ impl FromStr for PyVersionRange {
278279
let mut parts = s.split('-').map(str::trim);
279280
match (parts.next(), parts.next(), parts.next()) {
280281
(Some(lower), Some(""), None) => {
281-
let lower = PythonVersion::from_versions_file_string(lower)?;
282+
let lower = python_version_from_versions_file_string(lower)?;
282283
Ok(Self::AvailableFrom(lower..))
283284
}
284285
(Some(lower), Some(upper), None) => {
285-
let lower = PythonVersion::from_versions_file_string(lower)?;
286-
let upper = PythonVersion::from_versions_file_string(upper)?;
286+
let lower = python_version_from_versions_file_string(lower)?;
287+
let upper = python_version_from_versions_file_string(upper)?;
287288
Ok(Self::AvailableWithin(lower..=upper))
288289
}
289290
_ => Err(TypeshedVersionsParseErrorKind::UnexpectedNumberOfHyphens),
@@ -302,21 +303,21 @@ impl fmt::Display for PyVersionRange {
302303
}
303304
}
304305

305-
impl PythonVersion {
306-
fn from_versions_file_string(s: &str) -> Result<Self, TypeshedVersionsParseErrorKind> {
307-
let mut parts = s.split('.').map(str::trim);
308-
let (Some(major), Some(minor), None) = (parts.next(), parts.next(), parts.next()) else {
309-
return Err(TypeshedVersionsParseErrorKind::UnexpectedNumberOfPeriods(
310-
s.to_string(),
311-
));
312-
};
313-
PythonVersion::try_from((major, minor)).map_err(|int_parse_error| {
314-
TypeshedVersionsParseErrorKind::IntegerParsingFailure {
315-
version: s.to_string(),
316-
err: int_parse_error,
317-
}
318-
})
319-
}
306+
fn python_version_from_versions_file_string(
307+
s: &str,
308+
) -> Result<PythonVersion, TypeshedVersionsParseErrorKind> {
309+
let mut parts = s.split('.').map(str::trim);
310+
let (Some(major), Some(minor), None) = (parts.next(), parts.next(), parts.next()) else {
311+
return Err(TypeshedVersionsParseErrorKind::UnexpectedNumberOfPeriods(
312+
s.to_string(),
313+
));
314+
};
315+
PythonVersion::try_from((major, minor)).map_err(|int_parse_error| {
316+
TypeshedVersionsParseErrorKind::IntegerParsingFailure {
317+
version: s.to_string(),
318+
err: int_parse_error,
319+
}
320+
})
320321
}
321322

322323
#[cfg(test)]

crates/red_knot_python_semantic/src/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::module_resolver::SearchPaths;
22
use crate::python_platform::PythonPlatform;
3-
use crate::python_version::PythonVersion;
43
use crate::Db;
54

65
use anyhow::Context;
6+
use ruff_db::python_version::PythonVersion;
77
use ruff_db::system::{SystemPath, SystemPathBuf};
88
use salsa::Durability;
99
use salsa::Setter;

crates/red_knot_python_semantic/src/site_packages.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use std::io;
1313
use std::num::NonZeroUsize;
1414
use std::ops::Deref;
1515

16+
use ruff_db::python_version::PythonVersion;
1617
use ruff_db::system::{System, SystemPath, SystemPathBuf};
1718

18-
use crate::PythonVersion;
19-
2019
type SitePackagesDiscoveryResult<T> = Result<T, SitePackagesDiscoveryError>;
2120

2221
/// Abstraction for a Python virtual environment.

crates/red_knot_python_semantic/src/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use indexmap::IndexSet;
77
use itertools::Itertools;
88
use ruff_db::diagnostic::Severity;
99
use ruff_db::files::File;
10+
use ruff_db::python_version::PythonVersion;
1011
use ruff_python_ast as ast;
1112
use type_ordering::union_elements_ordering;
1213

@@ -44,7 +45,7 @@ use crate::types::diagnostic::INVALID_TYPE_FORM;
4445
use crate::types::infer::infer_unpack_types;
4546
use crate::types::mro::{Mro, MroError, MroIterator};
4647
use crate::types::narrow::narrowing_constraint;
47-
use crate::{Db, FxOrderSet, Module, Program, PythonVersion};
48+
use crate::{Db, FxOrderSet, Module, Program};
4849

4950
mod builder;
5051
mod call;
@@ -4860,9 +4861,9 @@ pub(crate) mod tests {
48604861
use super::*;
48614862
use crate::db::tests::{setup_db, TestDbBuilder};
48624863
use crate::stdlib::typing_symbol;
4863-
use crate::PythonVersion;
48644864
use ruff_db::files::system_path_to_file;
48654865
use ruff_db::parsed::parsed_module;
4866+
use ruff_db::python_version::PythonVersion;
48664867
use ruff_db::system::DbWithTestSystem;
48674868
use ruff_db::testing::assert_function_query_was_not_run;
48684869
use ruff_python_ast as ast;

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl<'db> TypeInferenceBuilder<'db> {
430430
region,
431431
deferred_state: DeferredExpressionState::None,
432432
types: TypeInference::empty(scope),
433-
syntax_checker: SyntaxChecker::new(target_version.into()),
433+
syntax_checker: SyntaxChecker::new(target_version),
434434
}
435435
}
436436

crates/red_knot_test/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
//! ```
1010
1111
use anyhow::Context;
12-
use red_knot_python_semantic::{PythonPlatform, PythonVersion};
12+
use red_knot_python_semantic::PythonPlatform;
13+
use ruff_db::python_version::PythonVersion;
1314
use serde::Deserialize;
1415

1516
#[derive(Deserialize, Debug, Default, Clone)]

crates/red_knot_test/src/db.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use std::sync::Arc;
33
use red_knot_python_semantic::lint::{LintRegistry, RuleSelection};
44
use red_knot_python_semantic::{
55
default_lint_registry, Db as SemanticDb, Program, ProgramSettings, PythonPlatform,
6-
PythonVersion, SearchPathSettings,
6+
SearchPathSettings,
77
};
88
use ruff_db::files::{File, Files};
9+
use ruff_db::python_version::PythonVersion;
910
use ruff_db::system::{DbWithTestSystem, System, SystemPath, SystemPathBuf, TestSystem};
1011
use ruff_db::vendored::VendoredFileSystem;
1112
use ruff_db::{Db as SourceDb, Upcast};

crates/red_knot_wasm/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub enum PythonVersion {
196196
Py313,
197197
}
198198

199-
impl From<PythonVersion> for red_knot_python_semantic::PythonVersion {
199+
impl From<PythonVersion> for ruff_db::python_version::PythonVersion {
200200
fn from(value: PythonVersion) -> Self {
201201
match value {
202202
PythonVersion::Py37 => Self::PY37,
@@ -306,8 +306,8 @@ mod tests {
306306
#[test]
307307
fn same_default_as_python_version() {
308308
assert_eq!(
309-
red_knot_python_semantic::PythonVersion::from(PythonVersion::default()),
310-
red_knot_python_semantic::PythonVersion::default()
309+
ruff_db::python_version::PythonVersion::from(PythonVersion::default()),
310+
ruff_db::python_version::PythonVersion::default()
311311
);
312312
}
313313
}

crates/ruff_benchmark/benches/red_knot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use red_knot_project::metadata::options::{EnvironmentOptions, Options};
88
use red_knot_project::metadata::value::RangedValue;
99
use red_knot_project::watch::{ChangeEvent, ChangedKind};
1010
use red_knot_project::{Db, ProjectDatabase, ProjectMetadata};
11-
use red_knot_python_semantic::PythonVersion;
1211
use ruff_benchmark::criterion::{criterion_group, criterion_main, BatchSize, Criterion};
1312
use ruff_benchmark::TestFile;
1413
use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity};
1514
use ruff_db::files::{system_path_to_file, File};
15+
use ruff_db::python_version::PythonVersion;
1616
use ruff_db::source::source_text;
1717
use ruff_db::system::{MemoryFileSystem, SystemPath, SystemPathBuf, TestSystem};
1818
use rustc_hash::FxHashSet;

crates/ruff_db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod file_revision;
1212
pub mod files;
1313
pub mod panic;
1414
pub mod parsed;
15+
pub mod python_version;
1516
pub mod source;
1617
pub mod system;
1718
#[cfg(feature = "testing")]

crates/red_knot_python_semantic/src/python_version.rs renamed to crates/ruff_db/src/python_version.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ impl From<(u8, u8)> for PythonVersion {
7575
}
7676
}
7777

78-
impl From<PythonVersion> for ruff_python_syntax_errors::PythonVersion {
79-
fn from(value: PythonVersion) -> Self {
80-
Self {
81-
major: value.major,
82-
minor: value.minor,
83-
}
84-
}
85-
}
86-
8778
impl fmt::Display for PythonVersion {
8879
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8980
let PythonVersion { major, minor } = self;
@@ -93,7 +84,7 @@ impl fmt::Display for PythonVersion {
9384

9485
#[cfg(feature = "serde")]
9586
mod serde {
96-
use crate::PythonVersion;
87+
use super::PythonVersion;
9788

9889
impl<'de> serde::Deserialize<'de> for PythonVersion {
9990
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>

crates/ruff_graph/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use zip::CompressionMethod;
44

55
use red_knot_python_semantic::lint::{LintRegistry, RuleSelection};
66
use red_knot_python_semantic::{
7-
default_lint_registry, Db, Program, ProgramSettings, PythonPlatform, PythonVersion,
8-
SearchPathSettings,
7+
default_lint_registry, Db, Program, ProgramSettings, PythonPlatform, SearchPathSettings,
98
};
109
use ruff_db::files::{File, Files};
10+
use ruff_db::python_version::PythonVersion;
1111
use ruff_db::system::{OsSystem, System, SystemPathBuf};
1212
use ruff_db::vendored::{VendoredFileSystem, VendoredFileSystemBuilder};
1313
use ruff_db::{Db as SourceDb, Upcast};

crates/ruff_linter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ license = { workspace = true }
1515
[dependencies]
1616
ruff_annotate_snippets = { workspace = true }
1717
ruff_cache = { workspace = true }
18+
ruff_db = { workspace = true }
1819
ruff_diagnostics = { workspace = true, features = ["serde"] }
1920
ruff_index = { workspace = true }
2021
ruff_notebook = { workspace = true }

0 commit comments

Comments
 (0)