diff --git a/lib/odoobaselib/__init__.py b/lib/odoobaselib/__init__.py index c2504986..f4776936 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,20 +62,14 @@ 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 @@ -88,8 +78,10 @@ def addons_config(): # Odoo core addons are least important elif repos == {CORE}: yield addon, CORE + else: + 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: diff --git a/tests/__init__.py b/tests/__init__.py index 6a862d64..f7d45272 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -179,6 +179,9 @@ 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 + ("bash", "-c", 'test "$(realpath auto/addons/sale)" == ' + '/opt/odoo/custom/src/dummy_repo/sale'), # ``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..cae8389d 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 + - sale --- ONLY: diff --git a/tests/scaffoldings/dotd/custom/src/dummy_repo/sale/__init__.py b/tests/scaffoldings/dotd/custom/src/dummy_repo/sale/__init__.py new file mode 100644 index 00000000..e69de29b