Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow external repo double stacking #324

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions nomenclature/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
"No external repos allowed in external repo, found in "
f"nomenclature.yaml in '{self.url}'"
)
)


class DataStructureConfig(BaseModel):
Expand Down
6 changes: 6 additions & 0 deletions tests/data/double_stacked_external_repo/nomenclature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repositories:
common-definitions:
url: https://github.com/IAMconsortium/common-definitions.git/
definitions:
region:
repository: common-definitions
12 changes: 12 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "No external repos allowed in external repo"
with raises(ValueError, match=match):
repo.check_external_repo_double_stacking()
Loading