diff --git a/lib/manager/pipenv/__snapshots__/update.spec.ts.snap b/lib/manager/pipenv/__snapshots__/update.spec.ts.snap deleted file mode 100644 index ec1f8a30684317d050b149855bb9fe3e7d9a6f52..0000000000000000000000000000000000000000 --- a/lib/manager/pipenv/__snapshots__/update.spec.ts.snap +++ /dev/null @@ -1,79 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`manager/pipenv/update updateDependency replaces existing value 1`] = ` -"[[source]] -url = \\"https://pypi.org/simple\\" -verify_ssl = true -name = \\"pypi\\" - -[[source]] -url = \\"http://example.com/private-pypi/\\" -verify_ssl = false -name = \\"private-pypi\\" - -[packages] -some-package = \\"==1.0.1\\" -some-other-package = \\"==1.0.0\\" -\\"_invalid-package\\" = \\"==1.0.0\\" -invalid-version = \\"==0 0\\" -pytest-benchmark = {version = \\"==1.0.0\\", extras = [\\"histogram\\"]} - -[dev-packages] -dev-package = \\"==0.1.0\\" - -[requires] -python_version = \\"3.6\\" -" -`; - -exports[`manager/pipenv/update updateDependency replaces nested value 1`] = ` -"[[source]] -url = \\"https://pypi.org/simple\\" -verify_ssl = true -name = \\"pypi\\" - -[[source]] -url = \\"http://example.com/private-pypi/\\" -verify_ssl = false -name = \\"private-pypi\\" - -[packages] -some-package = \\"==0.3.1\\" -some-other-package = \\"==1.0.0\\" -\\"_invalid-package\\" = \\"==1.0.0\\" -invalid-version = \\"==0 0\\" -pytest-benchmark = {version = \\"==1.9.1\\", extras = [\\"histogram\\"]} - -[dev-packages] -dev-package = \\"==0.1.0\\" - -[requires] -python_version = \\"3.6\\" -" -`; - -exports[`manager/pipenv/update updateDependency upgrades dev packages 1`] = ` -"[[source]] -url = \\"https://pypi.org/simple\\" -verify_ssl = true -name = \\"pypi\\" - -[[source]] -url = \\"http://example.com/private-pypi/\\" -verify_ssl = false -name = \\"private-pypi\\" - -[packages] -some-package = \\"==0.3.1\\" -some-other-package = \\"==1.0.0\\" -\\"_invalid-package\\" = \\"==1.0.0\\" -invalid-version = \\"==0 0\\" -pytest-benchmark = {version = \\"==1.0.0\\", extras = [\\"histogram\\"]} - -[dev-packages] -dev-package = \\"==0.2.0\\" - -[requires] -python_version = \\"3.6\\" -" -`; diff --git a/lib/manager/pipenv/index.ts b/lib/manager/pipenv/index.ts index cdcd7b33abe2c81e4453a6758daedc1f7d992bd2..ee4199c26fab8c6e9249f858c19e8ef0431986aa 100644 --- a/lib/manager/pipenv/index.ts +++ b/lib/manager/pipenv/index.ts @@ -1,7 +1,6 @@ import { LANGUAGE_PYTHON } from '../../constants/languages'; export { extractPackageFile } from './extract'; -export { updateDependency } from './update'; export { updateArtifacts } from './artifacts'; export const language = LANGUAGE_PYTHON; diff --git a/lib/manager/pipenv/update.spec.ts b/lib/manager/pipenv/update.spec.ts deleted file mode 100644 index 52a55ef1bd51496c47c00f98f6d93e5cd48a86a6..0000000000000000000000000000000000000000 --- a/lib/manager/pipenv/update.spec.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { readFileSync } from 'fs'; -import { updateDependency } from './update'; - -const pipfile = readFileSync( - 'lib/manager/pipenv/__fixtures__/Pipfile1', - 'utf8' -); - -describe('manager/pipenv/update', () => { - describe('updateDependency', () => { - it('replaces existing value', () => { - const upgrade = { - depName: 'some-package', - newValue: '==1.0.1', - depType: 'packages', - }; - const res = updateDependency({ fileContent: pipfile, upgrade }); - expect(res).not.toEqual(pipfile); - expect(res.includes(upgrade.newValue)).toBe(true); - expect(res).toMatchSnapshot(); - }); - it('handles already replace values', () => { - const upgrade = { - depName: 'some-package', - newValue: '==0.3.1', - depType: 'packages', - }; - const res = updateDependency({ fileContent: pipfile, upgrade }); - expect(res).toEqual(pipfile); - }); - it('replaces nested value', () => { - const upgrade = { - depName: 'pytest-benchmark', - newValue: '==1.9.1', - depType: 'packages', - managerData: { nestedVersion: true }, - }; - const res = updateDependency({ fileContent: pipfile, upgrade }); - expect(res).not.toEqual(pipfile); - expect(res.includes(upgrade.newValue)).toBe(true); - expect(res).toMatchSnapshot(); - }); - it('upgrades dev packages', () => { - const upgrade = { - depName: 'dev-package', - newValue: '==0.2.0', - depType: 'dev-packages', - }; - const res = updateDependency({ fileContent: pipfile, upgrade }); - expect(res).not.toEqual(pipfile); - expect(res.includes(upgrade.newValue)).toBe(true); - expect(res).toMatchSnapshot(); - }); - it('returns null if error', () => { - const res = updateDependency({ fileContent: null, upgrade: null }); - expect(res).toBeNull(); - }); - }); -}); diff --git a/lib/manager/pipenv/update.ts b/lib/manager/pipenv/update.ts deleted file mode 100644 index 504b162ed8d9c231775288ce7eaf5845269deac3..0000000000000000000000000000000000000000 --- a/lib/manager/pipenv/update.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { isEqual } from 'lodash'; -import { parse } from 'toml'; -import { logger } from '../../logger'; -import { UpdateDependencyConfig } from '../common'; -import { matchAt, replaceAt } from '../../util/string'; - -export function updateDependency({ - fileContent, - upgrade, -}: UpdateDependencyConfig): string | null { - try { - const { depType, depName, newValue, managerData = {} } = upgrade; - const { nestedVersion } = managerData; - logger.debug(`pipenv.updateDependency(): ${newValue}`); - const parsedContents = parse(fileContent); - let oldVersion: string; - if (nestedVersion) { - oldVersion = parsedContents[depType][depName].version; - } else { - oldVersion = parsedContents[depType][depName]; - } - if (oldVersion === newValue) { - logger.debug('Version is already updated'); - return fileContent; - } - if (nestedVersion) { - parsedContents[depType][depName].version = newValue; - } else { - parsedContents[depType][depName] = newValue; - } - const searchString = `"${oldVersion}"`; - const newString = `"${newValue}"`; - let newFileContent = null; - let searchIndex = fileContent.indexOf(`[${depType}]`) + depType.length; - for (; searchIndex < fileContent.length; searchIndex += 1) { - // First check if we have a hit for the old version - if (matchAt(fileContent, searchIndex, searchString)) { - logger.trace(`Found match at index ${searchIndex}`); - // Now test if the result matches - const testContent = replaceAt( - fileContent, - searchIndex, - searchString, - newString - ); - // Compare the parsed toml structure of old and new - if (isEqual(parsedContents, parse(testContent))) { - newFileContent = testContent; - break; - } else { - logger.debug('Mismatched replace at searchIndex ' + searchIndex); - } - } - } - // istanbul ignore if - if (!newFileContent) { - logger.debug( - { fileContent, parsedContents, depType, depName, newValue }, - 'Warning: updateDependency error' - ); - return fileContent; - } - return newFileContent; - } catch (err) { - logger.debug({ err }, 'Error setting new package version'); - return null; - } -}