Skip to content
Snippets Groups Projects

:bookmark: 20.7.0

3 files
+ 7
1
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 82
36
@@ -8,7 +8,7 @@ import sys
from ast import literal_eval
from collections import OrderedDict, defaultdict
from glob import glob
from typing import Any, Dict, List, Optional, Union
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
try:
# Python 3.11+
@@ -104,10 +104,8 @@ class Configuration:
if "path" not in value:
_logger.error("Expansion without path for %s", name)
raise Exception("Expansion without path for %s" % name)
# put in relative_path the relative path between this and the
# parent.
# this allows blacklisting odoo-mint/theme when expanding
# mint hr.
# put in relative_path the relative path between this and the parent.
# this allows blacklisting odoo-mint/theme when expanding mint hr.
if parent_configuration:
# difference between this path and the parents
relative_path = os.path.join(
@@ -174,7 +172,50 @@ class Configuration:
)
setattr(self, key, list(set_values))
self.python_packages: Dict[str, Dict[str, str]]
def read_expanded(
key: str,
default_value=None,
value_formatter: Optional[Callable[[str], Any]] = None,
):
"""Read from local version, or from expanded if value is found.
Raise an exception if more than one value is found."""
value = default_value
if toread(key):
found = False
for config in self._expanded_configuration.values():
if hasattr(config, key):
if found:
raise Exception(
"Key %s to read in several expanded "
"configurations" % key
)
value = getattr(config, key)
found = True
if key in section:
local_value = section.get(key, default_value)
if value_formatter is not None:
local_value = value_formatter(local_value)
if found and value != default_value and local_value != value:
raise Exception(
"Key %s in expanded configuration and locally set"
" with different values" % key
)
value = local_value
if toread(key):
setattr(self, key, value)
def version_formatter(value: str) -> Tuple[int, int, int]:
version_tuple = value.split(".")
return (
int(version_tuple[0]) if len(version_tuple) >= 1 else 0,
int(version_tuple[1]) if len(version_tuple) >= 2 else 0,
int(version_tuple[2]) if len(version_tuple) >= 3 else 0,
)
self.min_version: Tuple[int, int, int]
read_expanded("min_version", (0, 0, 0), version_formatter)
self.python_packages: Dict[str, Dict[str, Union[str, List[Tuple[str, str]]]]]
if toread("python_packages"):
self.python_packages = OrderedDict()
# add any expanded values
@@ -188,11 +229,42 @@ class Configuration:
section.get("python_packages", "{}")
).items():
value_with_default = {
"mount": ".",
"target": os.path.join("odoo", "addons", os.path.basename(key)),
"compile": "True",
"dirs": [],
"compile": value.get("compile", "True"),
}
value_with_default.update(value)
# previously authorized keys.
if "mount" in value or "target" in value:
simple_options = (
value.get("mount", "."),
value.get(
"target",
os.path.join("odoo", "addons", os.path.basename(key)),
),
)
value_with_default["dirs"].append(simple_options)
if "dirs" in value:
for element in value["dirs"]:
value_with_default["dirs"].append(
(
element.get("mount", "."),
element.get(
"target",
os.path.join(
"odoo",
"addons",
os.path.basename(
element["mount"]
if "mount" in element
else key
),
),
),
)
)
elif "mount" not in value and "target" not in value:
value_with_default["dirs"].append(
(".", os.path.join("odoo", "addons", os.path.basename(key)))
)
self.python_packages[key] = value_with_default
self.addons_path = {os.path.dirname(module) for module in self.modules}
@@ -232,32 +304,6 @@ class Configuration:
):
setattr(self, key_format(key), section.get(key, None))
def read_expanded(key: str, default_value=None):
"""Read from local version, or from expanded if value is found.
Raise an exception if more than one value is found."""
value = default_value
if toread(key):
found = False
for config in self._expanded_configuration.values():
if hasattr(config, key):
if found:
raise Exception(
"Key %s to read in several expanded "
"configurations" % key
)
value = getattr(config, key)
found = True
if key in section:
local_value = section.get(key, default_value)
if found and value != default_value and local_value != value:
raise Exception(
"Key %s in expanded configuration and locally set"
" with different values" % key
)
value = local_value
if toread(key):
setattr(self, key, value)
self.registry: Optional[str] = (
section.get("registry", "registry.xcg.io") if registry is None else registry
)
Loading