Skip to content

Commit

Permalink
Support having zero distros defined by a URI config
Browse files Browse the repository at this point in the history
This is useful for testing distros using forced_requirements(-r distro_a)
  • Loading branch information
MHendricks committed Nov 22, 2023
1 parent f0048ed commit 15c3e8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 9 additions & 3 deletions hab/parsers/flat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
{
Expand All @@ -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"),
}
Expand All @@ -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",
Expand Down

0 comments on commit 15c3e8e

Please sign in to comment.