From 74f892de955759cbcead836780126850be488a36 Mon Sep 17 00:00:00 2001 From: Aleksandr Mezin Date: Fri, 21 Dec 2018 15:07:39 +0600 Subject: [PATCH 1/2] Add test to verify same file 'extends' optimization Signed-off-by: Aleksandr Mezin --- tests/unit/config/config_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 5ad1a2334..0d3f49b99 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -18,6 +18,7 @@ from ...helpers import build_config_details from ...helpers import BUSYBOX_IMAGE_WITH_TAG from compose.config import config from compose.config import types +from compose.config.config import ConfigFile from compose.config.config import resolve_build_args from compose.config.config import resolve_environment from compose.config.environment import Environment @@ -4887,6 +4888,11 @@ class ExtendsTest(unittest.TestCase): assert types.SecurityOpt.parse('apparmor:unconfined') in svc['security_opt'] assert types.SecurityOpt.parse('seccomp:unconfined') in svc['security_opt'] + @mock.patch.object(ConfigFile, 'from_filename', wraps=ConfigFile.from_filename) + def test_extends_same_file_optimization(self, from_filename_mock): + load_from_filename('tests/fixtures/extends/no-file-specified.yml') + from_filename_mock.assert_called_once() + @pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash') class ExpandPathTest(unittest.TestCase): From c24b7b6464b302477728b0882d2fb6bf647f2e79 Mon Sep 17 00:00:00 2001 From: Aleksandr Mezin Date: Fri, 21 Dec 2018 15:03:44 +0600 Subject: [PATCH 2/2] Fix same file 'extends' optimization Signed-off-by: Aleksandr Mezin --- compose/config/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose/config/config.py b/compose/config/config.py index 5202d0025..f64dc04a0 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -615,7 +615,7 @@ class ServiceExtendsResolver(object): config_path = self.get_extended_config_path(extends) service_name = extends['service'] - if config_path == self.config_file.filename: + if config_path == os.path.abspath(self.config_file.filename): try: service_config = self.config_file.get_service(service_name) except KeyError: