Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(manager/pip-compile): Move functionality to common module #26873

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
];