From f4af97112f214455e34a291c2df7a6d9d82541a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Fredrik=20Ki=C3=A6r?= <31612826+anders-kiaer@users.noreply.github.com> Date: Thu, 29 Apr 2021 15:32:37 +0200 Subject: [PATCH] Support + test source_url/download_url combinations (#435) --- CHANGELOG.md | 2 + tests/test_docker_setup.py | 50 +++++++++++++++++++ .../_dockerize/_create_docker_setup.py | 4 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/test_docker_setup.py diff --git a/CHANGELOG.md b/CHANGELOG.md index f4335b3a..9869712b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ from `deprecated_decorators.py` to `_config_parser.py`. Simplified deprecation w `deprecated_plugin` decorator with `Type[WebvizPluginABC]`. - [#433](https://github.com/equinor/webviz-config/pull/433) - Removed short message from `deprecated_plugin` decorator. +- [#435](https://github.com/equinor/webviz-config/pull/435) - Support only specifying +`source_url` in `setup.py` when building Dockerfile. ## [0.3.0] - 2021-04-27 diff --git a/tests/test_docker_setup.py b/tests/test_docker_setup.py new file mode 100644 index 00000000..0fe0cc31 --- /dev/null +++ b/tests/test_docker_setup.py @@ -0,0 +1,50 @@ +import pytest + +from webviz_config._dockerize._create_docker_setup import get_python_requirements + + +@pytest.mark.parametrize( + "distributions, requirements", + [ + ( + { + "webviz-config": { + "download_url": "https://pypi.org/project/webviz-config", + "source_url": None, + "dist_version": "0.3.0", + } + }, + ["webviz-config==0.3.0"], + ), + ( + { + "webviz-config": { + "download_url": None, + "source_url": None, + "dist_version": "0.3.0", + } + }, + [], + ), + ( + { + "webviz-config": { + "download_url": None, + "source_url": "https://github.com/equinor/webviz-config", + "dist_version": "0.3.0", + } + }, + ["git+https://github.com/equinor/webviz-config@0.3.0"], + ), + ], +) +def test_derived_requirements(distributions, requirements): + with pytest.warns(None) as record: + assert requirements == get_python_requirements(distributions) + assert len(record) == len( + [ + metadata + for metadata in distributions.values() + if metadata["download_url"] is None and metadata["source_url"] is None + ] + ) diff --git a/webviz_config/_dockerize/_create_docker_setup.py b/webviz_config/_dockerize/_create_docker_setup.py index 5b694555..b26a6629 100644 --- a/webviz_config/_dockerize/_create_docker_setup.py +++ b/webviz_config/_dockerize/_create_docker_setup.py @@ -67,7 +67,9 @@ def get_python_requirements(distributions: dict) -> List[str]: ) continue - if dist["download_url"].startswith(PYPI_URL_ROOT): + if dist["download_url"] is not None and dist["download_url"].startswith( + PYPI_URL_ROOT + ): pypi_data = requests.get(f"{PYPI_URL_ROOT}/pypi/{dist_name}/json").json() if dist["dist_version"] in pypi_data["releases"]: requirements.append(f"{dist_name}=={dist['dist_version']}")