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] Watch search paths #12407

Merged
merged 2 commits into from
Jul 24, 2024
Merged

[red-knot] Watch search paths #12407

merged 2 commits into from
Jul 24, 2024

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jul 19, 2024

Summary

This PR extends the CLI to watch not only the workspace root but also all search paths. The watcher automatically registers new search paths or stops watching search paths when the program's SearchPathSettings change.

Test Plan

Added integration tests.

Copy link
Contributor

github-actions bot commented Jul 19, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

warning: Detected debug build without --no-cache.
error: Failed to parse examples/Chat_finetuning_data_prep.ipynb:6:18:25: Unparenthesized generator expression cannot be used here
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb:28:1:5: Simple statements must be separated by newlines or semicolons
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_text.ipynb:28:1:5: Simple statements must be separated by newlines or semicolons
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb:37:1:13: Simple statements must be separated by newlines or semicolons

Formatter (preview)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

ruff format --preview

warning: Detected debug build without --no-cache.
error: Failed to parse examples/Chat_finetuning_data_prep.ipynb:6:18:25: Unparenthesized generator expression cannot be used here
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb:28:1:5: Simple statements must be separated by newlines or semicolons
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_text.ipynb:28:1:5: Simple statements must be separated by newlines or semicolons
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb:37:1:13: Simple statements must be separated by newlines or semicolons

@MichaReiser MichaReiser force-pushed the watch-search-paths branch 2 times, most recently from 7cb5f50 to f969d0d Compare July 23, 2024 12:48
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit, adding countme fields to the different tracked structs isn't directly related to this PR but it seemed useful to have and it's a local enough change. But I can extract it if it is preferred.

@MichaReiser MichaReiser added the red-knot Multi-file analysis & type inference label Jul 23, 2024
@MichaReiser MichaReiser marked this pull request as ready for review July 23, 2024 12:53

/// Paths that should be watched but setting up the watcher failed for some reason.
/// This should be rare.
errored_paths: Vec<SystemPathBuf>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use a Vec here because this should almost always be empty and searching small vecs tends to be faster than hash maps, not that it matters much 😆

8.py Outdated Show resolved Hide resolved
Copy link

codspeed-hq bot commented Jul 23, 2024

CodSpeed Performance Report

Merging #12407 will not alter performance

Comparing watch-search-paths (0dcb095) with watch-search-paths (b396613)

Summary

✅ 33 untouched benchmarks

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module-resolver crate bits look good (haven't looked at the other bits yet, but I will!)

Comment on lines 12 to 21
use crate::resolver::{module_resolution_settings, SearchPathIterator};
pub use db::{Db, Jar};
pub use module::{Module, ModuleKind};
pub use module_name::ModuleName;
pub use resolver::resolve_module;
use ruff_db::system::SystemPath;
use std::iter::FusedIterator;
pub use typeshed::{
vendored_typeshed_stubs, TypeshedVersionsParseError, TypeshedVersionsParseErrorKind,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is inconsistent with the import style I've used for the rest of this crate

Suggested change
use crate::resolver::{module_resolution_settings, SearchPathIterator};
pub use db::{Db, Jar};
pub use module::{Module, ModuleKind};
pub use module_name::ModuleName;
pub use resolver::resolve_module;
use ruff_db::system::SystemPath;
use std::iter::FusedIterator;
pub use typeshed::{
vendored_typeshed_stubs, TypeshedVersionsParseError, TypeshedVersionsParseErrorKind,
};
use std::iter::FusedIterator;
use ruff_db::system::SystemPath;
pub use db::{Db, Jar};
pub use module::{Module, ModuleKind};
pub use module_name::ModuleName;
use resolver::{module_resolution_settings, SearchPathIterator};
pub use resolver::resolve_module;
pub use typeshed::{
vendored_typeshed_stubs, TypeshedVersionsParseError, TypeshedVersionsParseErrorKind,
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either deploy tooling to standardize use sorting or not be opinionated about it. It otherwise is guaranteed to get out of sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I'll try to be less picky about it in the future :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I'd be happy to have tooling that standardizes it, but I haven't looked into what the options are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rustfmt has an option for it but it isn't stabilized. https://rust-lang.github.io/rustfmt/?version=master&search=import#group_imports and it can't be enabled on non-nigthly rustfmt

Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel.
Warning: can't set `unstable_features = true`, unstable features are only available in nightly channel.

crates/red_knot_module_resolver/src/lib.rs Show resolved Hide resolved
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

crates/red_knot/src/workspace.rs Outdated Show resolved Hide resolved
crates/red_knot/tests/file_watching.rs Outdated Show resolved Hide resolved
crates/ruff_db/src/system/path.rs Show resolved Hide resolved
@MichaReiser MichaReiser enabled auto-merge (squash) July 24, 2024 07:35
@MichaReiser MichaReiser merged commit eac965e into main Jul 24, 2024
16 checks passed
@MichaReiser MichaReiser deleted the watch-search-paths branch July 24, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants