Skip to content

Commit

Permalink
Added code to CLI to verify file specs passed on the command line. If…
Browse files Browse the repository at this point in the history
… they don't exist, emit an error and a non-zero exit code. This addresses #6443.
  • Loading branch information
erictraut committed Nov 14, 2023
1 parent f0aad20 commit 7a4cf3d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/pyright-internal/src/pyright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { createDeferred } from './common/deferred';
import { Diagnostic, DiagnosticCategory } from './common/diagnostic';
import { FileDiagnostics } from './common/diagnosticSink';
import { FullAccessHost } from './common/fullAccessHost';
import { combinePaths, normalizePath } from './common/pathUtils';
import { combinePaths, getFileSpec, normalizePath, tryStat } from './common/pathUtils';
import { versionFromString } from './common/pythonVersion';
import { RealTempFile, createFromRealFileSystem } from './common/realFileSystem';
import { ServiceProvider } from './common/serviceProvider';
Expand Down Expand Up @@ -197,7 +197,7 @@ async function processArgs(): Promise<ExitStatus> {
}
}

if (args['verifytypes'] !== undefined) {
if (args.verifytypes !== undefined) {
const incompatibleArgs = ['watch', 'stats', 'createstub', 'dependencies', 'skipunannotated'];
for (const arg of incompatibleArgs) {
if (args[arg] !== undefined) {
Expand Down Expand Up @@ -241,6 +241,23 @@ async function processArgs(): Promise<ExitStatus> {

options.includeFileSpecsOverride = fileSpecList;
options.includeFileSpecsOverride = options.includeFileSpecsOverride.map((f) => combinePaths(process.cwd(), f));

// Verify the specified file specs to make sure their wildcard roots exist.
const tempFileSystem = new PyrightFileSystem(createFromRealFileSystem());
const tempServiceProvider = createServiceProvider(tempFileSystem, console);

for (const fileDesc of options.includeFileSpecsOverride) {
const includeSpec = getFileSpec(tempServiceProvider, '', fileDesc);
try {
const stat = tryStat(tempFileSystem, includeSpec.wildcardRoot);
if (!stat) {
console.error(`File or directory "${includeSpec.wildcardRoot}" does not exist.`);
return ExitStatus.ParameterError;
}
} catch {
// Ignore exception in this case.
}
}
}

if (args.project) {
Expand Down

0 comments on commit 7a4cf3d

Please sign in to comment.