Skip to content

Commit 0cf36b6

Browse files
committed
Deprecate omittable_distros in favor of stub_distros
Stub_distros is more powerful and flexible. This will automatically convert any existing omittable_distros in configs to config stub_distros. It shows a warning about converting any omittable_distros encountered to stubs.
1 parent fc1a501 commit 0cf36b6

19 files changed

+96
-372
lines changed

README.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,26 +1404,10 @@ create a stub for the requirement `the_dcc==1.3` but not for a requirement of
14041404

14051405
### Omittable Distros
14061406

1407-
The `omittable_distros` key in [config](#config) definitions are used to specify distros
1408-
that are not required to use this hab configuration. This can be used to make it
1409-
so not all hosts need to have a dcc installed. For example a producer likely will
1410-
never need to open houdini but does need access to external tools. You would need
1411-
to install Houdini(or create a empty .hab.json distro) so hab doesn't raise an
1412-
`InvalidRequirementError` when it can't find Houdini.
1413-
1414-
```json5
1415-
"distros": [
1416-
"houdini20.0==20.0.688",
1417-
"SideFXLabs20.0==20.0.506",
1418-
"python_tools"
1419-
],
1420-
"omittable_distros": [
1421-
"houdini20.0",
1422-
"SideFXLabs20.0"
1423-
]
1424-
```
1425-
This will make it so `houdini20.0` and `SideFXLabs20.0` will be loaded if found,
1426-
but if not they will be ignored. `python_tools` will always need to be installed.
1407+
The `omittable_distros` key in [config](#config) definitions is deprecated and should
1408+
be converted to config based [stub_distros](#stub-distros). For now hab will automatically
1409+
do this conversion but will print a warning when it does. This will be removed
1410+
in the future. The Config `omittable_distros` property has been removed.
14271411

14281412
Note: `omittable_distros` is a list of distro names. It does not accept specifier
14291413
arguments like `==20.0.688`.

hab/parsers/config.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,26 @@ def load(self, filename):
129129
data = super().load(filename)
130130
self._alias_mods = data.get("alias_mods", NotSet)
131131
self.inherits = data.get("inherits", NotSet)
132-
if self.omittable_distros is NotSet:
133-
self.omittable_distros = data.get("omittable_distros", NotSet)
134132
if self.stub_distros is NotSet:
135133
self.stub_distros = data.get("stub_distros", NotSet)
136-
return data
137134

138-
@hab_property(verbosity=3, process_order=50)
139-
def omittable_distros(self):
140-
"""A collection of distro names that are ignored if required by distros."""
141-
return self.frozen_data.get("omittable_distros", NotSet)
135+
# Handle legacy omittable_distros by convert it to stub_distros.
136+
# NOTE: This will be removed in a future version of hab.
137+
omittable_distros = data.get("omittable_distros", [])
138+
for distro in omittable_distros:
139+
# Only log these warnings if this config is flattened. This prevents
140+
# showing the warning every time hab resolves its configuration
141+
self.log_on_resolve(
142+
logging.WARNING,
143+
'omittable_distros is deprecated, move "{}" to stub_distros '
144+
'in "{}".'.format(distro, self.filename),
145+
logger=logger,
146+
)
147+
if self.stub_distros is NotSet:
148+
self.stub_distros = {}
149+
self.stub_distros.setdefault("set", {}).setdefault(distro, {})
142150

143-
@omittable_distros.setter
144-
def omittable_distros(self, value):
145-
self.frozen_data["omittable_distros"] = value
151+
return data
146152

147153
@hab_property(verbosity=3)
148154
def stub_distros(self):

hab/parsers/flat_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ def versions(self):
231231

232232
# Apply the config level stub_distros before resolving
233233
with self.resolver.site.stub_distros_override(self.stub_distros):
234-
reqs = self.resolver.resolve_requirements(
235-
distros, omittable=self.omittable_distros
236-
)
234+
reqs = self.resolver.resolve_requirements(distros)
237235
for req in reqs.values():
238236
version = self.resolver.find_distro(req)
239237
versions.append(version)

hab/resolver.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,11 @@ def resolve(self, uri, forced_requirements=None):
594594
if forced_requirements is not None:
595595
self.forced_requirements = current
596596

597-
def resolve_requirements(self, requirements, omittable=None):
597+
def resolve_requirements(self, requirements):
598598
"""Recursively solve the provided requirements into a final list of requirements.
599599
600600
Args:
601601
requirements (list): The requirements to resolve.
602-
omittable (list, optional): A list of distro names that are not required.
603-
If a suitable distro can not be found, normally an `InvalidRequirementError`
604-
is raised. If that distro name is in this list a warning is logged instead.
605602
606603
Raises:
607604
MaxRedirectError: Redirect limit reached, unable to resolve the requested
@@ -611,9 +608,7 @@ def resolve_requirements(self, requirements, omittable=None):
611608
if isinstance(requirements, list):
612609
requirements = Solver.simplify_requirements(requirements)
613610

614-
solver = Solver(
615-
requirements, self, forced=self.forced_requirements, omittable=omittable
616-
)
611+
solver = Solver(requirements, self, forced=self.forced_requirements)
617612
return solver.resolve()
618613

619614
def uri_validate(self, uri):

hab/solvers.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@ class Solver(object):
1818
forced (dict, optional): Forces this distro requirement replacing any resolved
1919
requirements. Using this may lead to configuring your environment
2020
incorrectly, use with caution.
21-
omittable (list, optional): A list of distro names that are not required.
22-
If a suitable distro can not be found, normally an `InvalidRequirementError`
23-
is raised. If that distro name is in this list a warning is logged instead.
2421
2522
Attributes:
2623
invalid (dict, optional): If a recursive requirement makes a already resolved
2724
version invalid, that version is added to this list as an exclusive exclude.
2825
"""
2926

30-
def __init__(self, requirements, resolver, forced=None, omittable=None):
27+
def __init__(self, requirements, resolver, forced=None):
3128
self.forced = forced if forced else {}
32-
self.omittable = omittable if omittable else []
3329
self.invalid = {}
3430
self.max_redirects = 2
3531
self.requirements = requirements
@@ -130,10 +126,6 @@ def _resolve(
130126
logger.warning(f"Forced Requirement: {req}")
131127
reported.add(name)
132128

133-
if name in self.omittable and name not in self.resolver.distros:
134-
logger.warning(f"Skipping missing omitted requirement: {req}")
135-
continue
136-
137129
# Update the requirement to match all current requirements
138130
req = self.append_requirement(resolved, req)
139131
if name in self.invalid:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "omittable",
3+
"description": "Legacy testing for omittable_distros. This is replaced by stub_distros.",
4+
"context": ["stub"],
5+
"inherits": false,
6+
"distros": {
7+
"maya2024": null
8+
},
9+
"omittable_distros": [
10+
"missing_dcc",
11+
"non-existent-distro"
12+
]
13+
}

tests/resolver_freeze_configs.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,22 @@
367367
]
368368
},
369369
"stub": "Error resolving stub: Unable to find a distro for requirement: invalid",
370+
"stub/omittable": {
371+
"context": [
372+
"stub"
373+
],
374+
"name": "omittable",
375+
"stub_distros": {
376+
"set": {
377+
"missing_dcc": {},
378+
"non-existent-distro": {}
379+
}
380+
},
381+
"uri": "stub/omittable",
382+
"versions": [
383+
"maya2024==2024.0"
384+
]
385+
},
370386
"stub/override": "Error resolving stub/override: Unable to find a distro for requirement: invalid",
371387
"verbosity": {
372388
"context": [],

tests/site_main_check.habcache

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,21 @@
522522
"inherits": false,
523523
"name": "stub"
524524
},
525+
"{config-root}/configs/stub/stub_omittable.json": {
526+
"context": [
527+
"stub"
528+
],
529+
"description": "Legacy testing for omittable_distros. This is replaced by stub_distros.",
530+
"distros": {
531+
"maya2024": null
532+
},
533+
"inherits": false,
534+
"name": "omittable",
535+
"omittable_distros": [
536+
"missing_dcc",
537+
"non-existent-distro"
538+
]
539+
},
525540
"{config-root}/configs/stub/stub_override.json": {
526541
"context": [
527542
"stub"

tests/site_omit/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/site_omit/configs/default.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)