diff --git a/lib/modules/manager/pip_requirements/__fixtures__/requirements9.txt b/lib/modules/manager/pip_requirements/__fixtures__/requirements9.txt new file mode 100644 index 0000000000..1f6fd94c58 --- /dev/null +++ b/lib/modules/manager/pip_requirements/__fixtures__/requirements9.txt @@ -0,0 +1,10 @@ +# Repositories +--index-url=https://artifactory.company.com/artifactory/api/pypi/python/simple --trusted-host artifactory.company.com --default-timeout 600 +--extra-index-url=http://example.com/private-pypi/ +# Packages +Django[argon2]==2.0.12 +celery [redis]==4.1.1 +foo [bar] == 3.2.1 # handles extra white space +some-package==0.3.1 +some-other-package==1.0.0 +not_semver==1.9 diff --git a/lib/modules/manager/pip_requirements/common.ts b/lib/modules/manager/pip_requirements/common.ts index c505baa3fc..2f4040b4c4 100644 --- a/lib/modules/manager/pip_requirements/common.ts +++ b/lib/modules/manager/pip_requirements/common.ts @@ -33,13 +33,23 @@ export function extractPackageFileFlags( const additionalRequirementsFiles: string[] = []; const additionalConstraintsFiles: string[] = []; content.split(newlineRegex).forEach((line) => { - if (line.startsWith('-i ') || line.startsWith('--index-url ')) { - registryUrls = [line.split(' ')[1]]; - } else if (line.startsWith('--extra-index-url ')) { - const extraUrl = line - .substring('--extra-index-url '.length) - .split(' ')[0]; - additionalRegistryUrls.push(extraUrl); + if (line.startsWith('-i ') || line.startsWith('--index-url')) { + // parameters can be separated by space or =, same below for --extra-index-url + if (line.includes('=')) { + registryUrls = [line.split('=')[1]]; + } else { + registryUrls = [line.split(' ')[1]]; + } + } else if (line.startsWith('--extra-index-url')) { + if (line.includes('=')) { + const extraUrl = line.split('=')[1]; + additionalRegistryUrls.push(extraUrl); + } else { + const extraUrl = line + .substring('--extra-index-url '.length) + .split(' ')[0]; + additionalRegistryUrls.push(extraUrl); + } } else if (line.startsWith('-r ')) { additionalRequirementsFiles.push(line.split(' ')[1]); } else if (line.startsWith('-c ')) { diff --git a/lib/modules/manager/pip_requirements/extract.spec.ts b/lib/modules/manager/pip_requirements/extract.spec.ts index f088de89f6..5c4b6d2a2d 100644 --- a/lib/modules/manager/pip_requirements/extract.spec.ts +++ b/lib/modules/manager/pip_requirements/extract.spec.ts @@ -10,6 +10,7 @@ const requirements5 = Fixtures.get('requirements5.txt'); const requirements6 = Fixtures.get('requirements6.txt'); const requirements7 = Fixtures.get('requirements7.txt'); const requirements8 = Fixtures.get('requirements8.txt'); +const requirements9 = Fixtures.get('requirements9.txt'); const requirementsWithEnvMarkers = Fixtures.get('requirements-env-markers.txt'); const requirementsGitPackages = Fixtures.get('requirements-git-packages.txt'); @@ -120,6 +121,18 @@ some-package==0.3.1`; expect(res?.deps).toHaveLength(6); }); + it('handles index urls with = as separator', () => { + const res = extractPackageFile(requirements9); + expect(res).toMatchSnapshot(); + expect(res?.registryUrls).toEqual([ + 'https://artifactory.company.com/artifactory/api/pypi/python/simple', + ]); + expect(res?.additionalRegistryUrls).toEqual([ + 'http://example.com/private-pypi/', + ]); + expect(res?.deps).toHaveLength(6); + }); + it('handles extra index url and defaults without index to config', () => { const res = extractPackageFile(requirements6); expect(res).toMatchSnapshot();