Skip to content

Commit

Permalink
feat(manager/poetry): support buildpack (#17002)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 5, 2022
1 parent 5138dae commit 6d426a0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
12 changes: 6 additions & 6 deletions lib/modules/manager/poetry/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -112,19 +112,19 @@ Array [
exports[`modules/manager/poetry/artifacts returns updated poetry.lock using docker (constraints) 1`] = `
Array [
Object {
"cmd": "docker pull renovate/python:2.7.5",
"cmd": "docker pull renovate/sidecar",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker ps --filter name=renovate_python -aq",
"cmd": "docker ps --filter name=renovate_sidecar -aq",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker run --rm --name=renovate_python --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/python:2.7.5 bash -l -c \\"install-tool poetry 1.2.0 && poetry update --lock --no-interaction dep1\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 1.2.0 && pip install --user 'poetry>=1.0' && poetry update --lock --no-interaction dep1\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -148,19 +148,19 @@ Array [
exports[`modules/manager/poetry/artifacts returns updated poetry.lock using docker 1`] = `
Array [
Object {
"cmd": "docker pull renovate/python:3.4.2",
"cmd": "docker pull renovate/sidecar",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker ps --filter name=renovate_python -aq",
"cmd": "docker ps --filter name=renovate_sidecar -aq",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker run --rm --name=renovate_python --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/python:3.4.2 bash -l -c \\"install-tool poetry 1.2.0 && poetry update --lock --no-interaction dep1\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 1.2.0 && pip install --user 'poetry>=1.0' && poetry update --lock --no-interaction dep1\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
53 changes: 53 additions & 0 deletions lib/modules/manager/poetry/artifacts.spec.ts
Expand Up @@ -19,6 +19,8 @@ jest.mock('../../../util/exec/env');
jest.mock('../../datasource');
jest.mock('../../../util/host-rules');

process.env.BUILDPACK = 'true';

const fs: jest.Mocked<typeof _fs> = _fs as any;
const datasource = mocked(_datasource);
const hostRules = mocked(_hostRules);
Expand Down Expand Up @@ -233,6 +235,57 @@ describe('modules/manager/poetry/artifacts', () => {
expect(execSnapshots).toMatchSnapshot();
});

it('returns updated poetry.lock using install mode', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
// poetry.lock
fs.readFile.mockResolvedValueOnce(
'[metadata]\npython-versions = "~2.7 || ^3.4"' as any
);
const execSnapshots = mockExecAll();
fs.readFile.mockReturnValueOnce('New poetry.lock' as any);
// poetry
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.0.0' },
{ version: '1.1.0' },
{ version: '1.2.0' },
],
});
// python
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '2.7.5' }, { version: '3.3.2' }],
});
const updatedDeps = [{ depName: 'dep1' }];
expect(
await updateArtifacts({
packageFileName: 'pyproject.toml',
updatedDeps,
newPackageFileContent: pyproject1toml,
config: {
...config,
constraints: {},
},
})
).toEqual([
{
file: {
type: 'addition',
path: 'poetry.lock',
contents: 'New poetry.lock',
},
},
]);

expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool python 1.2.0' },
{ cmd: "pip install --user 'poetry>=1.0'" },
{
cmd: 'poetry update --lock --no-interaction dep1',
options: { cwd: '/tmp/github/some/repo' },
},
]);
});

it('catches errors', async () => {
fs.readFile.mockResolvedValueOnce('Current poetry.lock' as any);
fs.outputFile.mockImplementationOnce(() => {
Expand Down
19 changes: 8 additions & 11 deletions lib/modules/manager/poetry/artifacts.ts
Expand Up @@ -5,7 +5,7 @@ import { TEMPORARY_ERROR } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { HostRule } from '../../../types';
import { exec } from '../../../util/exec';
import type { ExecOptions, ToolConstraint } from '../../../util/exec/types';
import type { ExecOptions } from '../../../util/exec/types';
import {
deleteLocalFile,
getSiblingFileName,
Expand Down Expand Up @@ -172,27 +172,24 @@ export async function updateArtifacts({
.join(' ')}`
);
}
const tagConstraint = getPythonConstraint(existingLockFileContent, config);
const constraint =
const constraint = getPythonConstraint(existingLockFileContent, config);
const poetryVersion =
config.constraints?.poetry ?? getPoetryRequirement(newPackageFileContent);
const extraEnv = getSourceCredentialVars(
newPackageFileContent,
packageFileName
);
const toolConstraint: ToolConstraint = {
toolName: 'poetry',
constraint,
};

const execOptions: ExecOptions = {
cwdFile: packageFileName,
extraEnv,
docker: {
image: 'python',
tagConstraint,
tagScheme: 'poetry',
image: 'sidecar',
},
toolConstraints: [toolConstraint],
toolConstraints: [{ toolName: 'python', constraint }],
preCommands: [
`pip install --user ${quote(`poetry${poetryVersion ?? ''}`)}`,
],
};
await exec(cmd, execOptions);
const newPoetryLockContent = await readLocalFile(lockFileName, 'utf8');
Expand Down

0 comments on commit 6d426a0

Please sign in to comment.