diff --git a/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap b/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap index a33d994db1ffbdd60b05f304ef91bfa5e361f60e..325dfdbde1116a8de9865fa308b88b1bb1e3b76f 100644 --- a/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap @@ -115,7 +115,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, @@ -161,7 +162,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, @@ -207,7 +209,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, @@ -237,6 +240,34 @@ Object { } `; +exports[`manager/pip_requirements/extract extractPackageFile() handles extra spaces around pinned dependency equal signs 1`] = ` +Object { + "deps": Array [ + Object { + "currentValue": "==2.0.12", + "currentVersion": "2.0.12", + "datasource": "pypi", + "depName": "Django", + }, + Object { + "currentValue": "==4.1.1", + "currentVersion": "4.1.1", + "datasource": "pypi", + "depName": "celery", + }, + Object { + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", + "datasource": "pypi", + "depName": "foo", + }, + ], + "registryUrls": Array [ + "https://artifactory.company.com/artifactory/api/pypi/python/simple", + ], +} +`; + exports[`manager/pip_requirements/extract extractPackageFile() handles extras and complex index url 1`] = ` Object { "deps": Array [ @@ -253,7 +284,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, diff --git a/lib/manager/pip_requirements/extract.spec.ts b/lib/manager/pip_requirements/extract.spec.ts index 259455bb1fa3d1c50700719769d238372006805e..4fba3ee3ea07ac3d1fbbc085d3a5e6e3a00e10ff 100644 --- a/lib/manager/pip_requirements/extract.spec.ts +++ b/lib/manager/pip_requirements/extract.spec.ts @@ -88,6 +88,20 @@ describe(getName(), () => { ]); expect(res.deps).toHaveLength(6); }); + + it('handles extra spaces around pinned dependency equal signs', () => { + const res = extractPackageFile(requirements4, 'unused_file_name', {}); + expect(res).toMatchSnapshot(); + + expect(res.deps[0].currentValue).toStartWith('=='); + expect(res.deps[0].currentVersion).toStartWith('2.0.12'); + expect(res.deps[1].currentValue).toStartWith('=='); + expect(res.deps[1].currentVersion).toStartWith('4.1.1'); + expect(res.deps[2].currentValue).toStartWith('=='); + expect(res.deps[2].currentVersion).toStartWith('3.2.1'); + + expect(res.deps).toHaveLength(3); + }); it('should not replace env vars in low trust mode', () => { process.env.PIP_TEST_TOKEN = 'its-a-secret'; const res = extractPackageFile(requirements7, 'unused_file_name', {}); diff --git a/lib/manager/pip_requirements/extract.ts b/lib/manager/pip_requirements/extract.ts index 87fc491b410ce2d776a0e49b2dc0bab3192601f6..f5e357bbea95ec7775e8f11cf2bc545e6f4b0680 100644 --- a/lib/manager/pip_requirements/extract.ts +++ b/lib/manager/pip_requirements/extract.ts @@ -63,7 +63,8 @@ export function extractPackageFile( if (!matches) { return null; } - const [, depName, , currentValue] = matches; + const [, depName, , currVal] = matches; + const currentValue = currVal.trim(); dep = { ...dep, depName, @@ -71,7 +72,7 @@ export function extractPackageFile( datasource: datasourcePypi.id, }; if (currentValue?.startsWith('==')) { - dep.currentVersion = currentValue.replace(/^==/, ''); + dep.currentVersion = currentValue.replace(/^==\s*/, ''); } return dep; })