Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
20c25d93
Unverified
Commit
20c25d93
authored
3 years ago
by
Christopher Frieler
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(pypi): Normalize package names before lookup (#12273)
parent
eef0a00c
Branches
Branches containing commit
Tags
28.20.0
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/datasource/pypi/index.spec.ts
+47
-0
47 additions, 0 deletions
lib/datasource/pypi/index.spec.ts
lib/datasource/pypi/index.ts
+14
-3
14 additions, 3 deletions
lib/datasource/pypi/index.ts
with
61 additions
and
3 deletions
lib/datasource/pypi/index.spec.ts
+
47
−
0
View file @
20c25d93
...
...
@@ -172,6 +172,53 @@ describe('datasource/pypi/index', () => {
expect
(
result
.
changelogUrl
).
toBe
(
info
.
project_urls
.
changelog
);
expect
(
httpMock
.
getTrace
()).
toMatchSnapshot
();
});
it
(
'
normalizes the package name according to PEP 503
'
,
async
()
=>
{
const
expectedHttpCall
=
httpMock
.
scope
(
baseUrl
)
.
get
(
'
/not-normalized-package/json
'
)
.
reply
(
200
,
htmlResponse
);
await
getPkgReleases
({
datasource
,
registryUrls
:
[
baseUrl
],
depName
:
'
not_normalized.Package
'
,
});
expect
(
expectedHttpCall
.
isDone
()).
toBeTrue
();
});
it
(
'
normalizes the package name according to PEP 503 when falling back to simple endpoint
'
,
async
()
=>
{
httpMock
.
scope
(
baseUrl
)
.
get
(
'
/not-normalized-package/json
'
)
.
reply
(
404
,
''
);
const
expectedFallbackHttpCall
=
httpMock
.
scope
(
baseUrl
)
.
get
(
'
/not-normalized-package/
'
)
.
reply
(
200
,
htmlResponse
);
await
getPkgReleases
({
datasource
,
registryUrls
:
[
baseUrl
],
depName
:
'
not_normalized.Package
'
,
});
expect
(
expectedFallbackHttpCall
.
isDone
()).
toBeTrue
();
});
it
(
'
normalizes the package name according to PEP 503 querying a simple endpoint
'
,
async
()
=>
{
const
simpleRegistryUrl
=
'
https://pypi.org/simple/
'
;
const
expectedHttpCall
=
httpMock
.
scope
(
simpleRegistryUrl
)
.
get
(
'
/not-normalized-package/
'
)
.
reply
(
200
,
htmlResponse
);
await
getPkgReleases
({
datasource
,
registryUrls
:
[
simpleRegistryUrl
],
depName
:
'
not_normalized.Package
'
,
});
expect
(
expectedHttpCall
.
isDone
()).
toBeTrue
();
});
it
(
'
respects constraints
'
,
async
()
=>
{
httpMock
...
...
This diff is collapsed.
Click to expand it.
lib/datasource/pypi/index.ts
+
14
−
3
View file @
20c25d93
...
...
@@ -36,6 +36,7 @@ export class PypiDatasource extends Datasource {
}:
GetReleasesConfig
):
Promise
<
ReleaseResult
|
null
>
{
let
dependency
:
ReleaseResult
=
null
;
const
hostUrl
=
ensureTrailingSlash
(
registryUrl
);
const
normalizedLookupName
=
PypiDatasource
.
normalizeName
(
lookupName
);
// not all simple indexes use this identifier, but most do
if
(
hostUrl
.
endsWith
(
'
/simple/
'
)
||
hostUrl
.
endsWith
(
'
/+simple/
'
))
{
...
...
@@ -43,12 +44,15 @@ export class PypiDatasource extends Datasource {
{
lookupName
,
hostUrl
},
'
Looking up pypi simple dependency
'
);
dependency
=
await
this
.
getSimpleDependency
(
lookupName
,
hostUrl
);
dependency
=
await
this
.
getSimpleDependency
(
normalizedLookupName
,
hostUrl
);
}
else
{
logger
.
trace
({
lookupName
,
hostUrl
},
'
Looking up pypi api dependency
'
);
try
{
// we need to resolve early here so we can catch any 404s and fallback to a simple lookup
dependency
=
await
this
.
getDependency
(
l
ookupName
,
hostUrl
);
dependency
=
await
this
.
getDependency
(
normalizedL
ookupName
,
hostUrl
);
}
catch
(
err
)
{
if
(
err
.
statusCode
!==
404
)
{
throw
err
;
...
...
@@ -59,12 +63,19 @@ export class PypiDatasource extends Datasource {
{
lookupName
,
hostUrl
},
'
Looking up pypi simple dependency via fallback
'
);
dependency
=
await
this
.
getSimpleDependency
(
lookupName
,
hostUrl
);
dependency
=
await
this
.
getSimpleDependency
(
normalizedLookupName
,
hostUrl
);
}
}
return
dependency
;
}
private
static
normalizeName
(
input
:
string
):
string
{
return
input
.
toLowerCase
().
replace
(
regEx
(
/
(
_|
\.
|-
)
+/g
),
'
-
'
);
}
private
async
getDependency
(
packageName
:
string
,
hostUrl
:
string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment