Skip to content

Commit 653c090

Browse files
Use an empty vendored file system in Ruff (#13436)
## Summary This PR changes removes the typeshed stubs from the vendored file system shipped with ruff and instead ships an empty "typeshed". Making the typeshed files optional required extracting the typshed files into a new `ruff_vendored` crate. I do like this even if all our builds always include typeshed because it means `red_knot_python_semantic` contains less code that needs compiling. This also allows us to use deflate because the compression algorithm doesn't matter for an archive containing a single, empty file. ## Test Plan `cargo test` I verified with ` cargo tree -f "{p} {f}" -p <package> ` that: * red_knot_wasm: enables `deflate` compression * red_knot: enables `zstd` compression * `ruff`: uses stored I'm not quiet sure how to build the binary that maturin builds but comparing the release artifact size with `strip = true` shows a `1.5MB` size reduction --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
1 parent 8921fbb commit 653c090

602 files changed

Lines changed: 158 additions & 126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/sync_typeshed.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ jobs:
3737
- name: Sync typeshed
3838
id: sync
3939
run: |
40-
rm -rf ruff/crates/red_knot_python_semantic/vendor/typeshed
41-
mkdir ruff/crates/red_knot_python_semantic/vendor/typeshed
42-
cp typeshed/README.md ruff/crates/red_knot_python_semantic/vendor/typeshed
43-
cp typeshed/LICENSE ruff/crates/red_knot_python_semantic/vendor/typeshed
44-
cp -r typeshed/stdlib ruff/crates/red_knot_python_semantic/vendor/typeshed/stdlib
45-
rm -rf ruff/crates/red_knot_python_semantic/vendor/typeshed/stdlib/@tests
46-
git -C typeshed rev-parse HEAD > ruff/crates/red_knot_python_semantic/vendor/typeshed/source_commit.txt
40+
rm -rf ruff/crates/ruff_vendored/vendor/typeshed
41+
mkdir ruff/crates/ruff_vendored/vendor/typeshed
42+
cp typeshed/README.md ruff/crates/ruff_vendored/vendor/typeshed
43+
cp typeshed/LICENSE ruff/crates/ruff_vendored/vendor/typeshed
44+
cp -r typeshed/stdlib ruff/crates/ruff_vendored/vendor/typeshed/stdlib
45+
rm -rf ruff/crates/ruff_vendored/vendor/typeshed/stdlib/@tests
46+
git -C typeshed rev-parse HEAD > ruff/crates/ruff_vendored/vendor/typeshed/source_commit.txt
4747
- name: Commit the changes
4848
id: commit
4949
if: ${{ steps.sync.outcome == 'success' }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fail_fast: true
22

33
exclude: |
44
(?x)^(
5-
crates/red_knot_python_semantic/vendor/.*|
5+
crates/ruff_vendored/vendor/.*|
66
crates/red_knot_workspace/resources/.*|
77
crates/ruff_linter/resources/.*|
88
crates/ruff_linter/src/rules/.*/snapshots/.*|

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ license = "MIT"
1414
[workspace.dependencies]
1515
ruff = { path = "crates/ruff" }
1616
ruff_cache = { path = "crates/ruff_cache" }
17-
ruff_db = { path = "crates/ruff_db" }
17+
ruff_db = { path = "crates/ruff_db", default-features = false }
1818
ruff_diagnostics = { path = "crates/ruff_diagnostics" }
1919
ruff_formatter = { path = "crates/ruff_formatter" }
2020
ruff_graph = { path = "crates/ruff_graph" }
@@ -34,11 +34,12 @@ ruff_python_trivia = { path = "crates/ruff_python_trivia" }
3434
ruff_server = { path = "crates/ruff_server" }
3535
ruff_source_file = { path = "crates/ruff_source_file" }
3636
ruff_text_size = { path = "crates/ruff_text_size" }
37+
ruff_vendored = { path = "crates/ruff_vendored" }
3738
ruff_workspace = { path = "crates/ruff_workspace" }
3839

3940
red_knot_python_semantic = { path = "crates/red_knot_python_semantic" }
4041
red_knot_server = { path = "crates/red_knot_server" }
41-
red_knot_workspace = { path = "crates/red_knot_workspace" }
42+
red_knot_workspace = { path = "crates/red_knot_workspace", default-features = false }
4243

4344
aho-corasick = { version = "1.1.3" }
4445
annotate-snippets = { version = "0.9.2", features = ["color"] }

crates/red_knot/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ license.workspace = true
1313

1414
[dependencies]
1515
red_knot_python_semantic = { workspace = true }
16-
red_knot_workspace = { workspace = true }
16+
red_knot_workspace = { workspace = true, features = ["zstd"] }
1717
red_knot_server = { workspace = true }
18-
1918
ruff_db = { workspace = true, features = ["os", "cache"] }
2019

2120
anyhow = { workspace = true }

crates/red_knot_python_semantic/Cargo.toml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ bitflags = { workspace = true }
2424
camino = { workspace = true }
2525
compact_str = { workspace = true }
2626
countme = { workspace = true }
27-
once_cell = { workspace = true }
2827
ordermap = { workspace = true }
2928
salsa = { workspace = true }
3029
thiserror = { workspace = true }
@@ -35,20 +34,14 @@ smallvec = { workspace = true }
3534
static_assertions = { workspace = true }
3635
test-case = { workspace = true }
3736

38-
[build-dependencies]
39-
path-slash = { workspace = true }
40-
walkdir = { workspace = true }
41-
zip = { workspace = true, features = ["zstd", "deflate"] }
42-
4337
[dev-dependencies]
4438
ruff_db = { workspace = true, features = ["os", "testing"] }
4539
ruff_python_parser = { workspace = true }
40+
ruff_vendored = { workspace = true }
4641

4742
anyhow = { workspace = true }
4843
insta = { workspace = true }
4944
tempfile = { workspace = true }
50-
walkdir = { workspace = true }
51-
zip = { workspace = true }
5245

5346
[lints]
5447
workspace = true

crates/red_knot_python_semantic/src/db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub trait Db: SourceDb + Upcast<dyn SourceDb> {
1111
pub(crate) mod tests {
1212
use std::sync::Arc;
1313

14-
use crate::module_resolver::vendored_typeshed_stubs;
1514
use ruff_db::files::{File, Files};
1615
use ruff_db::system::{DbWithTestSystem, System, TestSystem};
1716
use ruff_db::vendored::VendoredFileSystem;
@@ -33,7 +32,7 @@ pub(crate) mod tests {
3332
Self {
3433
storage: salsa::Storage::default(),
3534
system: TestSystem::default(),
36-
vendored: vendored_typeshed_stubs().clone(),
35+
vendored: ruff_vendored::file_system().clone(),
3736
events: std::sync::Arc::default(),
3837
files: Files::default(),
3938
}

crates/red_knot_python_semantic/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use rustc_hash::FxHasher;
44

55
pub use db::Db;
66
pub use module_name::ModuleName;
7-
pub use module_resolver::{
8-
resolve_module, system_module_search_paths, vendored_typeshed_stubs, Module,
9-
};
7+
pub use module_resolver::{resolve_module, system_module_search_paths, Module};
108
pub use program::{Program, ProgramSettings, SearchPathSettings, SitePackages};
119
pub use python_version::PythonVersion;
1210
pub use semantic_model::{HasTy, SemanticModel};

crates/red_knot_python_semantic/src/module_resolver/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub use module::Module;
44
pub use resolver::resolve_module;
55
pub(crate) use resolver::{file_to_module, SearchPaths};
66
use ruff_db::system::SystemPath;
7-
pub use typeshed::vendored_typeshed_stubs;
87

98
use crate::module_resolver::resolver::search_paths;
109
use crate::Db;

crates/red_knot_python_semantic/src/module_resolver/typeshed/versions.rs renamed to crates/red_knot_python_semantic/src/module_resolver/typeshed.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ mod tests {
390390
fn typeshed_versions_consistent_with_vendored_stubs() {
391391
let db = TestDb::new();
392392
let vendored_typeshed_versions = vendored_typeshed_versions(&db);
393-
let vendored_typeshed_dir = Path::new("vendor/typeshed").canonicalize().unwrap();
393+
let vendored_typeshed_dir =
394+
Path::new(env!("CARGO_MANIFEST_DIR")).join("../ruff_vendored/vendor/typeshed");
394395

395396
let mut empty_iterator = true;
396397

0 commit comments

Comments
 (0)