diff --git a/nomenclature/config.py b/nomenclature/config.py index 0bfb112f..c0372749 100644 --- a/nomenclature/config.py +++ b/nomenclature/config.py @@ -82,6 +82,20 @@ def fetch_repo(self, to_path): repo.git.clean("-xdf") if self.revision == "main": repo.remotes.origin.pull() + self.check_external_repo_double_stacking() + + def check_external_repo_double_stacking(self): + nomenclature_config = self.local_path / "nomenclature.yaml" + if nomenclature_config.is_file(): + with open(nomenclature_config, "r") as f: + config = yaml.safe_load(f) + if config.get("repositories"): + raise ValueError( + ( + "External repos cannot again refer to external repos, " + f"found in nomenclature.yaml in '{self.url}'" + ) + ) class DataStructureConfig(BaseModel): diff --git a/tests/data/double_stacked_external_repo/nomenclature.yaml b/tests/data/double_stacked_external_repo/nomenclature.yaml new file mode 100644 index 00000000..437e7ed0 --- /dev/null +++ b/tests/data/double_stacked_external_repo/nomenclature.yaml @@ -0,0 +1,6 @@ +repositories: + common-definitions: + url: https://github.com/IAMconsortium/common-definitions.git/ +definitions: + region: + repository: common-definitions diff --git a/tests/test_config.py b/tests/test_config.py index b03fd3e2..9674f08d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -55,3 +55,15 @@ def test_multiple_mapping_repos(): assert nomenclature_config.repositories.keys() == exp_repos finally: clean_up_external_repos(nomenclature_config.repositories) + + +def test_double_stacked_external_repo_raises(monkeypatch): + repo = Repository(url="lorem ipsum") + monkeypatch.setitem( + repo.__dict__, + "local_path", + TEST_DATA_DIR / "double_stacked_external_repo", + ) + match = "External repos cannot again refer to external repos" + with raises(ValueError, match=match): + repo.check_external_repo_double_stacking()