Skip to content

Commit

Permalink
fix: Revert relative path handling for --output (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Sep 8, 2023
1 parent 9a052a5 commit 029e3d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/pyright-scip/src/MainCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export function mainCommand(
.option('--project-namespace <namespace>', 'A prefix to prepend to all module definitions in the current index')
.option('--cwd <path>', 'working directory for executing scip-python', process.cwd())
.option('--target-only <path>', 'limit analysis to the following path')
.option('--output <path>', 'path to the output file', DEFAULT_OUTPUT_FILE)
.option(
'--output <path>',
'Path to the output file. If this path is relative, it is interpreted relative to the value for --cwd.',
DEFAULT_OUTPUT_FILE
)
.option('--quiet', 'run without logging and status information', false)
.option(
'--show-progress-rate-limit <limit>',
Expand All @@ -85,7 +89,11 @@ export function mainCommand(
.option('--only <name>', 'only generate snapshots for <name>')
.requiredOption('--project-name <name>', 'the name of the current project, pypi name if applicable')
.requiredOption('--project-version <version>', 'the name of the current project, pypi name if applicable')
.option('--output <path>', 'path to the output file', DEFAULT_OUTPUT_FILE)
.option(
'--output <path>',
'Path to the output file. If this path is relative, it is interpreted relative to the value for --cwd.',
DEFAULT_OUTPUT_FILE
)
.option('--environment <json-file>', 'the environment json file (experimental)')
.option('--no-index', 'skip indexing (use existing index.scip)')
.option('--quiet', 'run without logging and status information', false)
Expand Down
8 changes: 7 additions & 1 deletion packages/pyright-scip/src/main-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ function indexAction(options: IndexOptions): void {
const originalWorkdir = process.cwd();
process.chdir(projectRoot);

const outputFile = path.isAbsolute(options.output) ? options.output : path.join(originalWorkdir, options.output);
// In the relative path case, we use projectRoot rather than
// originalWorkdir because:
// 1. To preserve back-compat in case anyone is relying on projectRoot
// 2. The actual CLI flag for specifying the project root is --cwd,
// which may lead to the expectation that output is considered
// relative to the project root.
const outputFile = path.isAbsolute(options.output) ? options.output : path.join(projectRoot, options.output);
const output = fs.openSync(outputFile, 'w');

try {
Expand Down

0 comments on commit 029e3d8

Please sign in to comment.