-
Notifications
You must be signed in to change notification settings - Fork 97
Add CLI flag to override typeshed #488
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,10 @@ pub struct ConfigFile { | |
)] | ||
pub fallback_search_path: Vec<PathBuf>, | ||
|
||
/// Override the bundled typeshed with a custom path. | ||
#[serde(skip)] | ||
pub typeshed_path: Option<PathBuf>, | ||
|
||
// TODO(connernilsen): make this mutually exclusive with venv/conda env | ||
/// The python executable that will be queried for `python_version`, | ||
/// `python_platform`, or `site_package_path` if any of the values are missing. | ||
|
@@ -302,6 +306,7 @@ impl Default for ConfigFile { | |
custom_module_paths: Default::default(), | ||
use_untyped_imports: true, | ||
ignore_missing_source: true, | ||
typeshed_path: None, | ||
} | ||
} | ||
} | ||
|
@@ -354,14 +359,38 @@ impl ConfigFile { | |
Err(FindError::Ignored) | ||
} else if let Some(path) = find_module_in_search_path(module, self.search_path()) { | ||
Ok(path) | ||
} else if let Some(custom_typeshed_path) = &self.typeshed_path { | ||
// Check custom typeshed stdlib path before bundled typeshed | ||
let stdlib_path = custom_typeshed_path.join("stdlib"); | ||
if let Some(path) = find_module_in_search_path(module, std::iter::once(&stdlib_path)) { | ||
Ok(path) | ||
} else if let Some(path) = typeshed() | ||
.map_err(|err| FindError::not_found(err, module))? | ||
.find(module) | ||
{ | ||
Ok(path) | ||
} else if let Some(path) = find_module_in_search_path(module, self.fallback_search_path.iter()) { | ||
Ok(path) | ||
} else if let Some(path) = find_module_in_site_package_path( | ||
module, | ||
self.site_package_path(), | ||
self.use_untyped_imports, | ||
self.ignore_missing_source, | ||
)? { | ||
Ok(path) | ||
} else { | ||
Err(FindError::import_lookup_path( | ||
self.structured_import_lookup_path(), | ||
module, | ||
&self.source, | ||
)) | ||
} | ||
Comment on lines
+367
to
+387
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, it looks like this part might have been duplicated from below. Can you remove this? |
||
} else if let Some(path) = typeshed() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should only use the builtin typeshed if one isn't provided. Can we add an extra condition for that here?
|
||
.map_err(|err| FindError::not_found(err, module))? | ||
.find(module) | ||
{ | ||
Ok(path) | ||
} else if let Some(path) = | ||
find_module_in_search_path(module, self.fallback_search_path.iter()) | ||
{ | ||
} else if let Some(path) = find_module_in_search_path(module, self.fallback_search_path.iter()) { | ||
Ok(path) | ||
} else if let Some(path) = find_module_in_site_package_path( | ||
module, | ||
|
@@ -823,6 +852,7 @@ mod tests { | |
}], | ||
use_untyped_imports: true, | ||
ignore_missing_source: true, | ||
typeshed_path: None, | ||
} | ||
); | ||
} | ||
|
@@ -1033,6 +1063,7 @@ mod tests { | |
}], | ||
use_untyped_imports: false, | ||
ignore_missing_source: false, | ||
typeshed_path: None, | ||
}; | ||
|
||
let path_str = with_sep("path/to/my/config"); | ||
|
@@ -1069,6 +1100,7 @@ mod tests { | |
}], | ||
use_untyped_imports: false, | ||
ignore_missing_source: false, | ||
typeshed_path: None, | ||
}; | ||
assert_eq!(config, expected_config); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
arg(long, ...)
does the same thing asarg(long = "typeshed-path", ...)
, but specifying"typeshed-path"
is more prone to typos/less resilient to refactors. Can we just leave this asarg(long, ...)
?