Skip to content

Commit

Permalink
refactor(manager/pip-compile): Move generateMermaidGraph (#27311)
Browse files Browse the repository at this point in the history
  • Loading branch information
not7cd committed Feb 15, 2024
1 parent 09ad053 commit 31dd766
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
24 changes: 1 addition & 23 deletions lib/modules/manager/pip-compile/common.ts
Expand Up @@ -7,11 +7,7 @@ import { ensureCacheDir } from '../../../util/fs';
import * as hostRules from '../../../util/host-rules';
import { regEx } from '../../../util/regex';
import type { PackageFileContent, UpdateArtifactsConfig } from '../types';
import type {
DependencyBetweenFiles,
GetRegistryUrlVarsResult,
PipCompileArgs,
} from './types';
import type { GetRegistryUrlVarsResult, PipCompileArgs } from './types';

export function getPythonConstraint(
config: UpdateArtifactsConfig,
Expand Down Expand Up @@ -217,24 +213,6 @@ function throwForUnknownOption(arg: string): void {
throw new Error(`Option ${arg} not supported (yet)`);
}

export function generateMermaidGraph(
depsBetweenFiles: DependencyBetweenFiles[],
lockFileArgs: Map<string, PipCompileArgs>,
): string {
const lockFiles = [];
for (const lockFile of lockFileArgs.keys()) {
// TODO: add extra args to the lock file ${extraArgs ? '\n' + extraArgs : ''}
// const extraArgs = pipCompileArgs.extra
// ?.map((v) => '--extra=' + v)
// .join('\n');
lockFiles.push(` ${lockFile}[[${lockFile}]]`);
}
const edges = depsBetweenFiles.map(({ sourceFile, outputFile, type }) => {
return ` ${sourceFile} -${type === 'constraint' ? '.' : ''}-> ${outputFile}`;
});
return `graph TD\n${lockFiles.join('\n')}\n${edges.join('\n')}`;
}

function buildRegistryUrl(url: string): URL | null {
try {
const ret = new URL(url);
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/pip-compile/extract.ts
Expand Up @@ -3,12 +3,13 @@ import { readLocalFile } from '../../../util/fs';
import { extractPackageFile as extractRequirementsFile } from '../pip_requirements/extract';
import { extractPackageFile as extractSetupPyFile } from '../pip_setup';
import type { ExtractConfig, PackageFile, PackageFileContent } from '../types';
import { extractHeaderCommand, generateMermaidGraph } from './common';
import { extractHeaderCommand } from './common';
import type {
DependencyBetweenFiles,
PipCompileArgs,
SupportedManagers,
} from './types';
import { generateMermaidGraph } from './utils';

function matchManager(filename: string): SupportedManagers | 'unknown' {
if (filename.endsWith('setup.py')) {
Expand Down
19 changes: 19 additions & 0 deletions lib/modules/manager/pip-compile/utils.ts
@@ -0,0 +1,19 @@
import type { DependencyBetweenFiles, PipCompileArgs } from './types';

export function generateMermaidGraph(
depsBetweenFiles: DependencyBetweenFiles[],
lockFileArgs: Map<string, PipCompileArgs>,
): string {
const lockFiles = [];
for (const lockFile of lockFileArgs.keys()) {
// TODO: add extra args to the lock file ${extraArgs ? '\n' + extraArgs : ''}
// const extraArgs = pipCompileArgs.extra
// ?.map((v) => '--extra=' + v)
// .join('\n');
lockFiles.push(` ${lockFile}[[${lockFile}]]`);
}
const edges = depsBetweenFiles.map(({ sourceFile, outputFile, type }) => {
return ` ${sourceFile} -${type === 'constraint' ? '.' : ''}-> ${outputFile}`;
});
return `graph TD\n${lockFiles.join('\n')}\n${edges.join('\n')}`;
}

0 comments on commit 31dd766

Please sign in to comment.