Skip to content

Commit

Permalink
refactor(manager/pip-compile): Move functionality to common module (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
not7cd authored and Ronald van Butselaar committed Feb 2, 2024
1 parent eae157d commit be35b71
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
49 changes: 7 additions & 42 deletions lib/modules/manager/pip-compile/artifacts.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions lib/modules/manager/pip-compile/common.ts
Original file line number Diff line number Diff line change
@@ -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',
];

0 comments on commit be35b71

Please sign in to comment.