diff --git a/lib/modules/manager/pip-compile/artifacts.ts b/lib/modules/manager/pip-compile/artifacts.ts index c62860ef329aa13849a4eeeec5f0bbc47c469d07..baad6550c798d41fbf196ab14e51556dfb0a4082 100644 --- a/lib/modules/manager/pip-compile/artifacts.ts +++ b/lib/modules/manager/pip-compile/artifacts.ts @@ -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(); diff --git a/lib/modules/manager/pip-compile/common.ts b/lib/modules/manager/pip-compile/common.ts index d17dfdad7d390a53aced473b3789434c9f9ffd41..83d866fb0c97c9eb2e8f00326cabdc65e5d35bd3 100644 --- a/lib/modules/manager/pip-compile/common.ts +++ b/lib/modules/manager/pip-compile/common.ts @@ -1,5 +1,7 @@ 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/, );