From c2ca25a934b29e1e02fabbca982623ce211791ea Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 14 May 2024 11:19:17 -0500 Subject: [PATCH] fix: fix type hints for _parse_requirement() (#92) --- .../_config.py | 2 +- .../invalid/pip-no-list/dependencies.yaml | 18 ++++++++++++++++++ tests/test_config.py | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/examples/invalid/pip-no-list/dependencies.yaml diff --git a/src/rapids_dependency_file_generator/_config.py b/src/rapids_dependency_file_generator/_config.py index d6500370..550f8d35 100644 --- a/src/rapids_dependency_file_generator/_config.py +++ b/src/rapids_dependency_file_generator/_config.py @@ -178,7 +178,7 @@ def get_extras(): ) -def _parse_requirement(requirement: typing.Union[str, dict[str, str]]) -> typing.Union[str, PipRequirements]: +def _parse_requirement(requirement: typing.Union[str, dict[str, list[str]]]) -> typing.Union[str, PipRequirements]: if isinstance(requirement, str): return requirement diff --git a/tests/examples/invalid/pip-no-list/dependencies.yaml b/tests/examples/invalid/pip-no-list/dependencies.yaml new file mode 100644 index 00000000..98bc6fde --- /dev/null +++ b/tests/examples/invalid/pip-no-list/dependencies.yaml @@ -0,0 +1,18 @@ +# tests that dfg rejects a config where 'pip:' in a conda requirements is a single string +# (it should always be an array of packages) +files: + build: + output: conda + includes: + - build +channels: + - rapidsai + - conda-forge +dependencies: + build: + common: + - output_types: [conda] + packages: + - beep-boop=1.2.3 + - pip + - pip: pandas diff --git a/tests/test_config.py b/tests/test_config.py index 823fda75..2aab8af0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -38,7 +38,7 @@ def test_parse_outputs(input, output): ["input", "output"], [ ("package", "package"), - ({"pip": "package"}, _config.PipRequirements(pip="package")), + ({"pip": ["package", "other-package"]}, _config.PipRequirements(pip=["package", "other-package"])), ({"other": "invalid"}, KeyError), ], )