Skip to content
Snippets Groups Projects
Commit b1c45187 authored by Ronald Jäpel's avatar Ronald Jäpel
Browse files

Improve handling of paths

parent ea281620
No related branches found
No related tags found
No related merge requests found
import os
from pathlib import Path
import contextlib
import glob
import json
import os
import shutil
import sys
import traceback
from datetime import datetime
import shutil
import time
import contextlib
import glob
from pathlib import Path
from stat import S_IREAD, S_IWRITE
from urllib.request import urlretrieve
......@@ -176,8 +175,12 @@ class BaseRepo:
:return:
Path to the cloned repository
"""
if "://" in str(source_repo_location):
source_repo_name = source_repo_location.split("/")[-1]
else:
source_repo_name = Path(source_repo_location).name
if target_repo_location is None:
target_repo_location = self.working_dir / "external_cache" / source_repo_location.split("/")[-1]
target_repo_location = self.working_dir / "external_cache" / source_repo_name
else:
target_repo_location = self.working_dir / target_repo_location
......@@ -235,6 +238,9 @@ class BaseRepo:
target_repo_location = str(self.ensure_relative_path(target_repo_location))
if isinstance(source_repo_location, Path):
source_repo_location = source_repo_location.as_posix()
rdm_cache[target_repo_location] = {
"source_repo_location": source_repo_location,
"branch_name": source_repo_branch,
......
from pathlib import Path
import os
import random
from pathlib import Path
import pytest
import git
import numpy as np
import pytest
from cadetrdm import initialize_repo, ProjectRepo, clone
from cadetrdm.initialize_repo import init_lfs
from cadetrdm.repositories import OutputRepo, BaseRepo
from cadetrdm.io_utils import delete_path
from cadetrdm.repositories import OutputRepo, BaseRepo
@pytest.fixture(scope="module")
......@@ -158,7 +158,7 @@ def test_init_over_existing_repo(monkeypatch):
def test_cache_with_non_rdm_repo(monkeypatch):
path_to_repo = Path("test_repo_5")
path_to_repo = Path("non_rdm_repo")
if path_to_repo.exists():
delete_path(path_to_repo)
os.makedirs(path_to_repo)
......@@ -172,15 +172,22 @@ def test_cache_with_non_rdm_repo(monkeypatch):
repo.git.add(".")
repo.git.commit("-m", "Initial commit")
imported_repo = OutputRepo("../test_repo/results")
branch_name = imported_repo.active_branch.name
os.chdir("..")
if Path("test_repo_non_rdm_imports").exists():
delete_path("test_repo_non_rdm_imports")
initialize_repo("test_repo_non_rdm_imports")
os.chdir("test_repo_non_rdm_imports")
repo = BaseRepo(".")
if Path("external_cache/non_rdm_repo").exists():
delete_path("external_cache/non_rdm_repo")
if Path("foo/bar/non_rdm_repo").exists():
delete_path("foo/bar/non_rdm_repo")
# import two repos and confirm verify works.
repo.import_remote_repo(source_repo_location="../test_repo/results", source_repo_branch=branch_name)
repo.import_remote_repo(source_repo_location="../test_repo/results", source_repo_branch=branch_name,
target_repo_location="foo/bar/repo")
repo.import_remote_repo(source_repo_location=".." / path_to_repo, source_repo_branch="master")
repo.import_remote_repo(source_repo_location=".." / path_to_repo, source_repo_branch="master",
target_repo_location="foo/bar/non_rdm_repo")
repo.verify_unchanged_cache()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment