Changed the behavior of the command-line version of pyright when file specs are passed on the command line. Previously, file specs couldn't be used in conjunction with a config file. Now a config file is used, but the specified file specs override the "include" section of the config file.

This commit is contained in:
Eric Traut 2020-09-11 00:27:57 -07:00
parent 43939ada5c
commit 6356575664
3 changed files with 29 additions and 34 deletions

View File

@ -11,23 +11,21 @@ Pyright can be run as either a VS Code extension or as a node-based command-line
| -h, --help | Show help message |
| --lib | Use library code for types when stubs are missing |
| --outputjson | Output results in JSON format |
| -p, --project FILE OR DIRECTORY | Use the configuration file at this location (2) |
| -p, --project FILE OR DIRECTORY | Use the configuration file at this location |
| --stats | Print detailed performance stats |
| -t, --typeshed-path DIRECTORY | Use typeshed type stubs at this location (3) |
| -v, --venv-path DIRECTORY | Directory that contains virtual environments (4) |
| -t, --typeshed-path DIRECTORY | Use typeshed type stubs at this location (2) |
| -v, --venv-path DIRECTORY | Directory that contains virtual environments (3) |
| --verbose | Emit verbose diagnostics |
| --version | Print pyright version |
| -w, --watch | Continue to run and watch for changes (5) |
| -w, --watch | Continue to run and watch for changes (4) |
(1) If specific files are specified on the command line, the pyrightconfig.json file is ignored.
(2) The ”--project” switch cannot be used if individual files are specified.
(2) Pyright has built-in typeshed type stubs for Python stdlib functionality. To use a different version of typeshed type stubs, specify the directory with this option.
(3) Pyright has built-in typeshed type stubs for Python stdlib functionality. To use a different version of typeshed type stubs, specify the directory with this option.
(3) This option is used in conjunction with configuration file, which can refer to different virtual environments by name. For more details, refer to the [configuration](/docs/configuration.md) documentation. This allows a common config file to be checked in to the project and shared by everyone on the development team without making assumptions about the local paths to the venv directory on each developers computer.
(4) This option is used in conjunction with configuration file, which can refer to different virtual environments by name. For more details, refer to the [configuration](/docs/configuration.md) documentation. This allows a common config file to be checked in to the project and shared by everyone on the development team without making assumptions about the local paths to the venv directory on each developers computer.
(5) When running in watch mode, pyright will reanalyze only those files that have been modified. These “deltas” are typically much faster than the initial analysis, which needs to analyze all files in the source tree.
(4) When running in watch mode, pyright will reanalyze only those files that have been modified. These “deltas” are typically much faster than the initial analysis, which needs to analyze all files in the source tree.
# Pyright Exit Codes

View File

@ -396,14 +396,7 @@ export class AnalyzerService {
let projectRoot = commandLineOptions.executionRoot;
let configFilePath: string | undefined;
if (commandLineOptions.fileSpecs && commandLineOptions.fileSpecs.length > 0) {
// If file specs were passed in to the command line, no config file
// will be used. In this case, all file specs are assumed to be
// relative to the current working directory.
if (commandLineOptions.configFilePath) {
this._console.info('Project cannot be mixed with source files on a command line.');
}
} else if (commandLineOptions.configFilePath) {
if (commandLineOptions.configFilePath) {
// If the config file path was specified, determine whether it's
// a directory (in which case the default config file name is assumed)
// or a file.
@ -468,7 +461,8 @@ export class AnalyzerService {
this._typeCheckingMode,
this._console,
commandLineOptions.diagnosticSeverityOverrides,
commandLineOptions.pythonPath
commandLineOptions.pythonPath,
commandLineOptions.fileSpecs.length > 0
);
const configFileDir = getDirectoryPath(configFilePath);

View File

@ -610,24 +610,27 @@ export class ConfigOptions {
typeCheckingMode: string | undefined,
console: ConsoleInterface,
diagnosticOverrides?: DiagnosticSeverityOverridesMap,
pythonPath?: string
pythonPath?: string,
skipIncludeSection = false
) {
// Read the "include" entry.
this.include = [];
if (configObj.include !== undefined) {
if (!Array.isArray(configObj.include)) {
console.error(`Config "include" entry must must contain an array.`);
} else {
const filesList = configObj.include as string[];
filesList.forEach((fileSpec, index) => {
if (typeof fileSpec !== 'string') {
console.error(`Index ${index} of "include" array should be a string.`);
} else if (isAbsolute(fileSpec)) {
console.error(`Ignoring path "${fileSpec}" in "include" array because it is not relative.`);
} else {
this.include.push(getFileSpec(this.projectRoot, fileSpec));
}
});
if (!skipIncludeSection) {
this.include = [];
if (configObj.include !== undefined) {
if (!Array.isArray(configObj.include)) {
console.error(`Config "include" entry must must contain an array.`);
} else {
const filesList = configObj.include as string[];
filesList.forEach((fileSpec, index) => {
if (typeof fileSpec !== 'string') {
console.error(`Index ${index} of "include" array should be a string.`);
} else if (isAbsolute(fileSpec)) {
console.error(`Ignoring path "${fileSpec}" in "include" array because it is not relative.`);
} else {
this.include.push(getFileSpec(this.projectRoot, fileSpec));
}
});
}
}
}