[ty] Rename `extra-paths` to `non-environment-paths`, and `--extra-search-path` to `--non-environment-search-path`

This commit is contained in:
Alex Waygood 2025-10-06 15:00:07 +01:00
parent 1c5666ce5d
commit 0cecc22d8b
17 changed files with 95 additions and 86 deletions

4
crates/ty/docs/cli.md generated
View File

@ -54,10 +54,10 @@ over all configuration files.</p>
</dd><dt id="ty-check--exclude"><a href="#ty-check--exclude"><code>--exclude</code></a> <i>exclude</i></dt><dd><p>Glob patterns for files to exclude from type checking.</p> </dd><dt id="ty-check--exclude"><a href="#ty-check--exclude"><code>--exclude</code></a> <i>exclude</i></dt><dd><p>Glob patterns for files to exclude from type checking.</p>
<p>Uses gitignore-style syntax to exclude files and directories from type checking. Supports patterns like <code>tests/</code>, <code>*.tmp</code>, <code>**/__pycache__/**</code>.</p> <p>Uses gitignore-style syntax to exclude files and directories from type checking. Supports patterns like <code>tests/</code>, <code>*.tmp</code>, <code>**/__pycache__/**</code>.</p>
</dd><dt id="ty-check--exit-zero"><a href="#ty-check--exit-zero"><code>--exit-zero</code></a></dt><dd><p>Always use exit code 0, even when there are error-level diagnostics</p> </dd><dt id="ty-check--exit-zero"><a href="#ty-check--exit-zero"><code>--exit-zero</code></a></dt><dd><p>Always use exit code 0, even when there are error-level diagnostics</p>
</dd><dt id="ty-check--extra-search-path"><a href="#ty-check--extra-search-path"><code>--extra-search-path</code></a> <i>path</i></dt><dd><p>Additional path to use as a module-resolution source (can be passed multiple times).</p>
<p>This is an advanced option that should usually only be used for first-party or third-party modules that are not installed into your Python environment in a conventional way. Use <code>--python</code> to point ty to your Python environment if it is in an unusual location.</p>
</dd><dt id="ty-check--help"><a href="#ty-check--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Print help (see a summary with '-h')</p> </dd><dt id="ty-check--help"><a href="#ty-check--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Print help (see a summary with '-h')</p>
</dd><dt id="ty-check--ignore"><a href="#ty-check--ignore"><code>--ignore</code></a> <i>rule</i></dt><dd><p>Disables the rule. Can be specified multiple times.</p> </dd><dt id="ty-check--ignore"><a href="#ty-check--ignore"><code>--ignore</code></a> <i>rule</i></dt><dd><p>Disables the rule. Can be specified multiple times.</p>
</dd><dt id="ty-check--non-environment-search-path"><a href="#ty-check--non-environment-search-path"><code>--non-environment-search-path</code></a> <i>path</i></dt><dd><p>Additional path to use as a module-resolution source (can be passed multiple times).</p>
<p>This is an advanced option that should usually only be used for first-party or third-party modules that are not installed into your Python environment in a conventional way. Use <code>--python</code> to point ty to your Python environment if it is in an unusual location.</p>
</dd><dt id="ty-check--output-format"><a href="#ty-check--output-format"><code>--output-format</code></a> <i>output-format</i></dt><dd><p>The format to use for printing diagnostic messages</p> </dd><dt id="ty-check--output-format"><a href="#ty-check--output-format"><code>--output-format</code></a> <i>output-format</i></dt><dd><p>The format to use for printing diagnostic messages</p>
<p>Possible values:</p> <p>Possible values:</p>
<ul> <ul>

View File

@ -30,7 +30,7 @@ division-by-zero = "ignore"
## `environment` ## `environment`
### `extra-paths` ### `non-environment-paths`
User-provided paths that should take first priority in module resolution. User-provided paths that should take first priority in module resolution.
@ -49,7 +49,7 @@ configuration setting.
```toml ```toml
[tool.ty.environment] [tool.ty.environment]
extra-paths = ["./shared/my-search-path"] non-environment-paths = ["./shared/my-search-path"]
``` ```
--- ---

View File

@ -72,7 +72,7 @@ pub(crate) struct CheckCommand {
/// modules that are not installed into your Python environment in a conventional way. /// modules that are not installed into your Python environment in a conventional way.
/// Use `--python` to point ty to your Python environment if it is in an unusual location. /// Use `--python` to point ty to your Python environment if it is in an unusual location.
#[arg(long, value_name = "PATH")] #[arg(long, value_name = "PATH")]
pub(crate) extra_search_path: Option<Vec<SystemPathBuf>>, pub(crate) non_environment_search_path: Option<Vec<SystemPathBuf>>,
/// Python version to assume when resolving types. /// Python version to assume when resolving types.
/// ///
@ -184,12 +184,14 @@ impl CheckCommand {
.map(|platform| RangedValue::cli(platform.into())), .map(|platform| RangedValue::cli(platform.into())),
python: self.python.map(RelativePathBuf::cli), python: self.python.map(RelativePathBuf::cli),
typeshed: self.typeshed.map(RelativePathBuf::cli), typeshed: self.typeshed.map(RelativePathBuf::cli),
extra_paths: self.extra_search_path.map(|extra_search_paths| { non_environment_paths: self.non_environment_search_path.map(
extra_search_paths |non_environment_paths| {
non_environment_paths
.into_iter() .into_iter()
.map(RelativePathBuf::cli) .map(RelativePathBuf::cli)
.collect() .collect()
}), },
),
..EnvironmentOptions::default() ..EnvironmentOptions::default()
}), }),
terminal: Some(TerminalOptions { terminal: Some(TerminalOptions {

View File

@ -275,7 +275,7 @@ fn cli_arguments_are_relative_to_the_current_directory() -> anyhow::Result<()> {
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
"); ");
assert_cmd_snapshot!(case.command().current_dir(case.root().join("child")).arg("--extra-search-path").arg("../libs"), @r" assert_cmd_snapshot!(case.command().current_dir(case.root().join("child")).arg("--non-environment-search-path").arg("../libs"), @r"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -290,7 +290,7 @@ fn cli_arguments_are_relative_to_the_current_directory() -> anyhow::Result<()> {
/// Paths specified in a configuration file are relative to the project root. /// Paths specified in a configuration file are relative to the project root.
/// ///
/// We test this by adding `libs` (as a relative path) to the extra search path in the configuration and run /// We test this by adding `libs` (as a relative path) to `non-environment-paths` in the configuration and run
/// the CLI from a subdirectory. /// the CLI from a subdirectory.
/// ///
/// Project layout: /// Project layout:
@ -309,7 +309,7 @@ fn paths_in_configuration_files_are_relative_to_the_project_root() -> anyhow::Re
r#" r#"
[tool.ty.environment] [tool.ty.environment]
python-version = "3.11" python-version = "3.11"
extra-paths = ["libs"] non-environment-paths = ["libs"]
"#, "#,
), ),
( (

View File

@ -422,7 +422,7 @@ where
// We need a chance to create the directories here. // We need a chance to create the directories here.
if let Some(environment) = project.options().environment.as_ref() { if let Some(environment) = project.options().environment.as_ref() {
for path in environment for path in environment
.extra_paths .non_environment_paths
.as_deref() .as_deref()
.unwrap_or_default() .unwrap_or_default()
.iter() .iter()
@ -542,7 +542,7 @@ fn new_non_project_file() -> anyhow::Result<()> {
context.write_project_file("bar.py", "")?; context.write_project_file("bar.py", "")?;
context.set_options(Options { context.set_options(Options {
environment: Some(EnvironmentOptions { environment: Some(EnvironmentOptions {
extra_paths: Some(vec![RelativePathBuf::cli( non_environment_paths: Some(vec![RelativePathBuf::cli(
context.join_root_path("site_packages"), context.join_root_path("site_packages"),
)]), )]),
..EnvironmentOptions::default() ..EnvironmentOptions::default()
@ -986,7 +986,7 @@ fn search_path() -> anyhow::Result<()> {
context.set_options(Options { context.set_options(Options {
environment: Some(EnvironmentOptions { environment: Some(EnvironmentOptions {
extra_paths: Some(vec![RelativePathBuf::cli( non_environment_paths: Some(vec![RelativePathBuf::cli(
context.join_root_path("site_packages"), context.join_root_path("site_packages"),
)]), )]),
..EnvironmentOptions::default() ..EnvironmentOptions::default()
@ -1027,7 +1027,7 @@ fn add_search_path() -> anyhow::Result<()> {
// Register site-packages as a search path. // Register site-packages as a search path.
case.update_options(Options { case.update_options(Options {
environment: Some(EnvironmentOptions { environment: Some(EnvironmentOptions {
extra_paths: Some(vec![RelativePathBuf::cli("site_packages")]), non_environment_paths: Some(vec![RelativePathBuf::cli("site_packages")]),
..EnvironmentOptions::default() ..EnvironmentOptions::default()
}), }),
..Options::default() ..Options::default()
@ -1051,7 +1051,7 @@ fn remove_search_path() -> anyhow::Result<()> {
context.write_project_file("bar.py", "import sub.a")?; context.write_project_file("bar.py", "import sub.a")?;
context.set_options(Options { context.set_options(Options {
environment: Some(EnvironmentOptions { environment: Some(EnvironmentOptions {
extra_paths: Some(vec![RelativePathBuf::cli( non_environment_paths: Some(vec![RelativePathBuf::cli(
context.join_root_path("site_packages"), context.join_root_path("site_packages"),
)]), )]),
..EnvironmentOptions::default() ..EnvironmentOptions::default()
@ -1579,7 +1579,7 @@ mod unix {
context.set_options(Options { context.set_options(Options {
environment: Some(EnvironmentOptions { environment: Some(EnvironmentOptions {
extra_paths: Some(vec![RelativePathBuf::cli( non_environment_paths: Some(vec![RelativePathBuf::cli(
".venv/lib/python3.12/site-packages", ".venv/lib/python3.12/site-packages",
)]), )]),
python_version: Some(RangedValue::cli(PythonVersion::PY312)), python_version: Some(RangedValue::cli(PythonVersion::PY312)),

View File

@ -32,25 +32,25 @@ use ty_python_semantic::PythonPlatform;
/// ///
/// The main downside of this approach is that the ordering can be surprising in cases /// The main downside of this approach is that the ordering can be surprising in cases
/// where the option has a "first match" semantic and not a "last match" wins. /// where the option has a "first match" semantic and not a "last match" wins.
/// One such example is `extra-paths` where the semantics is given by Python: /// One such example is `non-environment-paths` where the semantics is given by Python:
/// the module on the first matching search path wins. /// the module on the first matching search path wins.
/// ///
/// ```toml /// ```toml
/// [environment] /// [environment]
/// extra-paths = ["b", "c"] /// non-environment-paths = ["b", "c"]
/// ``` /// ```
/// ///
/// ```bash /// ```bash
/// ty --extra-paths a /// ty --non-environment-search-path=a
/// ``` /// ```
/// ///
/// That's why a user might expect that this configuration results in `["a", "b", "c"]`, /// That's why a user might expect that this configuration results in `["a", "b", "c"]`,
/// because the CLI has higher precedence. However, the current implementation results in a /// because the CLI has higher precedence. However, the current implementation results in a
/// resolved extra search path of `["b", "c", "a"]`, which means `a` will be tried last. /// resolved `non-environment-paths` of `["b", "c", "a"]`, which means `a` will be tried last.
/// ///
/// There's an argument here that the user should be able to specify the order of the paths, /// There's an argument here that the user should be able to specify the order of the paths,
/// because only then is the user in full control of where to insert the path when specifying `extra-paths` /// because only then is the user in full control of where to insert the path when specifying
/// in multiple sources. /// `non-environment-paths` in multiple sources.
/// ///
/// ## Macro /// ## Macro
/// You can automatically derive `Combine` for structs with named fields by using `derive(ruff_macros::Combine)`. /// You can automatically derive `Combine` for structs with named fields by using `derive(ruff_macros::Combine)`.

View File

@ -301,18 +301,19 @@ impl Options {
}; };
// collect the existing site packages // collect the existing site packages
let mut extra_paths: Vec<SystemPathBuf> = environment let mut non_environment_paths: Vec<SystemPathBuf> = environment
.extra_paths .non_environment_paths
.as_deref() .as_deref()
.unwrap_or_default() .unwrap_or_default()
.iter() .iter()
.map(|path| path.absolute(project_root, system)) .map(|path| path.absolute(project_root, system))
.collect(); .collect();
// read all the paths off the PYTHONPATH environment variable, check // Read all the paths off the `PYTHONPATH` environment variable, check
// they exist as a directory, and add them to the vec of extra_paths // each exists as a directory, and add each to the vec of `non_environment_paths`.
// as they should be checked before site-packages just like python // This emulates the way `PYTHONPATH` entries will appear in `sys.path` prior to
// interpreter does // `site-packages` (the "environment search path") from a virtual environment at
// runtime.
if let Ok(python_path) = system.env_var(EnvVars::PYTHONPATH) { if let Ok(python_path) = system.env_var(EnvVars::PYTHONPATH) {
for path in std::env::split_paths(python_path.as_str()) { for path in std::env::split_paths(python_path.as_str()) {
let path = match SystemPathBuf::from_path_buf(path) { let path = match SystemPathBuf::from_path_buf(path) {
@ -336,15 +337,15 @@ impl Options {
} }
tracing::debug!( tracing::debug!(
"Adding `{abspath}` from the `PYTHONPATH` environment variable to `extra_paths`" "Adding `{abspath}` from the `PYTHONPATH` environment variable to `non_environment_paths`"
); );
extra_paths.push(abspath); non_environment_paths.push(abspath);
} }
} }
let settings = SearchPathSettings { let settings = SearchPathSettings {
extra_paths, non_environment_paths,
src_roots, src_roots,
custom_typeshed: environment custom_typeshed: environment
.typeshed .typeshed
@ -563,10 +564,10 @@ pub struct EnvironmentOptions {
default = r#"[]"#, default = r#"[]"#,
value_type = "list[str]", value_type = "list[str]",
example = r#" example = r#"
extra-paths = ["./shared/my-search-path"] non-environment-paths = ["./shared/my-search-path"]
"# "#
)] )]
pub extra_paths: Option<Vec<RelativePathBuf>>, pub non_environment_paths: Option<Vec<RelativePathBuf>>,
/// Optional path to a "typeshed" directory on disk for us to use for standard-library types. /// Optional path to a "typeshed" directory on disk for us to use for standard-library types.
/// If this is not provided, we will fallback to our vendored typeshed stubs for the stdlib, /// If this is not provided, we will fallback to our vendored typeshed stubs for the stdlib,

View File

@ -25,7 +25,7 @@ pub enum ValueSource {
File(Arc<SystemPathBuf>), File(Arc<SystemPathBuf>),
/// The value comes from a CLI argument, while it's left open if specified using a short argument, /// The value comes from a CLI argument, while it's left open if specified using a short argument,
/// long argument (`--extra-paths`) or `--config key=value`. /// long argument (`--non-environment-search-path`) or `--config key=value`.
Cli, Cli,
/// The value comes from an LSP client configuration. /// The value comes from an LSP client configuration.

View File

@ -48,7 +48,7 @@ search paths if the file name's casing does not match.
```toml ```toml
[environment] [environment]
extra-paths = ["/search-1", "/search-2"] non-environment-paths = ["/search-1", "/search-2"]
``` ```
`/search-1/A.py`: `/search-1/A.py`:

View File

@ -40,7 +40,7 @@ neither.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/py.typed`: `/packages/foo-stubs/py.typed`:
@ -99,7 +99,7 @@ Omitting the partial `py.typed`, we see "impl" now cannot be found.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/__init__.pyi`: `/packages/foo-stubs/__init__.pyi`:
@ -152,7 +152,7 @@ Including a blank py.typed we still don't conclude it's partial.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/py.typed`: `/packages/foo-stubs/py.typed`:
@ -210,7 +210,7 @@ reveal_type(Fake().fake) # revealed: Unknown
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/py.typed`: `/packages/foo-stubs/py.typed`:
@ -280,7 +280,7 @@ reveal_type(Fake().fake) # revealed: Unknown
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/py.typed`: `/packages/foo-stubs/py.typed`:
@ -355,7 +355,7 @@ reveal_type(Fake().fake) # revealed: Unknown
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/py.typed`: `/packages/foo-stubs/py.typed`:
@ -433,7 +433,7 @@ This is a regression test for <https://github.com/astral-sh/ty/issues/520>.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/parent-stubs/foo/both.pyi`: `/packages/parent-stubs/foo/both.pyi`:

View File

@ -7,7 +7,7 @@ Stub packages are packages named `<package>-stubs` that provide typing stubs for
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/__init__.pyi`: `/packages/foo-stubs/__init__.pyi`:
@ -38,7 +38,7 @@ The regular package isn't required for type checking.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs/__init__.pyi`: `/packages/foo-stubs/__init__.pyi`:
@ -63,7 +63,7 @@ A module named `<module>-stubs` isn't a stub package.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/foo-stubs.pyi`: `/packages/foo-stubs.pyi`:
@ -88,7 +88,7 @@ A namespace package with multiple stub packages spread over multiple search path
```toml ```toml
[environment] [environment]
extra-paths = ["/stubs1", "/stubs2", "/packages"] non-environment-paths = ["/stubs1", "/stubs2", "/packages"]
``` ```
`/stubs1/shapes-stubs/polygons/pentagon.pyi`: `/stubs1/shapes-stubs/polygons/pentagon.pyi`:
@ -136,7 +136,7 @@ should stop after the first non-namespace stub package. This matches Pyright's b
```toml ```toml
[environment] [environment]
extra-paths = ["/stubs1", "/stubs2", "/packages"] non-environment-paths = ["/stubs1", "/stubs2", "/packages"]
``` ```
`/stubs1/shapes-stubs/__init__.pyi`: `/stubs1/shapes-stubs/__init__.pyi`:
@ -196,7 +196,7 @@ fewer lookups.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/shapes-stubs/polygons/pentagon.pyi`: `/packages/shapes-stubs/polygons/pentagon.pyi`:
@ -254,7 +254,7 @@ to be an enforced convention. At least, Pyright is fine with the following.
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/shapes-stubs/__init__.py`: `/packages/shapes-stubs/__init__.py`:
@ -291,7 +291,7 @@ Regression test for <https://github.com/astral-sh/ty/issues/408>
```toml ```toml
[environment] [environment]
extra-paths = ["/packages"] non-environment-paths = ["/packages"]
``` ```
`/packages/yaml-stubs/__init__.pyi`: `/packages/yaml-stubs/__init__.pyi`:

View File

@ -93,7 +93,7 @@ impl ModulePath {
relative_path, relative_path,
} = self; } = self;
match &*search_path.0 { match &*search_path.0 {
SearchPathInner::Extra(search_path) SearchPathInner::NonEnvironment(search_path)
| SearchPathInner::FirstParty(search_path) | SearchPathInner::FirstParty(search_path)
| SearchPathInner::SitePackages(search_path) | SearchPathInner::SitePackages(search_path)
| SearchPathInner::Editable(search_path) | SearchPathInner::Editable(search_path)
@ -131,7 +131,7 @@ impl ModulePath {
} = self; } = self;
match &*search_path.0 { match &*search_path.0 {
SearchPathInner::Extra(search_path) SearchPathInner::NonEnvironment(search_path)
| SearchPathInner::FirstParty(search_path) | SearchPathInner::FirstParty(search_path)
| SearchPathInner::SitePackages(search_path) | SearchPathInner::SitePackages(search_path)
| SearchPathInner::Editable(search_path) => { | SearchPathInner::Editable(search_path) => {
@ -199,7 +199,7 @@ impl ModulePath {
relative_path, relative_path,
} = self; } = self;
match &*search_path.0 { match &*search_path.0 {
SearchPathInner::Extra(search_path) SearchPathInner::NonEnvironment(search_path)
| SearchPathInner::FirstParty(search_path) | SearchPathInner::FirstParty(search_path)
| SearchPathInner::SitePackages(search_path) | SearchPathInner::SitePackages(search_path)
| SearchPathInner::Editable(search_path) => Some(search_path.join(relative_path)), | SearchPathInner::Editable(search_path) => Some(search_path.join(relative_path)),
@ -219,7 +219,7 @@ impl ModulePath {
relative_path, relative_path,
} = self; } = self;
match &*search_path.0 { match &*search_path.0 {
SearchPathInner::Extra(search_path) SearchPathInner::NonEnvironment(search_path)
| SearchPathInner::FirstParty(search_path) | SearchPathInner::FirstParty(search_path)
| SearchPathInner::SitePackages(search_path) | SearchPathInner::SitePackages(search_path)
| SearchPathInner::Editable(search_path) => { | SearchPathInner::Editable(search_path) => {
@ -451,7 +451,7 @@ type SearchPathResult<T> = Result<T, SearchPathValidationError>;
#[derive(Debug, Clone, PartialEq, Eq, Hash, get_size2::GetSize)] #[derive(Debug, Clone, PartialEq, Eq, Hash, get_size2::GetSize)]
enum SearchPathInner { enum SearchPathInner {
Extra(SystemPathBuf), NonEnvironment(SystemPathBuf),
FirstParty(SystemPathBuf), FirstParty(SystemPathBuf),
StandardLibraryCustom(SystemPathBuf), StandardLibraryCustom(SystemPathBuf),
StandardLibraryVendored(VendoredPathBuf), StandardLibraryVendored(VendoredPathBuf),
@ -464,7 +464,7 @@ enum SearchPathInner {
/// that can be used to locate Python modules. /// that can be used to locate Python modules.
/// ///
/// The different kinds of search paths are: /// The different kinds of search paths are:
/// - "Extra" search paths: these go at the start of the module resolution order /// - "Non-environment" search paths: these go at the start of the module resolution order
/// - First-party search paths: the user code that we are directly invoked on. /// - First-party search paths: the user code that we are directly invoked on.
/// - Standard-library search paths: these come in three different forms: /// - Standard-library search paths: these come in three different forms:
/// - Custom standard-library search paths: paths provided by the user /// - Custom standard-library search paths: paths provided by the user
@ -499,9 +499,12 @@ impl SearchPath {
} }
} }
/// Create a new "Extra" search path /// Create a new non-environment search path
pub(crate) fn extra(system: &dyn System, root: SystemPathBuf) -> SearchPathResult<Self> { pub(crate) fn non_environment(
Ok(Self(Arc::new(SearchPathInner::Extra( system: &dyn System,
root: SystemPathBuf,
) -> SearchPathResult<Self> {
Ok(Self(Arc::new(SearchPathInner::NonEnvironment(
Self::directory_path(system, root)?, Self::directory_path(system, root)?,
)))) ))))
} }
@ -616,7 +619,7 @@ impl SearchPath {
} }
match &*self.0 { match &*self.0 {
SearchPathInner::Extra(search_path) SearchPathInner::NonEnvironment(search_path)
| SearchPathInner::FirstParty(search_path) | SearchPathInner::FirstParty(search_path)
| SearchPathInner::StandardLibraryCustom(search_path) | SearchPathInner::StandardLibraryCustom(search_path)
| SearchPathInner::StandardLibraryReal(search_path) | SearchPathInner::StandardLibraryReal(search_path)
@ -643,7 +646,7 @@ impl SearchPath {
} }
match &*self.0 { match &*self.0 {
SearchPathInner::Extra(_) SearchPathInner::NonEnvironment(_)
| SearchPathInner::FirstParty(_) | SearchPathInner::FirstParty(_)
| SearchPathInner::StandardLibraryCustom(_) | SearchPathInner::StandardLibraryCustom(_)
| SearchPathInner::StandardLibraryReal(_) | SearchPathInner::StandardLibraryReal(_)
@ -662,7 +665,7 @@ impl SearchPath {
#[must_use] #[must_use]
pub(super) fn as_path(&self) -> SystemOrVendoredPathRef<'_> { pub(super) fn as_path(&self) -> SystemOrVendoredPathRef<'_> {
match *self.0 { match *self.0 {
SearchPathInner::Extra(ref path) SearchPathInner::NonEnvironment(ref path)
| SearchPathInner::FirstParty(ref path) | SearchPathInner::FirstParty(ref path)
| SearchPathInner::StandardLibraryCustom(ref path) | SearchPathInner::StandardLibraryCustom(ref path)
| SearchPathInner::StandardLibraryReal(ref path) | SearchPathInner::StandardLibraryReal(ref path)
@ -691,7 +694,7 @@ impl SearchPath {
#[must_use] #[must_use]
pub(crate) fn debug_kind(&self) -> &'static str { pub(crate) fn debug_kind(&self) -> &'static str {
match *self.0 { match *self.0 {
SearchPathInner::Extra(_) => "extra", SearchPathInner::NonEnvironment(_) => "extra",
SearchPathInner::FirstParty(_) => "first-party", SearchPathInner::FirstParty(_) => "first-party",
SearchPathInner::StandardLibraryCustom(_) => "std-custom", SearchPathInner::StandardLibraryCustom(_) => "std-custom",
SearchPathInner::StandardLibraryReal(_) => "std-real", SearchPathInner::StandardLibraryReal(_) => "std-real",
@ -706,8 +709,8 @@ impl SearchPath {
#[must_use] #[must_use]
pub(crate) fn describe_kind(&self) -> &'static str { pub(crate) fn describe_kind(&self) -> &'static str {
match *self.0 { match *self.0 {
SearchPathInner::Extra(_) => { SearchPathInner::NonEnvironment(_) => {
"extra search path specified on the CLI or in your config file" "non-environment search path specified on the CLI or in your config file"
} }
SearchPathInner::FirstParty(_) => "first-party code", SearchPathInner::FirstParty(_) => "first-party code",
SearchPathInner::StandardLibraryCustom(_) => { SearchPathInner::StandardLibraryCustom(_) => {
@ -772,7 +775,7 @@ impl PartialEq<SearchPath> for VendoredPathBuf {
impl fmt::Display for SearchPath { impl fmt::Display for SearchPath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &*self.0 { match &*self.0 {
SearchPathInner::Extra(system_path_buf) SearchPathInner::NonEnvironment(system_path_buf)
| SearchPathInner::FirstParty(system_path_buf) | SearchPathInner::FirstParty(system_path_buf)
| SearchPathInner::SitePackages(system_path_buf) | SearchPathInner::SitePackages(system_path_buf)
| SearchPathInner::Editable(system_path_buf) | SearchPathInner::Editable(system_path_buf)
@ -1073,7 +1076,7 @@ mod tests {
fn relativize_non_stdlib_path_errors() { fn relativize_non_stdlib_path_errors() {
let TestCase { db, src, .. } = TestCaseBuilder::new().build(); let TestCase { db, src, .. } = TestCaseBuilder::new().build();
let root = SearchPath::extra(db.system(), src.clone()).unwrap(); let root = SearchPath::non_environment(db.system(), src.clone()).unwrap();
// Must have a `.py` extension, a `.pyi` extension, or no extension: // Must have a `.py` extension, a `.pyi` extension, or no extension:
let bad_absolute_path = src.join("x.rs"); let bad_absolute_path = src.join("x.rs");
assert_eq!(root.relativize_system_path(&bad_absolute_path), None); assert_eq!(root.relativize_system_path(&bad_absolute_path), None);

View File

@ -228,7 +228,7 @@ impl SearchPaths {
} }
let SearchPathSettings { let SearchPathSettings {
extra_paths, non_environment_paths,
src_roots, src_roots,
custom_typeshed: typeshed, custom_typeshed: typeshed,
site_packages_paths, site_packages_paths,
@ -237,11 +237,11 @@ impl SearchPaths {
let mut static_paths = vec![]; let mut static_paths = vec![];
for path in extra_paths { for path in non_environment_paths {
let path = canonicalize(path, system); let path = canonicalize(path, system);
tracing::debug!("Adding extra search-path `{path}`"); tracing::debug!("Adding non-environment search path `{path}`");
static_paths.push(SearchPath::extra(system, path)?); static_paths.push(SearchPath::non_environment(system, path)?);
} }
for src_root in src_roots { for src_root in src_roots {

View File

@ -110,7 +110,7 @@ pub enum PythonVersionSource {
InstallationDirectoryLayout { site_packages_parent_dir: Box<str> }, InstallationDirectoryLayout { site_packages_parent_dir: Box<str> },
/// The value comes from a CLI argument, while it's left open if specified using a short argument, /// The value comes from a CLI argument, while it's left open if specified using a short argument,
/// long argument (`--extra-paths`) or `--config key=value`. /// long argument (`--non-environment-search-path`) or `--config key=value`.
Cli, Cli,
/// The value comes from the Python VS Code extension (the selected interpreter). /// The value comes from the Python VS Code extension (the selected interpreter).
@ -163,10 +163,10 @@ impl Default for PythonVersionWithSource {
/// Configures the search paths for module resolution. /// Configures the search paths for module resolution.
#[derive(Eq, PartialEq, Debug, Clone)] #[derive(Eq, PartialEq, Debug, Clone)]
pub struct SearchPathSettings { pub struct SearchPathSettings {
/// List of user-provided paths that should take first priority in the module resolution. /// List of user-provided paths that should take first priority in module resolution.
/// Examples in other type checkers are mypy's MYPYPATH environment variable, /// Examples in other type checkers are mypy's `MYPYPATH` environment variable,
/// or pyright's stubPath configuration setting. /// or pyright's `stubPath` configuration setting.
pub extra_paths: Vec<SystemPathBuf>, pub non_environment_paths: Vec<SystemPathBuf>,
/// The root of the project, used for finding first-party modules. /// The root of the project, used for finding first-party modules.
pub src_roots: Vec<SystemPathBuf>, pub src_roots: Vec<SystemPathBuf>,
@ -197,7 +197,7 @@ impl SearchPathSettings {
pub fn empty() -> Self { pub fn empty() -> Self {
SearchPathSettings { SearchPathSettings {
src_roots: vec![], src_roots: vec![],
extra_paths: vec![], non_environment_paths: vec![],
custom_typeshed: None, custom_typeshed: None,
site_packages_paths: vec![], site_packages_paths: vec![],
real_stdlib_path: None, real_stdlib_path: None,

View File

@ -44,8 +44,8 @@ impl MarkdownTestConfig {
self.environment.as_ref()?.typeshed.as_deref() self.environment.as_ref()?.typeshed.as_deref()
} }
pub(crate) fn extra_paths(&self) -> Option<&[SystemPathBuf]> { pub(crate) fn non_environment_paths(&self) -> Option<&[SystemPathBuf]> {
self.environment.as_ref()?.extra_paths.as_deref() self.environment.as_ref()?.non_environment_paths.as_deref()
} }
pub(crate) fn python(&self) -> Option<&SystemPath> { pub(crate) fn python(&self) -> Option<&SystemPath> {
@ -75,7 +75,7 @@ pub(crate) struct Environment {
pub(crate) typeshed: Option<SystemPathBuf>, pub(crate) typeshed: Option<SystemPathBuf>,
/// Additional search paths to consider when resolving modules. /// Additional search paths to consider when resolving modules.
pub(crate) extra_paths: Option<Vec<SystemPathBuf>>, pub(crate) non_environment_paths: Option<Vec<SystemPathBuf>>,
/// Path to the Python environment. /// Path to the Python environment.
/// ///

View File

@ -303,7 +303,10 @@ fn run_test(
.unwrap_or(PythonPlatform::Identifier("linux".to_string())), .unwrap_or(PythonPlatform::Identifier("linux".to_string())),
search_paths: SearchPathSettings { search_paths: SearchPathSettings {
src_roots: vec![src_path], src_roots: vec![src_path],
extra_paths: configuration.extra_paths().unwrap_or_default().to_vec(), non_environment_paths: configuration
.non_environment_paths()
.unwrap_or_default()
.to_vec(),
custom_typeshed: custom_typeshed_path.map(SystemPath::to_path_buf), custom_typeshed: custom_typeshed_path.map(SystemPath::to_path_buf),
site_packages_paths, site_packages_paths,
real_stdlib_path: None, real_stdlib_path: None,

2
ty.schema.json generated
View File

@ -61,7 +61,7 @@
"EnvironmentOptions": { "EnvironmentOptions": {
"type": "object", "type": "object",
"properties": { "properties": {
"extra-paths": { "non-environment-paths": {
"description": "User-provided paths that should take first priority in module resolution.\n\nThis is an advanced option that should usually only be used for first-party or third-party modules that are not installed into your Python environment in a conventional way. Use the `python` option to specify the location of your Python environment.\n\nThis option is similar to mypy's `MYPYPATH` environment variable and pyright's `stubPath` configuration setting.", "description": "User-provided paths that should take first priority in module resolution.\n\nThis is an advanced option that should usually only be used for first-party or third-party modules that are not installed into your Python environment in a conventional way. Use the `python` option to specify the location of your Python environment.\n\nThis option is similar to mypy's `MYPYPATH` environment variable and pyright's `stubPath` configuration setting.",
"type": [ "type": [
"array", "array",