This commit is contained in:
Oluf Lorenzen 2025-01-01 10:24:33 +05:30 committed by GitHub
commit 3a88bfd03c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 7 deletions

View file

@ -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

View file

@ -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 ')) {
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 ')) {
}
} 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 ')) {

View file

@ -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();