Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot]: Add a VendoredFileSystem implementation #11863

Merged
merged 43 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
41a1aff
Refactor `file` and `vendored` methods and make them standalone funct…
MichaReiser Jun 10, 2024
d3c8e83
Make `file_system_path_to_file` return an Option
MichaReiser Jun 10, 2024
1a69745
Improve documentation, rewrite inline comment, rename `file_system_pa…
MichaReiser Jun 13, 2024
43fa7bf
Update crates/ruff_db/src/vfs.rs
MichaReiser Jun 13, 2024
b054315
Don't use non-platform agnostic `is_absolute` method
MichaReiser Jun 13, 2024
383691e
Add `ModuleName` struct with tests
MichaReiser Jun 10, 2024
5a1da62
Module resolver
MichaReiser Jun 10, 2024
01041cd
Port module resolver to salsa
MichaReiser Jun 11, 2024
f16c045
Add `remove_file` and `remove_directory` tests
MichaReiser Jun 11, 2024
56f2caf
Suppress warning about unused `Os` file system that are only used on …
MichaReiser Jun 11, 2024
bcaea19
Change `ModuleName::new` to return an `Option`
MichaReiser Jun 13, 2024
4df3bea
Use `touch` over `set_permission` and `set_revision` in Tests
MichaReiser Jun 13, 2024
4441c9e
[red-knot]: Add a `VendoredFileSystem` implementation
AlexWaygood Jun 13, 2024
ae49c71
Fix many easily addressed review comments
AlexWaygood Jun 14, 2024
bd94c60
More relatively easily addressed comments
AlexWaygood Jun 14, 2024
43e3626
Just use the file hash for `FileRevision`
AlexWaygood Jun 14, 2024
13ee2d2
simplify
AlexWaygood Jun 14, 2024
05846ae
Refactor `file` and `vendored` methods and make them standalone funct…
MichaReiser Jun 10, 2024
88a6aa4
Make `file_system_path_to_file` return an Option
MichaReiser Jun 10, 2024
64b67ef
Improve documentation, rewrite inline comment, rename `file_system_pa…
MichaReiser Jun 13, 2024
cbb8992
Update crates/ruff_db/src/vfs.rs
MichaReiser Jun 13, 2024
00477c7
Add `ModuleName` struct with tests
MichaReiser Jun 10, 2024
de1ec29
Module resolver
MichaReiser Jun 10, 2024
92b3465
Port module resolver to salsa
MichaReiser Jun 11, 2024
2ee6973
Add `remove_file` and `remove_directory` tests
MichaReiser Jun 11, 2024
96d75a7
Suppress warning about unused `Os` file system that are only used on …
MichaReiser Jun 11, 2024
e5e8da6
Change `ModuleName::new` to return an `Option`
MichaReiser Jun 13, 2024
2348fe6
Use `touch` over `set_permission` and `set_revision` in Tests
MichaReiser Jun 13, 2024
eea6023
Merge branch 'salsa-memory-resolver' into vendored-filesystem
AlexWaygood Jun 14, 2024
07e5a80
Reduce clones and make them more explicit
AlexWaygood Jun 15, 2024
514e9b6
Use interior mutability to avoid cloning when unnecessary
AlexWaygood Jun 15, 2024
1f68832
Do not implement `FileSystem`
AlexWaygood Jun 16, 2024
035ea53
Simplify normalization logic
AlexWaygood Jun 17, 2024
5c33610
Update crates/ruff_db/src/vendored.rs
AlexWaygood Jun 17, 2024
ecf97a9
Get rid of unneeded methods
AlexWaygood Jun 17, 2024
be8f952
Return `Result` from `read()`
AlexWaygood Jun 17, 2024
f4f97d4
Replace a wrapper type with a type alias
AlexWaygood Jun 17, 2024
df248ce
fix tests
AlexWaygood Jun 17, 2024
f05bcb2
Bring back some notion of vendored-stub-file "metadata"
AlexWaygood Jun 17, 2024
89ebc91
Merge remote-tracking branch 'upstream/main' into vendored-filesystem
AlexWaygood Jun 18, 2024
13c2802
add some newlines
AlexWaygood Jun 18, 2024
5d511bb
More docs etc.
AlexWaygood Jun 18, 2024
3127ff6
See if bumping `zstd-sys` changes anything
AlexWaygood Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use touch over set_permission and set_revision in Tests
  • Loading branch information
MichaReiser committed Jun 13, 2024
commit 4df3bea2bcd7c1f055ea73a46990faa2740111cf
3 changes: 1 addition & 2 deletions crates/ruff_db/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl std::fmt::Debug for SourceText {

#[cfg(test)]
mod tests {
use filetime::FileTime;
use salsa::EventKind;

use ruff_source_file::OneIndexed;
Expand All @@ -80,7 +79,7 @@ mod tests {
db.file_system_mut()
.write_file(path, "x = 20".to_string())
.unwrap();
file.set_revision(&mut db).to(FileTime::now().into());
file.touch(&mut db);

assert_eq!(&*source_text(&db, file), "x = 20");

Expand Down
1 change: 1 addition & 0 deletions crates/ruff_db/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl VfsFile {
Self::touch_impl(db, &path, Some(self));
}

/// Private method providing the implementation for [`Self::touch_path`] and [`Self::touch`].
fn touch_impl(db: &mut dyn Db, path: &VfsPath, file: Option<VfsFile>) {
match path {
VfsPath::FileSystem(path) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_semantic/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ModuleName {
return None;
}

if name.split('.').all(|component| is_identifier(component)) {
if name.split('.').all(is_identifier) {
Some(Self(name))
} else {
None
Expand Down
12 changes: 6 additions & 6 deletions crates/ruff_python_semantic/src/module/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::Deref;
use std::sync::Arc;

use ruff_db::file_system::{FileSystem, FileSystemPath, FileSystemPathBuf};
use ruff_db::vfs::{file_system_path_to_file, vfs_path_to_file, VfsFile, VfsPath};
use ruff_db::vfs::{system_path_to_file, vfs_path_to_file, VfsFile, VfsPath};

use crate::module::resolver::internal::ModuleResolverSearchPaths;
use crate::module::{
Expand Down Expand Up @@ -258,13 +258,13 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(ModuleSearchPath, Vfs
// TODO Implement full https://peps.python.org/pep-0561/#type-checker-module-resolution-order resolution
let stub = package_path.with_extension("pyi");

if let Some(stub) = file_system_path_to_file(db.upcast(), &stub) {
if let Some(stub) = system_path_to_file(db.upcast(), &stub) {
return Some((search_path.clone(), stub, kind));
}

let module = package_path.with_extension("py");

if let Some(module) = file_system_path_to_file(db.upcast(), &module) {
if let Some(module) = system_path_to_file(db.upcast(), &module) {
return Some((search_path.clone(), module, kind));
}

Expand Down Expand Up @@ -376,7 +376,7 @@ impl PackageKind {
mod tests {

use ruff_db::file_system::{FileSystemPath, FileSystemPathBuf};
use ruff_db::vfs::{file_system_path_to_file, VfsFile, VfsPath};
use ruff_db::vfs::{system_path_to_file, VfsFile, VfsPath};

use crate::db::tests::TestDb;
use crate::module::{ModuleKind, ModuleName};
Expand Down Expand Up @@ -872,7 +872,7 @@ mod tests {
let foo_module_name = ModuleName::new_static("foo").unwrap();
let foo_module = resolve_module(&db, foo_module_name.clone()).unwrap();

let bar = file_system_path_to_file(&db, &bar_path).expect("bar.py to exist");
let bar = system_path_to_file(&db, &bar_path).expect("bar.py to exist");

db.clear_salsa_events();

Expand Down Expand Up @@ -907,7 +907,7 @@ mod tests {
// Now write the foo file
db.memory_file_system().write_file(&foo_path, "x = 1")?;
VfsFile::touch_path(&mut db, &VfsPath::FileSystem(foo_path.clone()));
let foo_file = file_system_path_to_file(&db, &foo_path).expect("foo.py to exist");
let foo_file = system_path_to_file(&db, &foo_path).expect("foo.py to exist");

let foo_module = resolve_module(&db, foo_module_name).expect("Foo module to resolve");
assert_eq!(foo_file, foo_module.file());
Expand Down
Loading