Skip to content

Commit

Permalink
🚑 Fix odoo core addon taking priority over extra version
Browse files Browse the repository at this point in the history
Pull #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.
  • Loading branch information
yajo committed Oct 16, 2017
1 parent bf0ee7e commit 5b9f706
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ env:
global:
# Variables found by default in Docker Hub builder
- DOCKER_REPO=tecnativa/odoo-base
- DOCKER_TAG=latest
- IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
matrix:
- DOCKER_TAG=8.0 ODOO_VERSIONS=8.0
- DOCKER_TAG=9.0 ODOO_VERSIONS=9.0
- DOCKER_TAG=10.0 ODOO_VERSIONS=10.0
- DOCKER_TAG=11.0 ODOO_VERSIONS=11.0
- DOCKER_TAG=8.0
- DOCKER_TAG=9.0
- DOCKER_TAG=10.0
- DOCKER_TAG=11.0

before_install:
- sudo apt-get update
Expand Down
4 changes: 4 additions & 0 deletions hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ else
dockerfile="$DOCKER_TAG.Dockerfile"
fi

if [ -z "$IMAGE_NAME" ]; then
IMAGE_NAME="$DOCKER_REPO:$DOCKER_TAG"
fi

# See http://label-schema.org/rc1/#build-time-labels
time docker image build \
--build-arg VCS_REF="$GIT_SHA1" \
Expand Down
38 changes: 15 additions & 23 deletions lib/odoobaselib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)):
Expand All @@ -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()
6 changes: 5 additions & 1 deletion tests/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
DIR = dirname(__file__)
ODOO_PREFIX = ("odoo", "--stop-after-init", "--workers=0")
ODOO_VERSIONS = frozenset(environ.get(
"ODOO_VERSIONS", "8.0 9.0 10.0 11.0").split())
"DOCKER_TAG", "8.0 9.0 10.0 11.0").split())
PG_VERSIONS = frozenset(environ.get(
"PG_VERSIONS", "9.6").split())
SCAFFOLDINGS_DIR = join(DIR, "scaffoldings")
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/scaffoldings/dotd/custom/src/addons.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dummy_repo:
- dummy_addon
- product

---
ONLY:
Expand Down
Empty file.

0 comments on commit 5b9f706

Please sign in to comment.