From 47509e774af06190ff87cc51a8e9bbb213282184 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 16 Oct 2017 13:58:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Fix=20odoo=20core=20addon=20taki?= =?UTF-8?q?ng=20priority=20over=20extra=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #84 introduced a regression that violated [the addon priority table](https://github.com/Tecnativa/docker-odoo-base#optodoocustomsrcaddonsyaml). This fixes the regression and tests it. --- lib/odoobaselib/__init__.py | 38 ++++++++----------- tests/__init__.py | 4 ++ .../scaffoldings/dotd/custom/src/addons.yaml | 1 + .../custom/src/dummy_repo/product/__init__.py | 0 4 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 tests/scaffoldings/dotd/custom/src/dummy_repo/product/__init__.py diff --git a/lib/odoobaselib/__init__.py b/lib/odoobaselib/__init__.py index c2504986..7760c839 100644 --- a/lib/odoobaselib/__init__.py +++ b/lib/odoobaselib/__init__.py @@ -41,8 +41,7 @@ def addons_config(): """Yield addon name and path from ``ADDONS_YAML``.""" config = dict() - private_done = False - core_done = False + special_missing = {PRIVATE, CORE} try: with open(ADDONS_YAML) as addons_file: for doc in yaml.load_all(addons_file): @@ -53,11 +52,8 @@ def addons_config(): continue # Flatten all sections in a single dict for repo, addons in doc.items(): - if repo == PRIVATE: - private_done = True - elif repo == CORE: - core_done = True logging.debug("Processing %s repo", repo) + special_missing.discard(repo) for glob in addons: logging.debug("Expanding glob %s", glob) for addon in iglob(os.path.join(SRC_DIR, repo, glob)): @@ -66,31 +62,27 @@ def addons_config(): config.setdefault(addon, set()) config[addon].add(repo) except IOError: - logging.debug('Could not find addons configuration yml.') + logging.debug('Could not find addons configuration yaml.') # By default, all private and core addons are enabled - if not private_done: - logging.debug("Auto-adding all private repo addons") - config.update({ - os.path.basename(addon): {PRIVATE} - for addon in iglob(os.path.join(SRC_DIR, PRIVATE, "*")) - }) - if not core_done: - logging.debug("Auto-adding all core repo addons") - config.update({ - os.path.basename(addon): {CORE} - for addon in iglob(os.path.join(SRC_DIR, CORE, "*")) - }) + for repo in special_missing: + logging.debug("Auto-adding all addons from %s", repo) + for addon in iglob(os.path.join(SRC_DIR, repo, "*")): + addon = os.path.basename(addon) + config.setdefault(addon, set()) + config[addon].add(repo) logging.debug("Resulting configuration: %r", config) for addon, repos in config.items(): # Private addons are most important if PRIVATE in repos: yield addon, PRIVATE + continue # Odoo core addons are least important - elif repos == {CORE}: + if repos == {CORE}: yield addon, CORE + continue + repos.discard(CORE) # Other addons fall in between - elif len(repos) != 1: + if len(repos) != 1: logging.error("Addon %s defined in several repos %s", addon, repos) raise Exception - else: - yield addon, repos.pop() + yield addon, repos.pop() diff --git a/tests/__init__.py b/tests/__init__.py index 7bbe784b..d1a1a8f7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -179,6 +179,10 @@ def test_dotd(self): ("test", "-d", "custom/src/private/private_addon"), ("test", "-f", "custom/src/private/private_addon/__init__.py"), ("test", "-e", "auto/addons/private_addon"), + # Addon from extra repo takes higher priority than core version + ("realpath", "auto/addons/product"), + ("bash", "-c", 'test "$(realpath auto/addons/product)" == ' + '/opt/odoo/custom/src/dummy_repo/product'), # ``odoo`` command works ("odoo", "--version"), # Implicit ``odoo`` command also works diff --git a/tests/scaffoldings/dotd/custom/src/addons.yaml b/tests/scaffoldings/dotd/custom/src/addons.yaml index 9d859568..58822a39 100644 --- a/tests/scaffoldings/dotd/custom/src/addons.yaml +++ b/tests/scaffoldings/dotd/custom/src/addons.yaml @@ -1,5 +1,6 @@ dummy_repo: - dummy_addon + - product --- ONLY: diff --git a/tests/scaffoldings/dotd/custom/src/dummy_repo/product/__init__.py b/tests/scaffoldings/dotd/custom/src/dummy_repo/product/__init__.py new file mode 100644 index 00000000..e69de29b