Skip to content

Commit 1a6640a

Browse files
committed
Some windows annoyance
1 parent 244a469 commit 1a6640a

26 files changed

+421
-376
lines changed

.editorconfig

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ indent_size = 4
1717
trim_trailing_whitespace = false
1818

1919
[*.md]
20-
max_line_length = 100
20+
max_line_length = 100
21+
22+
[*.toml]
23+
indent_size = 4

Cargo.lock

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

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ criterion = { version = "0.5.1", default-features = false }
6666
crossbeam = { version = "0.8.4" }
6767
dashmap = { version = "6.0.1" }
6868
dir-test = { version = "0.3.0" }
69+
dunce = { version = "1.0.5" }
6970
drop_bomb = { version = "0.1.5" }
7071
env_logger = { version = "0.11.0" }
7172
etcetera = { version = "0.8.0" }
@@ -81,7 +82,7 @@ hashbrown = { version = "0.15.0", default-features = false, features = [
8182
ignore = { version = "0.4.22" }
8283
imara-diff = { version = "0.1.5" }
8384
imperative = { version = "1.0.4" }
84-
indexmap = {version = "2.6.0" }
85+
indexmap = { version = "2.6.0" }
8586
indicatif = { version = "0.17.8" }
8687
indoc = { version = "2.0.4" }
8788
insta = { version = "1.35.1" }

crates/red_knot/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tracing-tree = { workspace = true }
3434
[dev-dependencies]
3535
filetime = { workspace = true }
3636
tempfile = { workspace = true }
37+
ruff_db = { workspace = true, features = ["testing"] }
3738

3839
[lints]
3940
workspace = true

crates/red_knot/tests/file_watching.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use red_knot_workspace::workspace::WorkspaceMetadata;
1414
use ruff_db::files::{system_path_to_file, File, FileError};
1515
use ruff_db::source::source_text;
1616
use ruff_db::system::{OsSystem, SystemPath, SystemPathBuf};
17+
use ruff_db::testing::setup_logging;
1718
use ruff_db::Upcast;
1819

1920
struct TestCase {
@@ -203,7 +204,9 @@ where
203204
.as_utf8_path()
204205
.canonicalize_utf8()
205206
.with_context(|| "Failed to canonicalize root path.")?,
206-
);
207+
)
208+
.simplified()
209+
.to_path_buf();
207210

208211
let workspace_path = root_path.join("workspace");
209212

@@ -1351,6 +1354,7 @@ fn nested_packages_delete_root() -> anyhow::Result<()> {
13511354

13521355
#[test]
13531356
fn added_package() -> anyhow::Result<()> {
1357+
let _ = setup_logging();
13541358
let mut case = setup([
13551359
(
13561360
"pyproject.toml",

crates/red_knot_python_semantic/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ thiserror = { workspace = true }
3232
tracing = { workspace = true }
3333
rustc-hash = { workspace = true }
3434
hashbrown = { workspace = true }
35+
serde = { workspace = true, optional = true }
3536
smallvec = { workspace = true }
3637
static_assertions = { workspace = true }
3738
test-case = { workspace = true }

crates/red_knot_python_semantic/src/program.rs

+3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ impl Program {
5454
}
5555

5656
#[derive(Clone, Debug, Eq, PartialEq)]
57+
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
5758
pub struct ProgramSettings {
5859
pub target_version: PythonVersion,
5960
pub search_paths: SearchPathSettings,
6061
}
6162

6263
/// Configures the search paths for module resolution.
6364
#[derive(Eq, PartialEq, Debug, Clone)]
65+
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
6466
pub struct SearchPathSettings {
6567
/// List of user-provided paths that should take first priority in the module resolution.
6668
/// Examples in other type checkers are mypy's MYPYPATH environment variable,
@@ -91,6 +93,7 @@ impl SearchPathSettings {
9193
}
9294

9395
#[derive(Debug, Clone, Eq, PartialEq)]
96+
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
9497
pub enum SitePackages {
9598
Derived {
9699
venv_path: SystemPathBuf,

crates/red_knot_python_semantic/src/python_version.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fmt;
55
/// Unlike the `TargetVersion` enums in the CLI crates,
66
/// this does not necessarily represent a Python version that we actually support.
77
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
89
pub struct PythonVersion {
910
pub major: u8,
1011
pub minor: u8,

crates/red_knot_python_semantic/src/site_packages.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,17 @@ mod tests {
732732
let system = TestSystem::default();
733733
assert!(matches!(
734734
VirtualEnvironment::new("/.venv", &system),
735-
Err(SitePackagesDiscoveryError::VenvDirIsNotADirectory(_))
735+
Err(SitePackagesDiscoveryError::VenvDirCanonicalizationError(..))
736+
));
737+
}
738+
739+
#[test]
740+
fn reject_venv_that_is_not_a_directory() {
741+
let system = TestSystem::default();
742+
system.memory_file_system().write_file("/.venv", "").unwrap();
743+
assert!(matches!(
744+
VirtualEnvironment::new("/.venv", &system),
745+
Err(SitePackagesDiscoveryError::VenvDirIsNotADirectory(..))
736746
));
737747
}
738748

crates/red_knot_wasm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl System for WasmSystem {
226226
}
227227

228228
fn canonicalize_path(&self, path: &SystemPath) -> ruff_db::system::Result<SystemPathBuf> {
229-
Ok(self.fs.canonicalize(path))
229+
self.fs.canonicalize(path)
230230
}
231231

232232
fn read_to_string(&self, path: &SystemPath) -> ruff_db::system::Result<String> {

crates/red_knot_workspace/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ license.workspace = true
1515
red_knot_python_semantic = { workspace = true }
1616

1717
ruff_cache = { workspace = true }
18-
ruff_db = { workspace = true, features = ["os", "cache"] }
19-
ruff_python_ast = { workspace = true }
18+
ruff_db = { workspace = true, features = ["os", "cache", "serde"] }
19+
ruff_python_ast = { workspace = true, features = ["serde"] }
2020
ruff_text_size = { workspace = true }
2121
red_knot_vendored = { workspace = true }
2222

@@ -35,8 +35,9 @@ tracing = { workspace = true }
3535

3636
[dev-dependencies]
3737
ruff_db = { workspace = true, features = ["testing"] }
38-
insta = { workspace = true, features = ["filters"] }
39-
regex = { workspace = true }
38+
red_knot_python_semantic = { workspace = true, features = ["serde"] }
39+
40+
insta = { workspace = true, features = ["filters", "redactions", "ron"] }
4041
tempfile = { workspace = true }
4142

4243
[features]

crates/red_knot_workspace/src/watch/workspace_watcher.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tracing::info;
66
use red_knot_python_semantic::system_module_search_paths;
77
use ruff_cache::{CacheKey, CacheKeyHasher};
88
use ruff_db::system::{SystemPath, SystemPathBuf};
9-
use ruff_db::Upcast;
9+
use ruff_db::{Db as _, Upcast};
1010

1111
use crate::db::{Db, RootDatabase};
1212
use crate::watch::Watcher;
@@ -68,10 +68,9 @@ impl WorkspaceWatcher {
6868

6969
self.has_errored_paths = false;
7070

71-
let workspace_path = workspace_path
72-
.as_utf8_path()
73-
.canonicalize_utf8()
74-
.map(SystemPathBuf::from_utf8_path_buf)
71+
let workspace_path = db
72+
.system()
73+
.canonicalize_path(&workspace_path)
7574
.unwrap_or(workspace_path);
7675

7776
// Find the non-overlapping module search paths and filter out paths that are already covered by the workspace.

0 commit comments

Comments
 (0)