Skip to content
Snippets Groups Projects
Unverified Commit 5cc37ec7 authored by Norbert Szulc's avatar Norbert Szulc Committed by GitHub
Browse files

refactor(manager/pip-compile): Extract getExecOptions method to common (#27149)

parent 7e3c8ca4
No related branches found
Tags 38.39.6
No related merge requests found
......@@ -3,10 +3,8 @@ import upath from 'upath';
import { TEMPORARY_ERROR } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import {
deleteLocalFile,
ensureCacheDir,
readLocalFile,
writeLocalFile,
} from '../../../util/fs';
......@@ -16,8 +14,7 @@ import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
import {
allowedPipArguments,
constraintLineRegex,
getPipToolsConstraint,
getPythonConstraint,
getExecOptions,
} from './common';
export function constructPipCompileCmd(
......@@ -86,25 +83,7 @@ export async function updateArtifacts({
inputFileName,
outputFileName,
);
const constraint = getPythonConstraint(config);
const pipToolsConstraint = getPipToolsConstraint(config);
const execOptions: ExecOptions = {
cwdFile: inputFileName,
docker: {},
toolConstraints: [
{
toolName: 'python',
constraint,
},
{
toolName: 'pip-tools',
constraint: pipToolsConstraint,
},
],
extraEnv: {
PIP_CACHE_DIR: await ensureCacheDir('pip'),
},
};
const execOptions = await getExecOptions(config, inputFileName);
logger.trace({ cmd }, 'pip-compile command');
await exec(cmd, execOptions);
const status = await getRepoStatus();
......
import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import type { ExecOptions } from '../../../util/exec/types';
import { ensureCacheDir } from '../../../util/fs';
import { regEx } from '../../../util/regex';
import type { UpdateArtifactsConfig } from '../types';
......@@ -27,6 +29,32 @@ export function getPipToolsConstraint(config: UpdateArtifactsConfig): string {
return '';
}
export async function getExecOptions(
config: UpdateArtifactsConfig,
inputFileName: string,
): Promise<ExecOptions> {
const constraint = getPythonConstraint(config);
const pipToolsConstraint = getPipToolsConstraint(config);
const execOptions: ExecOptions = {
cwdFile: inputFileName,
docker: {},
toolConstraints: [
{
toolName: 'python',
constraint,
},
{
toolName: 'pip-tools',
constraint: pipToolsConstraint,
},
],
extraEnv: {
PIP_CACHE_DIR: await ensureCacheDir('pip'),
},
};
return execOptions;
}
export const constraintLineRegex = regEx(
/^(#.*?\r?\n)+# {4}pip-compile(?<arguments>.*?)\r?\n/,
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment