Skip to content

Commit

Permalink
Remove 'os' feature requirement in red_knot_project
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Feb 7, 2025
1 parent 89e26c5 commit 50e15b4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/red_knot_project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license.workspace = true

[dependencies]
ruff_cache = { workspace = true }
ruff_db = { workspace = true, features = ["os", "cache", "serde"] }
ruff_db = { workspace = true, features = ["cache", "serde"] }
ruff_macros = { workspace = true }
ruff_python_ast = { workspace = true, features = ["serde"] }
ruff_text_size = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_python_semantic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test-case = { workspace = true }
memchr = { workspace = true }

[dev-dependencies]
ruff_db = { workspace = true, features = ["os", "testing"] }
ruff_db = { workspace = true, features = ["testing"] }
ruff_python_parser = { workspace = true }
red_knot_test = { workspace = true }
red_knot_vendored = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = { workspace = true }

[dependencies]
red_knot_project = { workspace = true }
ruff_db = { workspace = true }
ruff_db = { workspace = true, features = ["os"] }
ruff_notebook = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_source_file = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = ["console_error_panic_hook"]
red_knot_python_semantic = { workspace = true }
red_knot_project = { workspace = true, default-features = false, features = ["deflate"] }

ruff_db = { workspace = true, features = [] }
ruff_db = { workspace = true, default-features = false, features = [] }
ruff_notebook = { workspace = true }

console_error_panic_hook = { workspace = true, optional = true }
Expand Down
7 changes: 4 additions & 3 deletions crates/ruff_db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ colored = { workspace = true }
countme = { workspace = true }
dashmap = { workspace = true }
dunce = { workspace = true }
etcetera = { workspace = true, optional = true }
filetime = { workspace = true }
glob = { workspace = true }
ignore = { workspace = true, optional = true }
Expand All @@ -44,14 +43,16 @@ zip = { workspace = true }
[target.'cfg(target_arch="wasm32")'.dependencies]
web-time = { version = "1.1.0" }

[target.'cfg(not(target_arch="wasm32"))'.dependencies]
etcetera = { workspace = true, optional = true }

[dev-dependencies]
insta = { workspace = true }
tempfile = { workspace = true }

[features]
default = ["os"]
cache = ["ruff_cache"]
os = ["ignore", "etcetera"]
os = ["ignore", "dep:etcetera"]
serde = ["dep:serde", "camino/serde1"]
# Exposes testing utilities.
testing = ["tracing-subscriber", "tracing-tree"]
11 changes: 10 additions & 1 deletion crates/ruff_db/src/system/os.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;
use std::{any::Any, path::PathBuf};

use etcetera::BaseStrategy as _;
use filetime::FileTime;

use ruff_notebook::{Notebook, NotebookError};
Expand Down Expand Up @@ -99,11 +98,21 @@ impl System for OsSystem {
&self.inner.cwd
}

#[cfg(not(target_arch = "wasm32"))]
fn user_config_directory(&self) -> Option<SystemPathBuf> {
use etcetera::BaseStrategy as _;

let strategy = etcetera::base_strategy::choose_base_strategy().ok()?;
SystemPathBuf::from_path_buf(strategy.config_dir()).ok()
}

// TODO: Remove this feature gating once `ruff_wasm` no longer depends on `ruff_db` with the
// Os feature enabled.
#[cfg(target_arch = "wasm32")]
fn user_config_directory(&self) -> Option<SystemPathBuf> {
None
}

/// Creates a builder to recursively walk `path`.
///
/// The walker ignores files according to [`ignore::WalkBuilder::standard_filters`]
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_db/src/system/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct TestSystem {
}

impl TestSystem {
/// Returns the [`InMemorySystem`].
/// Returns the `InMemorySystem`.
///
/// ## Panics
/// If this test db isn't the in memory system.
Expand All @@ -35,7 +35,7 @@ impl TestSystem {
.expect("The test db is not using a memory file system")
}

/// Returns the [`InMemorySystem`] or `None` if the test system is using an other underlying system.
/// Returns the `InMemorySystem` or `None` if the test system is using an other underlying system.
pub fn as_in_memory(&self) -> Option<&InMemorySystem> {
self.system().as_any().downcast_ref::<InMemorySystem>()
}
Expand Down

0 comments on commit 50e15b4

Please sign in to comment.