From 15c3e8eae9c08f14809674b8d801f0fdf5e7aa88 Mon Sep 17 00:00:00 2001 From: Mike Hendricks Date: Fri, 18 Aug 2023 15:53:19 -0700 Subject: [PATCH] Support having zero distros defined by a URI config This is useful for testing distros using forced_requirements(-r distro_a) --- hab/parsers/flat_config.py | 12 +++++++++--- tests/test_resolver.py | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/hab/parsers/flat_config.py b/hab/parsers/flat_config.py index 7b29c1c..0d10a81 100644 --- a/hab/parsers/flat_config.py +++ b/hab/parsers/flat_config.py @@ -197,8 +197,14 @@ def freeze(self): @hab_property(verbosity=1) def versions(self): - if self.distros is NotSet: - return [] + distros = self.distros + if distros is NotSet: + if self.resolver.forced_requirements: + distros = {} + else: + return [] + if distros == []: + distros = {} # Lazily load the contents of versions the first time it's called if "versions" not in self.frozen_data: @@ -207,7 +213,7 @@ def versions(self): self._alias_mods = {} self.frozen_data["versions"] = versions - reqs = self.resolver.resolve_requirements(self.distros) + reqs = self.resolver.resolve_requirements(distros) for req in reqs.values(): version = self.resolver.find_distro(req) versions.append(version) diff --git a/tests/test_resolver.py b/tests/test_resolver.py index 3622de4..ab1d8d9 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -486,10 +486,14 @@ def test_resolve_requirements_markers(resolver, platform, marker): @pytest.mark.parametrize( - "forced,check", + "forced,check,check_versions", ( # No forced items - (None, ["the_dcc_plugin_a", "the_dcc_plugin_d", "the_dcc_plugin_e<1.0,<2.0"]), + ( + None, + ["the_dcc_plugin_a", "the_dcc_plugin_d", "the_dcc_plugin_e<1.0,<2.0"], + [], + ), # Force ( { @@ -504,12 +508,13 @@ def test_resolve_requirements_markers(resolver, platform, marker): "the_dcc_plugin_d", "the_dcc_plugin_e==1.1", ], + ["the_dcc_plugin_c==1.1", "the_dcc_plugin_e==1.1"], ), ), ) -def test_forced_requirements(resolver, helpers, forced, check): +def test_forced_requirements(resolver, helpers, forced, check, check_versions): requirements = { - # plugin_a adds an extra dependency outside of the requiremets or forced + # plugin_a adds an extra dependency outside of the requirements or forced "the_dcc_plugin_a": Requirement("the_dcc_plugin_a"), "the_dcc_plugin_e": Requirement("the_dcc_plugin_e<1.0"), } @@ -522,6 +527,13 @@ def test_forced_requirements(resolver, helpers, forced, check): resolved = resolver_forced.resolve_requirements(requirements) helpers.assert_requirements_equal(resolved, check) + # Check that forced_requirements work if the config defines zero distros + cfg = resolver_forced.resolve("not_set/no_distros") + versions = cfg.versions + assert len(versions) == len(check_versions) + for i, v in enumerate(versions): + assert v.name == check_versions[i] + @pytest.mark.parametrize( "value,check",