Skip to content

Commit

Permalink
refactor(manager/pip-compile): Rename results of extractHeaderCommand (
Browse files Browse the repository at this point in the history
  • Loading branch information
not7cd committed Feb 15, 2024
1 parent b31d6d1 commit bd9fb30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions lib/modules/manager/pip-compile/artifacts.ts
Expand Up @@ -22,27 +22,27 @@ export function constructPipCompileCmd(
outputFileName: string,
haveCredentials: boolean,
): string {
const headerArguments = extractHeaderCommand(content, outputFileName);
if (headerArguments.isCustomCommand) {
const compileArgs = extractHeaderCommand(content, outputFileName);
if (compileArgs.isCustomCommand) {
throw new Error(
'Detected custom command, header modified or set by CUSTOM_COMPILE_COMMAND',
);
}
if (headerArguments.outputFile) {
if (compileArgs.outputFile) {
// TODO(not7cd): This file path can be relative like `reqs/main.txt`
const file = upath.parse(outputFileName).base;
if (headerArguments.outputFile !== file) {
if (compileArgs.outputFile !== file) {
// we don't trust the user-supplied output-file argument;
// TODO(not7cd): allow relative paths
logger.warn(
{ outputFile: headerArguments.outputFile, actualPath: file },
{ outputFile: compileArgs.outputFile, actualPath: file },
'pip-compile was previously executed with an unexpected `--output-file` filename',
);
// TODO(not7cd): this shouldn't be changed in extract function
headerArguments.outputFile = file;
headerArguments.argv.forEach((item, i) => {
compileArgs.outputFile = file;
compileArgs.argv.forEach((item, i) => {
if (item.startsWith('--output-file=')) {
headerArguments.argv[i] = `--output-file=${quote(file)}`;
compileArgs.argv[i] = `--output-file=${quote(file)}`;
}
});
}
Expand All @@ -51,12 +51,12 @@ export function constructPipCompileCmd(
}
// safeguard against index url leak if not explicitly set by an option
if (
(!headerArguments.noEmitIndexUrl && !headerArguments.emitIndexUrl) ||
(!headerArguments.noEmitIndexUrl && haveCredentials)
(!compileArgs.noEmitIndexUrl && !compileArgs.emitIndexUrl) ||
(!compileArgs.noEmitIndexUrl && haveCredentials)
) {
headerArguments.argv.splice(1, 0, '--no-emit-index-url');
compileArgs.argv.splice(1, 0, '--no-emit-index-url');
}
return headerArguments.argv.map(quote).join(' ');
return compileArgs.argv.map(quote).join(' ');
}

export async function updateArtifacts({
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/manager/pip-compile/extract.ts
Expand Up @@ -69,18 +69,18 @@ export async function extractAllPackageFiles(
logger.debug(`pip-compile: no content found for fileMatch ${fileMatch}`);
continue;
}
let pipCompileArgs: PipCompileArgs;
let compileArgs: PipCompileArgs;
try {
pipCompileArgs = extractHeaderCommand(fileContent, fileMatch);
lockFileArgs.set(fileMatch, pipCompileArgs);
compileArgs = extractHeaderCommand(fileContent, fileMatch);
lockFileArgs.set(fileMatch, compileArgs);
} catch (error) {
logger.warn(
{ fileMatch, error },
'pip-compile: Failed to extract and parse command in output file header',
);
continue;
}
for (const constraint in pipCompileArgs.constraintsFiles) {
for (const constraint in compileArgs.constraintsFiles) {
// TODO(not7cd): handle constraints
/* istanbul ignore next */
depsBetweenFiles.push({
Expand All @@ -91,7 +91,7 @@ export async function extractAllPackageFiles(
}
// TODO(not7cd): handle locked deps
// const lockedDeps = extractRequirementsFile(content);
for (const packageFile of pipCompileArgs.sourceFiles) {
for (const packageFile of compileArgs.sourceFiles) {
depsBetweenFiles.push({
sourceFile: packageFile,
outputFile: fileMatch,
Expand Down

0 comments on commit bd9fb30

Please sign in to comment.