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

feat(pipenv): Use @renovatebot/detect-tools for constraints detection #29787

Merged
merged 33 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a372e10
test(pipenv): Rewrite test mocks
zharinov Jun 18, 2024
64715d7
Merge branch 'main' into refactor/pipenv-artifact-tests
zharinov Jun 18, 2024
13551c8
Merge branch 'main' into refactor/pipenv-artifact-tests
zharinov Jun 18, 2024
fcc7ad6
Merge branch 'main' into refactor/pipenv-artifact-tests
zharinov Jun 18, 2024
a40af9e
Specify which files to mock
zharinov Jun 18, 2024
eddd30f
Fix mock helper
zharinov Jun 18, 2024
4941ab2
Fix mock helper
zharinov Jun 18, 2024
5103858
Fix
zharinov Jun 20, 2024
08e23fc
Merge branch 'main' into refactor/pipenv-artifact-tests
zharinov Jun 20, 2024
59d151e
feat(pipenv): Use "@renovatebot/detect-tools" for constraints detection
zharinov Jun 20, 2024
777842b
Add package
zharinov Jul 1, 2024
7674413
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Jul 1, 2024
2e33fe9
Remove unused schema
zharinov Jul 1, 2024
ba95f6f
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Jul 1, 2024
c799740
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Jul 2, 2024
c25f822
Revert unrelated changes
zharinov Jul 2, 2024
f8daf96
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Jul 3, 2024
86d7b8d
Fix lockfile
zharinov Jul 3, 2024
5294e9d
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Jul 15, 2024
ba5d3e9
Bump `detect-tools`
zharinov Jul 15, 2024
5027064
Fix import
zharinov Jul 15, 2024
6d9c682
Revert unrelated lockfile change
zharinov Jul 15, 2024
8f89d27
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Jul 23, 2024
7c571c4
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Aug 4, 2024
e4f36c2
Revert unrelated lockfile change
zharinov Jul 15, 2024
41bc897
Bump to 1.0.3
zharinov Aug 4, 2024
b941708
Return type constraints
zharinov Aug 4, 2024
97df9dc
Apply suggestions from code review
zharinov Aug 5, 2024
e70a63c
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Aug 5, 2024
bc852b4
Use `detect-tools` in the extract phase
zharinov Aug 6, 2024
073a207
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Aug 6, 2024
af430ce
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Aug 11, 2024
af72b37
Merge branch 'main' into feat/pipenv-to-use-detect-tools
zharinov Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 57 additions & 16 deletions lib/modules/manager/pipenv/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
extractEnvironmentVariableName,
getMatchingHostRule,
} from './artifacts';
import type { PipfileLockSchema } from './schema';
zharinov marked this conversation as resolved.
Show resolved Hide resolved
import { updateArtifacts } from '.';

const datasource = mocked(_datasource);
Expand Down Expand Up @@ -128,13 +127,14 @@ describe('modules/manager/pipenv/artifacts', () => {

it('returns null if unchanged', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': JSON.stringify({
_meta: {
requires: { python_full_version: '3.7.6' },
},
} satisfies PipfileLockSchema),
}),
});
const execSnapshots = mockExecAll();

Expand Down Expand Up @@ -165,19 +165,23 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('gets python full version from Pipfile', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile': Fixtures.get('Pipfile1'),
'/Pipfile.lock': JSON.stringify({
_meta: {
requires: { python_full_version: '3.7.6' },
},
} satisfies PipfileLockSchema),
}),
});

fsExtra.ensureDir.mockResolvedValue(undefined as never);
Expand Down Expand Up @@ -213,19 +217,22 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('gets python version from Pipfile', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile': Fixtures.get('Pipfile2'),
'/Pipfile.lock': JSON.stringify({
_meta: {
requires: { python_full_version: '3.7.6' },
},
} satisfies PipfileLockSchema),
}),
});

fsExtra.ensureDir.mockResolvedValue(undefined as never);
Expand Down Expand Up @@ -261,12 +268,14 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('gets full python version from .python-version', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': '{}',
Expand Down Expand Up @@ -306,13 +315,16 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('gets python stream, from .python-version', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fsExtra.stat.mockResolvedValueOnce({} as never);

fsExtra.ensureDir.mockResolvedValue(undefined as never);

Expand Down Expand Up @@ -351,13 +363,16 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('handles no constraint', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': 'unparseable pipfile lock',
Expand Down Expand Up @@ -394,12 +409,16 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('returns updated Pipfile.lock', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': ['current pipfile.lock', 'new pipfile.lock'],
Expand Down Expand Up @@ -448,19 +467,23 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('supports docker mode', async () => {
GlobalConfig.set(dockerAdminConfig);
fsExtra.stat.mockResolvedValueOnce({} as never);

const pipFileLock = JSON.stringify({
_meta: { requires: { python_version: '3.7' } },
} satisfies PipfileLockSchema);
});
mockFiles({
'/Pipfile.lock': [pipFileLock, 'new lock'],
'/Pipfile.lock': [pipFileLock, pipFileLock, 'new lock'],
});

fsExtra.ensureDir.mockResolvedValue(undefined as never);
Expand Down Expand Up @@ -523,17 +546,20 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('supports install mode', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fsExtra.stat.mockResolvedValueOnce({} as never);

const pipFileLock = JSON.stringify({
_meta: { requires: { python_version: '3.6' } },
} satisfies PipfileLockSchema);
});
mockFiles({
'/Pipfile.lock': [pipFileLock, 'new lock'],
});
Expand Down Expand Up @@ -582,13 +608,16 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('defaults to latest if no lock constraints', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fsExtra.stat.mockResolvedValueOnce({} as never);
fsExtra.ensureDir.mockResolvedValue(undefined as never);

mockFiles({
Expand Down Expand Up @@ -637,14 +666,17 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('catches errors', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': 'Current Pipfile.lock',
Expand All @@ -666,13 +698,12 @@ describe('modules/manager/pipenv/artifacts', () => {
]);

expect(fsExtra.ensureDir.mock.calls).toEqual([]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
expect(fsExtra.readFile.mock.calls).toEqual([]);
});

it('returns updated Pipenv.lock when doing lockfile maintenance', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': ['Current Pipfile.lock', 'New Pipfile.lock'],
Expand Down Expand Up @@ -711,14 +742,15 @@ describe('modules/manager/pipenv/artifacts', () => {

it('uses pipenv version from Pipfile', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

GlobalConfig.set(dockerAdminConfig);

const oldLock = JSON.stringify({
default: { pipenv: { version: '==2020.8.13' } },
} satisfies PipfileLockSchema);
});
mockFiles({
'/Pipfile.lock': [oldLock, 'new lock'],
'/Pipfile.lock': [oldLock, oldLock, 'new lock'],
});

const execSnapshots = mockExecAll();
Expand Down Expand Up @@ -774,22 +806,25 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('uses pipenv version from Pipfile dev packages', async () => {
GlobalConfig.set(dockerAdminConfig);
fsExtra.stat.mockResolvedValueOnce({} as never);

fsExtra.ensureDir.mockResolvedValue(undefined as never);

const oldLock = JSON.stringify({
develop: { pipenv: { version: '==2020.8.13' } },
} satisfies PipfileLockSchema) as never;
}) as never;
mockFiles({
'/Pipfile.lock': [oldLock, 'new lock'],
'/Pipfile.lock': [oldLock, oldLock, 'new lock'],
});

const execSnapshots = mockExecAll();
Expand Down Expand Up @@ -845,19 +880,22 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
]);
});

it('uses pipenv version from config', async () => {
GlobalConfig.set(dockerAdminConfig);
fsExtra.stat.mockResolvedValueOnce({} as never);
fsExtra.ensureDir.mockResolvedValue(undefined as never);

const oldLock = JSON.stringify({
default: { pipenv: { version: '==2020.8.13' } },
} satisfies PipfileLockSchema) as never;
}) as never;
zharinov marked this conversation as resolved.
Show resolved Hide resolved
mockFiles({
'/Pipfile.lock': [oldLock, 'new lock'],
});
Expand Down Expand Up @@ -915,6 +953,7 @@ describe('modules/manager/pipenv/artifacts', () => {
[expect.toEndWith(join('/tmp/renovate/cache/others/virtualenvs'))],
]);
expect(fsExtra.readFile.mock.calls).toEqual([
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/.python-version')), 'utf8'],
[expect.toEndWith(join('/tmp/github/some/repo/Pipfile.lock')), 'utf8'],
Expand All @@ -923,6 +962,7 @@ describe('modules/manager/pipenv/artifacts', () => {

it('passes private credential environment vars', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': ['current Pipfile.lock', 'New Pipfile.lock'],
Expand Down Expand Up @@ -985,7 +1025,7 @@ describe('modules/manager/pipenv/artifacts', () => {
${'${USERNAME}'} | ${'USERNAME'}
${'${USERNAME:-default}'} | ${'USERNAME'}
${'${COMPLEX_NAME_1:-default}'} | ${'COMPLEX_NAME_1'}
`('extractEnvironmentVariableName(%p)', ({ credential, result }) => {
`('extractEnvironmentVariableName($credential)', ({ credential, result }) => {
expect(extractEnvironmentVariableName(credential)).toEqual(result);
});

Expand All @@ -999,6 +1039,7 @@ describe('modules/manager/pipenv/artifacts', () => {

it('updates extraEnv if variable names differ from default', async () => {
fsExtra.ensureDir.mockResolvedValue(undefined as never);
fsExtra.stat.mockResolvedValueOnce({} as never);

mockFiles({
'/Pipfile.lock': ['current Pipfile.lock', 'New Pipfile.lock'],
Expand Down
Loading