Skip to content

fix: Revert relative path handling for --output #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2023
Merged
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
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