From ca6ba820383d14f0484ab6701ec44d2b7764a33e Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Mon, 29 Jul 2024 11:59:33 +0200 Subject: [PATCH] Allow [[tool.poetry.source]] to be defined without any URL Fixes: https://github.com/thoth-station/micropipenv/issues/292 --- micropipenv.py | 5 ++- .../poetry_source_without_url/poetry.lock | 44 +++++++++++++++++++ .../poetry_source_without_url/pyproject.toml | 19 ++++++++ tests/test_micropipenv.py | 31 +++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 tests/data/parse/poetry_source_without_url/poetry.lock create mode 100644 tests/data/parse/poetry_source_without_url/pyproject.toml diff --git a/micropipenv.py b/micropipenv.py index 49b5f04..9bc7fce 100755 --- a/micropipenv.py +++ b/micropipenv.py @@ -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) diff --git a/tests/data/parse/poetry_source_without_url/poetry.lock b/tests/data/parse/poetry_source_without_url/poetry.lock new file mode 100644 index 0000000..329f099 --- /dev/null +++ b/tests/data/parse/poetry_source_without_url/poetry.lock @@ -0,0 +1,44 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + +[[package]] +name = "daiquiri" +version = "2.0.0" +description = "Library to configure Python logging easily" +optional = false +python-versions = "*" +files = [ + {file = "daiquiri-2.0.0-py2.py3-none-any.whl", hash = "sha256:d57b9fd5432933c6e899054eb62cee22eab89f560c8493254d327ec27893c866"}, + {file = "daiquiri-2.0.0.tar.gz", hash = "sha256:6b235ed15b73b87fd3cc2521aacbb727bf8443a0896dc534b07503841d03cfdb"}, +] + +[package.dependencies] +python-json-logger = "*" + +[package.extras] +systemd = ["systemd-python (>=234)"] +test = ["mock", "pytest", "six"] + +[[package]] +name = "flexmock" +version = "0.10.10" +description = "flexmock is a testing library for Python that makes it easy to create mocks,stubs and fakes." +optional = false +python-versions = "*" +files = [ + {file = "flexmock-0.10.10.tar.gz", hash = "sha256:8bb073f4b7b590672e8c312e73d6a14f88ae624a867b691462f9e8c24b9f19d1"}, +] + +[[package]] +name = "python-json-logger" +version = "0.1.11" +description = "A python library adding a json log formatter" +optional = false +python-versions = ">=2.7" +files = [ + {file = "python-json-logger-0.1.11.tar.gz", hash = "sha256:b7a31162f2a01965a5efb94453ce69230ed208468b0bbc7fdfc56e6d8df2e281"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "*" +content-hash = "735029730bde8fac7a13976310edf93d63ef123733a43758632ed3e2879c22ec" diff --git a/tests/data/parse/poetry_source_without_url/pyproject.toml b/tests/data/parse/poetry_source_without_url/pyproject.toml new file mode 100644 index 0000000..0c178cd --- /dev/null +++ b/tests/data/parse/poetry_source_without_url/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "aaa" +version = "0.1.0" +description = "" +authors = ["Fridolin Pokorny "] + +[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" diff --git a/tests/test_micropipenv.py b/tests/test_micropipenv.py index 11b6a76..b71280f 100644 --- a/tests/test_micropipenv.py +++ b/tests/test_micropipenv.py @@ -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", [