From a3f82cf0646e85290009545fc4e14522f408504c Mon Sep 17 00:00:00 2001 From: Norbert Szulc <norbert@icetek.io> Date: Fri, 26 Jan 2024 18:41:23 +0100 Subject: [PATCH] refactor(manager/pip-compile): Move functionality to common module (#26873) --- lib/modules/manager/pip-compile/artifacts.ts | 49 +++----------------- lib/modules/manager/pip-compile/common.ts | 38 +++++++++++++++ 2 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 lib/modules/manager/pip-compile/common.ts diff --git a/lib/modules/manager/pip-compile/artifacts.ts b/lib/modules/manager/pip-compile/artifacts.ts index 15b51aa9fc..c62860ef32 100644 --- a/lib/modules/manager/pip-compile/artifacts.ts +++ b/lib/modules/manager/pip-compile/artifacts.ts @@ -1,4 +1,3 @@ -import is from '@sindresorhus/is'; import { quote, split } from 'shlex'; import upath from 'upath'; import { TEMPORARY_ERROR } from '../../../constants/error-messages'; @@ -13,47 +12,13 @@ import { } from '../../../util/fs'; import { getRepoStatus } from '../../../util/git'; import { regEx } from '../../../util/regex'; -import type { - UpdateArtifact, - UpdateArtifactsConfig, - UpdateArtifactsResult, -} from '../types'; - -function getPythonConstraint( - config: UpdateArtifactsConfig, -): string | undefined | null { - const { constraints = {} } = config; - const { python } = constraints; - - if (python) { - logger.debug('Using python constraint from config'); - return python; - } - - return undefined; -} - -function getPipToolsConstraint(config: UpdateArtifactsConfig): string { - const { constraints = {} } = config; - const { pipTools } = constraints; - - if (is.string(pipTools)) { - logger.debug('Using pipTools constraint from config'); - return pipTools; - } - - return ''; -} - -const constraintLineRegex = regEx( - /^(#.*?\r?\n)+# {4}pip-compile(?<arguments>.*?)\r?\n/, -); -const allowedPipArguments = [ - '--allow-unsafe', - '--generate-hashes', - '--no-emit-index-url', - '--strip-extras', -]; +import type { UpdateArtifact, UpdateArtifactsResult } from '../types'; +import { + allowedPipArguments, + constraintLineRegex, + getPipToolsConstraint, + getPythonConstraint, +} from './common'; export function constructPipCompileCmd( content: string, diff --git a/lib/modules/manager/pip-compile/common.ts b/lib/modules/manager/pip-compile/common.ts new file mode 100644 index 0000000000..d17dfdad7d --- /dev/null +++ b/lib/modules/manager/pip-compile/common.ts @@ -0,0 +1,38 @@ +import is from '@sindresorhus/is'; +import { logger } from '../../../logger'; +import { regEx } from '../../../util/regex'; +import type { UpdateArtifactsConfig } from '../types'; + +export function getPythonConstraint( + config: UpdateArtifactsConfig, +): string | undefined | null { + const { constraints = {} } = config; + const { python } = constraints; + + if (python) { + logger.debug('Using python constraint from config'); + return python; + } + + return undefined; +} +export function getPipToolsConstraint(config: UpdateArtifactsConfig): string { + const { constraints = {} } = config; + const { pipTools } = constraints; + + if (is.string(pipTools)) { + logger.debug('Using pipTools constraint from config'); + return pipTools; + } + + return ''; +} +export const constraintLineRegex = regEx( + /^(#.*?\r?\n)+# {4}pip-compile(?<arguments>.*?)\r?\n/, +); +export const allowedPipArguments = [ + '--allow-unsafe', + '--generate-hashes', + '--no-emit-index-url', + '--strip-extras', +]; -- GitLab