Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 21 additions & 21 deletions docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ Pyright can be run as either a VS Code extension or as a node-based command-line

| Flag | Description |
| :--------------------------------- | :--------------------------------------------------- |
| --createstub `<IMPORT>` | Create type stub file(s) for import |
| --dependencies | Emit import dependency information |
| -h, --help | Show help message |
| --ignoreexternal | Ignore external imports for --verifytypes |
| --level <LEVEL> | Minimum diagnostic level (error or warning) |
| --outputjson | Output results in JSON format |
| -p, --project `<FILE OR DIRECTORY>` | Use the configuration file at this location |
| --pythonpath `<FILE>` | Path to the Python interpreter (2) |
| --pythonplatform `<PLATFORM>` | Analyze for platform (Darwin, Linux, Windows) |
| --pythonversion `<VERSION>` | Analyze for version (3.3, 3.4, etc.) |
| --skipunannotated | Skip type analysis of unannotated functions |
| --stats | Print detailed performance stats |
| -t, --typeshedpath `<DIRECTORY>` | Use typeshed type stubs at this location (3) |
| --threads <optional N> | Use up to N threads to parallelize type checking (4) |
| -v, --venvpath `<DIRECTORY>` | Directory that contains virtual environments (5) |
| --verbose | Emit verbose diagnostics |
| --verifytypes `<IMPORT>` | Verify completeness of types in py.typed package |
| --version | Print pyright version and exit |
| --warnings | Use exit code of 1 if warnings are reported |
| -w, --watch | Continue to run and watch for changes (6) |
| - | Read file or directory list from stdin |
| --createstub `<IMPORT>` | Create type stub file(s) for import |
| --dependencies | Emit import dependency information |
| -h, --help | Show help message |
| --ignoreexternal | Ignore external imports for --verifytypes |
| --level <LEVEL> | Minimum diagnostic level (error or warning) |
| --outputjson | Output results in JSON format |
| -p, --project `<FILE OR DIRECTORY>` | Use the configuration file at this location |
| --pythonpath `<FILE>` | Path to the Python interpreter (2) |
| --pythonplatform `<PLATFORM>` | Analyze for platform (Darwin, Linux, Windows, iOS, Android) |
| --pythonversion `<VERSION>` | Analyze for version (3.3, 3.4, etc.) |
| --skipunannotated | Skip type analysis of unannotated functions |
| --stats | Print detailed performance stats |
| -t, --typeshedpath `<DIRECTORY>` | Use typeshed type stubs at this location (3) |
| --threads <optional N> | Use up to N threads to parallelize type checking (4) |
| -v, --venvpath `<DIRECTORY>` | Directory that contains virtual environments (5) |
| --verbose | Emit verbose diagnostics |
| --verifytypes `<IMPORT>` | Verify completeness of types in py.typed package |
| --version | Print pyright version and exit |
| --warnings | Use exit code of 1 if warnings are reported |
| -w, --watch | Continue to run and watch for changes (6) |
| - | Read file or directory list from stdin |

(1) If specific files are specified on the command line, it overrides the files or directories specified in the pyrightconfig.json or pyproject.toml file.

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The following settings control the *environment* in which Pyright will check for

- **pythonVersion** [string, optional]: Specifies the version of Python that will be used to execute the source code. The version should be specified as a string in the format "M.m" where M is the major version and m is the minor (e.g. `"3.0"` or `"3.6"`). If a version is provided, pyright will generate errors if the source code makes use of language features that are not supported in that version. It will also tailor its use of type stub files, which conditionalizes type definitions based on the version. If no version is specified, pyright will use the version of the current python interpreter, if one is present.

- **pythonPlatform** [string, optional]: Specifies the target platform that will be used to execute the source code. Should be one of `"Windows"`, `"Darwin"`, `"Linux"`, or `"All"`. If specified, pyright will tailor its use of type stub files, which conditionalize type definitions based on the platform. If no platform is specified, pyright will use the current platform.
- **pythonPlatform** [string, optional]: Specifies the target platform that will be used to execute the source code. Should be one of `"Windows"`, `"Darwin"`, `"Linux"`, `"iOS"`, `"Android"`, or `"All"`. If specified, pyright will tailor its use of type stub files, which conditionalize type definitions based on the platform. If no platform is specified, pyright will use the current platform.

- **executionEnvironments** [array of objects, optional]: Specifies a list of execution environments (see [below](configuration.md#execution-environment-options)). Execution environments are searched from start to finish by comparing the path of a source file with the root path specified in the execution environment.

Expand Down
13 changes: 13 additions & 0 deletions packages/pyright-internal/src/analyzer/staticExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ function _getExpectedPlatformNameFromPlatform(execEnv: ExecutionEnvironment): st
return 'win32';
} else if (execEnv.pythonPlatform === PythonPlatform.Linux) {
return 'linux';
} else if (execEnv.pythonPlatform === PythonPlatform.iOS) {
return 'ios';
} else if (execEnv.pythonPlatform === PythonPlatform.Android) {
// Python >= 3.13 reports Android as 'android', earlier used to report it as 'linux'
if (execEnv.pythonVersion.major === 3 && execEnv.pythonVersion.minor >= 13) {
return 'android';
} else {
return 'linux';
}
}

return undefined;
Expand All @@ -357,6 +366,10 @@ function _getExpectedOsNameFromPlatform(execEnv: ExecutionEnvironment): string |
return 'nt';
} else if (execEnv.pythonPlatform === PythonPlatform.Linux) {
return 'posix';
} else if (execEnv.pythonPlatform === PythonPlatform.iOS) {
return 'posix';
} else if (execEnv.pythonPlatform === PythonPlatform.Android) {
return 'posix';
}

return undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/common/commandLineOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class CommandLineConfigOptions {
// Name for the virtual environment.
pythonEnvironmentName?: string | undefined;

// Python platform indicator (darwin, linux, win32)
pythonPlatform?: 'Darwin' | 'Linux' | 'Windows' | undefined;
// Python platform indicator (darwin, linux, win32, ios, android)
pythonPlatform?: 'Darwin' | 'Linux' | 'Windows' | 'iOS' | 'Android' | undefined;

// Python version string (3.3, 3.4, etc.)
pythonVersion?: PythonVersion | undefined;
Expand Down
2 changes: 2 additions & 0 deletions packages/pyright-internal/src/common/configOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export enum PythonPlatform {
Darwin = 'Darwin',
Windows = 'Windows',
Linux = 'Linux',
iOS = 'iOS',
Android = 'Android',
}

export class ExecutionEnvironment {
Expand Down
2 changes: 2 additions & 0 deletions packages/pyright-internal/src/common/fullAccessHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class LimitedAccessHost extends NoAccessHost {
return PythonPlatform.Linux;
} else if (process.platform === 'win32') {
return PythonPlatform.Windows;
} else if (process.platform === 'android') {
return PythonPlatform.Android;
}

return undefined;
Expand Down
7 changes: 4 additions & 3 deletions packages/pyright-internal/src/pyright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ async function processArgs(): Promise<ExitStatus> {
}

if (args.pythonplatform) {
if (args.pythonplatform === 'Darwin' || args.pythonplatform === 'Linux' || args.pythonplatform === 'Windows') {
if (args.pythonplatform === 'Darwin' || args.pythonplatform === 'Linux' || args.pythonplatform === 'Windows' ||
args.pythonplatform === 'iOS' || args.pythonplatform === 'Android') {
options.configSettings.pythonPlatform = args.pythonplatform;
} else {
console.error(
`'${args.pythonplatform}' is not a supported Python platform; specify Darwin, Linux, or Windows`
`'${args.pythonplatform}' is not a supported Python platform; specify Darwin, Linux, Windows, iOS, or Android.`
);
return ExitStatus.ParameterError;
}
Expand Down Expand Up @@ -1129,7 +1130,7 @@ function printUsage() {
' --level <LEVEL> Minimum diagnostic level (error or warning)\n' +
' --outputjson Output results in JSON format\n' +
' -p,--project <FILE OR DIRECTORY> Use the configuration file at this location\n' +
' --pythonplatform <PLATFORM> Analyze for a specific platform (Darwin, Linux, Windows)\n' +
' --pythonplatform <PLATFORM> Analyze for a specific platform (Darwin, Linux, Windows, iOS, Android)\n' +
' --pythonpath <FILE> Path to the Python interpreter\n' +
' --pythonversion <VERSION> Analyze for a specific version (3.3, 3.4, etc.)\n' +
' --skipunannotated Skip analysis of functions with no type annotations\n' +
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-pyright/schemas/pyrightconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"examples": [
"Linux"
],
"pattern": "^(Linux|Windows|Darwin|All)$"
"pattern": "^(Linux|Windows|Darwin|iOS|Android|All)$"
},
"disableBytesTypePromotions": {
"type": "boolean",
Expand Down