From 84b7eede507e5fcd11d46e8405c78ac4bf29d717 Mon Sep 17 00:00:00 2001 From: Daniel Barrett Date: Thu, 30 Apr 2020 20:06:37 +1000 Subject: [PATCH] feat(manager): enable pipenv lockfile maintance (#6096) --- .../__snapshots__/artifacts.spec.ts.snap | 23 +++++++++++++++++++ lib/manager/pipenv/artifacts.spec.ts | 18 +++++++++++++++ lib/manager/pipenv/artifacts.ts | 5 +++- lib/manager/pipenv/index.ts | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/manager/pipenv/__snapshots__/artifacts.spec.ts.snap b/lib/manager/pipenv/__snapshots__/artifacts.spec.ts.snap index 38c8164f2d..f1f79216b2 100644 --- a/lib/manager/pipenv/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/pipenv/__snapshots__/artifacts.spec.ts.snap @@ -57,6 +57,29 @@ Array [ ] `; +exports[`.updateArtifacts() returns updated Pipenv.lock when doing lockfile maintenance 1`] = ` +Array [ + Object { + "cmd": "pipenv lock", + "options": Object { + "cwd": "/tmp/github/some/repo", + "encoding": "utf-8", + "env": Object { + "HOME": "/home/user", + "HTTPS_PROXY": "https://example.com", + "HTTP_PROXY": "http://example.com", + "LANG": "en_US.UTF-8", + "LC_ALL": "en_US", + "NO_PROXY": "localhost", + "PATH": "/tmp/path", + "PIPENV_CACHE_DIR": "/tmp/renovate/cache/others/pipenv", + }, + "timeout": 900000, + }, + }, +] +`; + exports[`.updateArtifacts() returns updated Pipfile.lock 1`] = ` Array [ Object { diff --git a/lib/manager/pipenv/artifacts.spec.ts b/lib/manager/pipenv/artifacts.spec.ts index 15ea6ee310..24ad3cb61b 100644 --- a/lib/manager/pipenv/artifacts.spec.ts +++ b/lib/manager/pipenv/artifacts.spec.ts @@ -34,6 +34,7 @@ const config = { }; const dockerConfig = { ...config, binarySource: BinarySource.Docker }; +const lockMaintenceConfig = { ...config, isLockFileMaintenance: true }; describe('.updateArtifacts()', () => { let pipFileLock; @@ -139,4 +140,21 @@ describe('.updateArtifacts()', () => { }) ).toMatchSnapshot(); }); + it('returns updated Pipenv.lock when doing lockfile maintenance', async () => { + platform.getFile.mockResolvedValueOnce('Current Pipfile.lock'); + const execSnapshots = mockExecAll(exec); + platform.getRepoStatus.mockResolvedValue({ + modified: ['Pipfile.lock'], + } as StatusResult); + fs.readFile.mockReturnValueOnce('New Pipfile.lock' as any); + expect( + await pipenv.updateArtifacts({ + packageFileName: 'Pipfile', + updatedDeps: [], + newPackageFileContent: '{}', + config: lockMaintenceConfig, + }) + ).not.toBeNull(); + expect(execSnapshots).toMatchSnapshot(); + }); }); diff --git a/lib/manager/pipenv/artifacts.ts b/lib/manager/pipenv/artifacts.ts index 93e1ea80b1..5580fc798d 100644 --- a/lib/manager/pipenv/artifacts.ts +++ b/lib/manager/pipenv/artifacts.ts @@ -1,4 +1,4 @@ -import { ensureDir, outputFile, readFile } from 'fs-extra'; +import { ensureDir, outputFile, readFile, remove } from 'fs-extra'; import { join } from 'upath'; import { exec, ExecOptions } from '../../util/exec'; import { logger } from '../../logger'; @@ -56,6 +56,9 @@ export async function updateArtifacts({ const localPipfileFileName = join(config.localDir, pipfileName); await outputFile(localPipfileFileName, newPipfileContent); const localLockFileName = join(config.localDir, lockFileName); + if (config.isLockFileMaintenance) { + await remove(localLockFileName); + } const cmd = 'pipenv lock'; const tagConstraint = getPythonConstraint(existingLockFileContent, config); const execOptions: ExecOptions = { diff --git a/lib/manager/pipenv/index.ts b/lib/manager/pipenv/index.ts index ee4199c26f..c5a1017c65 100644 --- a/lib/manager/pipenv/index.ts +++ b/lib/manager/pipenv/index.ts @@ -4,6 +4,7 @@ export { extractPackageFile } from './extract'; export { updateArtifacts } from './artifacts'; export const language = LANGUAGE_PYTHON; +export const supportsLockFileMaintenance = true; export const defaultConfig = { fileMatch: ['(^|/)Pipfile$'],