Skip to content

Commit

Permalink
Allow [[tool.poetry.source]] to be defined without any URL
Browse files Browse the repository at this point in the history
Fixes: #292
  • Loading branch information
frenzymadness committed Jul 29, 2024
1 parent bd9f31b commit ca6ba82
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
5 changes: 4 additions & 1 deletion micropipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,10 @@ def _poetry2pipfile_lock(
sources = []
has_default = False # If default flag is set, it disallows PyPI.
for item in pyproject_poetry_section.get("source", []):
sources.append({"name": item["name"], "url": item["url"], "verify_ssl": True})
source = {"name": item["name"], "verify_ssl": True}
if item.get("url"):
source["url"] = item.get("url")
sources.append(source)

has_default = has_default or item.get("default", False)

Expand Down
44 changes: 44 additions & 0 deletions tests/data/parse/poetry_source_without_url/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tests/data/parse/poetry_source_without_url/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "aaa"
version = "0.1.0"
description = ""
authors = ["Fridolin Pokorny <[email protected]>"]

[tool.poetry.dependencies]
daiquiri = "2.0.0"

[tool.poetry.dev-dependencies]
flexmock = "^0.10.4"

[[tool.poetry.source]]
name = "PyPI"
priority = "primary"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
31 changes: 31 additions & 0 deletions tests/test_micropipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,37 @@ def test_parse_poetry2pipfile_lock(directory, options, expected_file):
assert python_version == "{}.{}".format(sys.version_info.major, sys.version_info.minor)


def test_parse_poetry2pipfile_source_without_url():
"""Test parsing Poetry files with source without URL"""
work_dir = os.path.join(_DATA_DIR, "parse", "poetry_source_without_url")
with cwd(work_dir):
pipfile_lock = micropipenv._poetry2pipfile_lock(only_direct=True)

python_version = pipfile_lock["_meta"]["requires"].pop("python_version")
assert python_version == "{}.{}".format(sys.version_info.major, sys.version_info.minor)

assert pipfile_lock == {
"_meta": {
"hash": {"sha256": "735029730bde8fac7a13976310edf93d63ef123733a43758632ed3e2879c22ec"},
"pipfile-spec": 6,
"requires": {},
"sources": [
{
"name": "5a06749b2297be54ac5699f6f2761716adc5001a2d5f8b915ab2172922dd5706",
"url": "https://pypi.org/simple",
"verify_ssl": True,
},
{
"name": "PyPI",
"verify_ssl": True,
},
],
},
"default": {"daiquiri": "==2.0.0"},
"develop": {"flexmock": "^0.10.4"},
}


@pytest.mark.parametrize(
"test,options,expected_file",
[
Expand Down

0 comments on commit ca6ba82

Please sign in to comment.