diff --git a/lib/manager/pip_requirements/extract.js b/lib/manager/pip_requirements/extract.js index 434cfa797343f108b854184c4361422d23b43f3a..af13cfd3f8a31abfcead56d61c39e646fc4865eb 100644 --- a/lib/manager/pip_requirements/extract.js +++ b/lib/manager/pip_requirements/extract.js @@ -65,7 +65,7 @@ function extractPackageFile(content, _, config) { ...dep, depName, currentValue, - lineNumber, + managerData: { lineNumber }, datasource: 'pypi', }; if ( diff --git a/lib/manager/pip_requirements/update.js b/lib/manager/pip_requirements/update.js index ba1ad061cb8874a2542c336d969be6bd88d1a4dd..7809aa63a8eb5b784bd9c4de043523668b766863 100644 --- a/lib/manager/pip_requirements/update.js +++ b/lib/manager/pip_requirements/update.js @@ -9,7 +9,7 @@ function updateDependency(fileContent, upgrade) { try { logger.debug(`pip_requirements.updateDependency(): ${upgrade.newValue}`); const lines = fileContent.split('\n'); - const oldValue = lines[upgrade.lineNumber]; + const oldValue = lines[upgrade.managerData.lineNumber]; let newValue; const multiDependencyRegex = new RegExp( `(install_requires\\s*[=]\\s*\\[.*)(${upgrade.depName}.+?(?='))(.*])`, @@ -32,7 +32,7 @@ function updateDependency(fileContent, upgrade) { `$1$2${upgrade.newValue}` ); } - lines[upgrade.lineNumber] = newValue; + lines[upgrade.managerData.lineNumber] = newValue; return lines.join('\n'); } catch (err) { logger.info({ err }, 'Error setting new package version'); diff --git a/test/manager/pip_requirements/__snapshots__/extract.spec.js.snap b/test/manager/pip_requirements/__snapshots__/extract.spec.js.snap index f932fa4a6c4fa49511f4b9a05b8ea6ad3805afb2..24c6295c7782f4b44e52367a14309befd915a8c5 100644 --- a/test/manager/pip_requirements/__snapshots__/extract.spec.js.snap +++ b/test/manager/pip_requirements/__snapshots__/extract.spec.js.snap @@ -8,21 +8,27 @@ Object { "datasource": "pypi", "depName": "some-package", "fromVersion": "0.3.1", - "lineNumber": 2, + "managerData": Object { + "lineNumber": 2, + }, }, Object { "currentValue": "==1.0.0", "datasource": "pypi", "depName": "some-other-package", "fromVersion": "1.0.0", - "lineNumber": 3, + "managerData": Object { + "lineNumber": 3, + }, }, Object { "currentValue": "==1.9", "datasource": "pypi", "depName": "not_semver", "fromVersion": "1.9", - "lineNumber": 4, + "managerData": Object { + "lineNumber": 4, + }, }, ], "registryUrls": Array [ @@ -38,35 +44,45 @@ Array [ "datasource": "pypi", "depName": "Django", "fromVersion": "1", - "lineNumber": 0, + "managerData": Object { + "lineNumber": 0, + }, }, Object { "currentValue": "==0.6.27", "datasource": "pypi", "depName": "distribute", "fromVersion": "0.6.27", - "lineNumber": 1, + "managerData": Object { + "lineNumber": 1, + }, }, Object { "currentValue": "==0.2", "datasource": "pypi", "depName": "dj-database-url", "fromVersion": "0.2", - "lineNumber": 2, + "managerData": Object { + "lineNumber": 2, + }, }, Object { "currentValue": "==2.4.5", "datasource": "pypi", "depName": "psycopg2", "fromVersion": "2.4.5", - "lineNumber": 3, + "managerData": Object { + "lineNumber": 3, + }, }, Object { "currentValue": "==0.1.2", "datasource": "pypi", "depName": "wsgiref", "fromVersion": "0.1.2", - "lineNumber": 4, + "managerData": Object { + "lineNumber": 4, + }, }, ] `; @@ -78,14 +94,18 @@ Array [ "datasource": "pypi", "depName": "Django", "fromVersion": "1.11.19", - "lineNumber": 0, + "managerData": Object { + "lineNumber": 0, + }, }, Object { "currentValue": "==0.6.27", "datasource": "pypi", "depName": "distribute", "fromVersion": "0.6.27", - "lineNumber": 1, + "managerData": Object { + "lineNumber": 1, + }, "skipReason": "ignored", }, Object { @@ -93,21 +113,27 @@ Array [ "datasource": "pypi", "depName": "dj-database-url", "fromVersion": "0.2", - "lineNumber": 2, + "managerData": Object { + "lineNumber": 2, + }, }, Object { "currentValue": "==2.4.5", "datasource": "pypi", "depName": "psycopg2", "fromVersion": "2.4.5", - "lineNumber": 3, + "managerData": Object { + "lineNumber": 3, + }, }, Object { "currentValue": "==0.1.2", "datasource": "pypi", "depName": "wsgiref", "fromVersion": "0.1.2", - "lineNumber": 4, + "managerData": Object { + "lineNumber": 4, + }, }, ] `; @@ -120,41 +146,53 @@ Object { "datasource": "pypi", "depName": "Django", "fromVersion": "2.0.12", - "lineNumber": 4, + "managerData": Object { + "lineNumber": 4, + }, }, Object { "currentValue": "==4.1.1", "datasource": "pypi", "depName": "celery", "fromVersion": "4.1.1", - "lineNumber": 5, + "managerData": Object { + "lineNumber": 5, + }, }, Object { "currentValue": " == 3.2.1", "datasource": "pypi", "depName": "foo", - "lineNumber": 6, + "managerData": Object { + "lineNumber": 6, + }, }, Object { "currentValue": "==0.3.1", "datasource": "pypi", "depName": "some-package", "fromVersion": "0.3.1", - "lineNumber": 7, + "managerData": Object { + "lineNumber": 7, + }, }, Object { "currentValue": "==1.0.0", "datasource": "pypi", "depName": "some-other-package", "fromVersion": "1.0.0", - "lineNumber": 8, + "managerData": Object { + "lineNumber": 8, + }, }, Object { "currentValue": "==1.9", "datasource": "pypi", "depName": "not_semver", "fromVersion": "1.9", - "lineNumber": 9, + "managerData": Object { + "lineNumber": 9, + }, }, ], "registryUrls": Array [ @@ -172,41 +210,53 @@ Object { "datasource": "pypi", "depName": "Django", "fromVersion": "2.0.12", - "lineNumber": 3, + "managerData": Object { + "lineNumber": 3, + }, }, Object { "currentValue": "==4.1.1", "datasource": "pypi", "depName": "celery", "fromVersion": "4.1.1", - "lineNumber": 4, + "managerData": Object { + "lineNumber": 4, + }, }, Object { "currentValue": " == 3.2.1", "datasource": "pypi", "depName": "foo", - "lineNumber": 5, + "managerData": Object { + "lineNumber": 5, + }, }, Object { "currentValue": "==0.3.1", "datasource": "pypi", "depName": "some-package", "fromVersion": "0.3.1", - "lineNumber": 6, + "managerData": Object { + "lineNumber": 6, + }, }, Object { "currentValue": "==1.0.0", "datasource": "pypi", "depName": "some-other-package", "fromVersion": "1.0.0", - "lineNumber": 7, + "managerData": Object { + "lineNumber": 7, + }, }, Object { "currentValue": "==1.9", "datasource": "pypi", "depName": "not_semver", "fromVersion": "1.9", - "lineNumber": 8, + "managerData": Object { + "lineNumber": 8, + }, }, ], "registryUrls": Array [ @@ -224,41 +274,53 @@ Object { "datasource": "pypi", "depName": "Django", "fromVersion": "2.0.12", - "lineNumber": 3, + "managerData": Object { + "lineNumber": 3, + }, }, Object { "currentValue": "==4.1.1", "datasource": "pypi", "depName": "celery", "fromVersion": "4.1.1", - "lineNumber": 4, + "managerData": Object { + "lineNumber": 4, + }, }, Object { "currentValue": " == 3.2.1", "datasource": "pypi", "depName": "foo", - "lineNumber": 5, + "managerData": Object { + "lineNumber": 5, + }, }, Object { "currentValue": "==0.3.1", "datasource": "pypi", "depName": "some-package", "fromVersion": "0.3.1", - "lineNumber": 6, + "managerData": Object { + "lineNumber": 6, + }, }, Object { "currentValue": "==1.0.0", "datasource": "pypi", "depName": "some-other-package", "fromVersion": "1.0.0", - "lineNumber": 7, + "managerData": Object { + "lineNumber": 7, + }, }, Object { "currentValue": "==1.9", "datasource": "pypi", "depName": "not_semver", "fromVersion": "1.9", - "lineNumber": 8, + "managerData": Object { + "lineNumber": 8, + }, }, ], "registryUrls": Array [ @@ -276,20 +338,26 @@ Object { "datasource": "pypi", "depName": "Django", "fromVersion": "2.0.12", - "lineNumber": 1, + "managerData": Object { + "lineNumber": 1, + }, }, Object { "currentValue": "==4.1.1", "datasource": "pypi", "depName": "celery", "fromVersion": "4.1.1", - "lineNumber": 2, + "managerData": Object { + "lineNumber": 2, + }, }, Object { "currentValue": " == 3.2.1", "datasource": "pypi", "depName": "foo", - "lineNumber": 3, + "managerData": Object { + "lineNumber": 3, + }, }, ], "registryUrls": Array [ diff --git a/test/manager/pip_requirements/update.spec.js b/test/manager/pip_requirements/update.spec.js index 8a25d15ed5016ce1bb44203c5ffda23d2e8a66a2..d2d00561134d5cbb44d850ab08c9fb692a69ceee 100644 --- a/test/manager/pip_requirements/update.spec.js +++ b/test/manager/pip_requirements/update.spec.js @@ -33,7 +33,7 @@ describe('manager/pip_requirements/update', () => { it('replaces existing value', () => { const upgrade = { depName: 'some-package', - lineNumber: 2, + managerData: { lineNumber: 2 }, newValue: '==1.0.1', }; const res = updateDependency(requirements, upgrade); @@ -48,7 +48,7 @@ describe('manager/pip_requirements/update', () => { it('replaces existing value with comment', () => { const upgrade = { depName: 'psycopg2', - lineNumber: 3, + managerData: { lineNumber: 3 }, newValue: '==2.4.6', }; const res = updateDependency(requirements3, upgrade); @@ -60,7 +60,7 @@ describe('manager/pip_requirements/update', () => { it('replaces existing value with extras', () => { const upgrade = { depName: 'celery', - lineNumber: 1, + managerData: { lineNumber: 1 }, newValue: '==4.1.2', }; const res = updateDependency(requirements4, upgrade); @@ -71,7 +71,7 @@ describe('manager/pip_requirements/update', () => { it('handles dependencies in different lines in setup.py', () => { const upgrade = { depName: 'requests', - lineNumber: 64, + managerData: { lineNumber: 64 }, newValue: '>=2.11.0', }; const res = updateDependency(setupPy1, upgrade); @@ -82,7 +82,7 @@ describe('manager/pip_requirements/update', () => { it('handles multiple dependencies in same lines in setup.py', () => { const upgrade = { depName: 'pycryptodome', - lineNumber: 60, + managerData: { lineNumber: 60 }, newValue: '==3.8.0', }; const res = updateDependency(setupPy2, upgrade);