Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
cd3026f7
Commit
cd3026f7
authored
Apr 22, 2022
by
Bernardo Meurer
Committed by
Arun Babu Neelicattu
May 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(link_sources): don't bail on an invalid version
parent
86036944
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
6 deletions
+57
-6
src/poetry/repositories/link_sources/base.py
+14
-6
tests/repositories/fixtures/legacy/invalid-version.html
+12
-0
tests/repositories/test_legacy_repository.py
+31
-0
No files found.
src/poetry/repositories/link_sources/base.py
View file @
cd3026f7
from
__future__
import
annotations
from
__future__
import
annotations
import
contextlib
import
logging
import
re
import
re
from
abc
import
abstractmethod
from
abc
import
abstractmethod
...
@@ -19,6 +19,9 @@ if TYPE_CHECKING:
...
@@ -19,6 +19,9 @@ if TYPE_CHECKING:
from
poetry.core.packages.utils.link
import
Link
from
poetry.core.packages.utils.link
import
Link
logger
=
logging
.
getLogger
(
__name__
)
class
LinkSource
:
class
LinkSource
:
VERSION_REGEX
=
re
.
compile
(
r"(?i)([a-z0-9_\-.]+?)-(?=\d)([a-z0-9_.!+-]+)"
)
VERSION_REGEX
=
re
.
compile
(
r"(?i)([a-z0-9_\-.]+?)-(?=\d)([a-z0-9_.!+-]+)"
)
CLEAN_REGEX
=
re
.
compile
(
r"[^a-z0-9$&+,/:;=?@.#
%
_\\|-]"
,
re
.
I
)
CLEAN_REGEX
=
re
.
compile
(
r"[^a-z0-9$&+,/:;=?@.#
%
_\\|-]"
,
re
.
I
)
...
@@ -46,7 +49,7 @@ class LinkSource:
...
@@ -46,7 +49,7 @@ class LinkSource:
for
link
in
self
.
links
:
for
link
in
self
.
links
:
pkg
=
self
.
link_package_data
(
link
)
pkg
=
self
.
link_package_data
(
link
)
if
pkg
.
name
==
name
and
pkg
.
version
and
pkg
.
version
not
in
seen
:
if
pkg
and
pkg
.
name
==
name
and
pkg
.
version
and
pkg
.
version
not
in
seen
:
seen
.
add
(
pkg
.
version
)
seen
.
add
(
pkg
.
version
)
yield
pkg
.
version
yield
pkg
.
version
...
@@ -55,7 +58,7 @@ class LinkSource:
...
@@ -55,7 +58,7 @@ class LinkSource:
for
link
in
self
.
links
:
for
link
in
self
.
links
:
pkg
=
self
.
link_package_data
(
link
)
pkg
=
self
.
link_package_data
(
link
)
if
pkg
.
name
and
pkg
.
version
:
if
pkg
and
pkg
.
name
and
pkg
.
version
:
yield
pkg
yield
pkg
@property
@property
...
@@ -63,7 +66,7 @@ class LinkSource:
...
@@ -63,7 +66,7 @@ class LinkSource:
def
links
(
self
)
->
Iterator
[
Link
]:
def
links
(
self
)
->
Iterator
[
Link
]:
raise
NotImplementedError
()
raise
NotImplementedError
()
def
link_package_data
(
self
,
link
:
Link
)
->
Package
:
def
link_package_data
(
self
,
link
:
Link
)
->
Package
|
None
:
name
,
version
=
None
,
None
name
,
version
=
None
,
None
m
=
wheel_file_re
.
match
(
link
.
filename
)
or
sdist_file_re
.
match
(
link
.
filename
)
m
=
wheel_file_re
.
match
(
link
.
filename
)
or
sdist_file_re
.
match
(
link
.
filename
)
...
@@ -76,8 +79,13 @@ class LinkSource:
...
@@ -76,8 +79,13 @@ class LinkSource:
if
match
:
if
match
:
version_string
=
match
.
group
(
2
)
version_string
=
match
.
group
(
2
)
with
contextlib
.
suppress
(
ValueError
)
:
try
:
version
=
Version
.
parse
(
version_string
)
version
=
Version
.
parse
(
version_string
)
except
ValueError
:
logger
.
debug
(
"Skipping url (
%
s) due to invalid version (
%
s)"
,
link
.
url
,
version
)
return
None
return
Package
(
name
,
version
,
source_url
=
link
.
url
)
return
Package
(
name
,
version
,
source_url
=
link
.
url
)
...
@@ -87,7 +95,7 @@ class LinkSource:
...
@@ -87,7 +95,7 @@ class LinkSource:
for
link
in
self
.
links
:
for
link
in
self
.
links
:
pkg
=
self
.
link_package_data
(
link
)
pkg
=
self
.
link_package_data
(
link
)
if
pkg
.
name
==
name
and
pkg
.
version
and
pkg
.
version
==
version
:
if
pkg
and
pkg
.
name
==
name
and
pkg
.
version
and
pkg
.
version
==
version
:
yield
link
yield
link
def
clean_link
(
self
,
url
:
str
)
->
str
:
def
clean_link
(
self
,
url
:
str
)
->
str
:
...
...
tests/repositories/fixtures/legacy/invalid-version.html
0 → 100644
View file @
cd3026f7
<!DOCTYPE html>
<html>
<head>
<title>
Links for poetry
</title>
</head>
<body>
<h1>
Links for poetry
</h1>
<a
href=
"poetry-21.07.28.5ffb65e2ff8067c732e2b178d03b707c7fb27855-py3-none-any.whl#sha256=1d85132efab8ead3c6f69202843da40a03823992091c29f8d65a31af68940163"
data-requires-python=
">=3.6.0"
>
poetry-21.07.28.5ffb65e2ff8067c732e2b178d03b707c7fb27855-py3-none-any.whl
</a><br/>
<a
href=
"poetry-0.1.0-py3-none-any.whl#sha256=1d85132efab8ead3c6f69202843da40a03823992091c29f8d65a31af68940163"
data-requires-python=
">=3.6.0"
>
poetry-0.1.0-py3-none-any.whl
</a><br/>
</body>
</html>
<!--SERIAL 3907384-->
tests/repositories/test_legacy_repository.py
View file @
cd3026f7
...
@@ -82,6 +82,37 @@ def test_page_clean_link():
...
@@ -82,6 +82,37 @@ def test_page_clean_link():
assert
cleaned
==
"https://legacy.foo.bar/test
%20
/the
%22
/cleaning
%00
"
assert
cleaned
==
"https://legacy.foo.bar/test
%20
/the
%22
/cleaning
%00
"
def
test_page_invalid_version_link
():
repo
=
MockRepository
()
page
=
repo
.
_get_page
(
"/invalid-version"
)
links
=
list
(
page
.
links
)
assert
len
(
links
)
==
2
versions
=
list
(
page
.
versions
(
"poetry"
))
assert
len
(
versions
)
==
1
assert
versions
[
0
]
.
to_string
()
==
"0.1.0"
invalid_link
=
None
for
link
in
links
:
if
link
.
filename
.
startswith
(
"poetry-21"
):
invalid_link
=
link
break
links_010
=
list
(
page
.
links_for_version
(
"poetry"
,
versions
[
0
]))
assert
invalid_link
not
in
links_010
assert
invalid_link
assert
not
page
.
link_package_data
(
invalid_link
)
packages
=
list
(
page
.
packages
)
assert
len
(
packages
)
==
1
assert
packages
[
0
]
.
name
==
"poetry"
assert
packages
[
0
]
.
version
.
to_string
()
==
"0.1.0"
def
test_sdist_format_support
():
def
test_sdist_format_support
():
repo
=
MockRepository
()
repo
=
MockRepository
()
page
=
repo
.
_get_page
(
"/relative"
)
page
=
repo
.
_get_page
(
"/relative"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment