Esempio n. 1
0
            def __call__(self, match):
                name, suffix, rest = match.groups()
                if rest is None:
                    rest = ''

                if not any(name.startswith(p) for p in ('$', '#')):
                    if self.working_dir is None:
                        log.warning(
                            'no working directory found, you will have broken links'
                        )
                        rel = Path(name + suffix)
                    else:
                        try:
                            rel = ((self.current_file.parent /
                                    (name + suffix)).resolve().relative_to(
                                        self.working_dir))
                        except ValueError as e:
                            log.error('path went outside current repo')
                            return name + suffix + rest

                    if suffix in ('.md', '.org', '.ipynb'):
                        rel = rel.with_suffix('.html')

                    rel_path = rel.as_posix() + rest
                    #print('aaaaaaaaaaa', suffix, rel, rel_path)
                    return self.base + rel_path
                elif name.startswith('$'):
                    raise self.MakeMeAnInlineSrcBlock(match.group())
                else:
                    #print('bbbbbbbbbbb', match.group())
                    return match.group()  # rel_path = name + ext + rest
Esempio n. 2
0
def _ontology_data_files():
    resources = 'resources'
    relpaths = [
        'ttl/phenotype-core.ttl',
        'ttl/phenotype-indicators.ttl',
        'ttl/phenotypes.ttl',
        'ttl/generated/part-of-self.ttl',
    ]
    if RELEASE:
        from augpathlib import RepoPath as Path
        ### KILL IT WITH FIRE
        try:
            from neurondm.core import auth  ### this is NOT ok
        except Exception:
            # can't catch an error that you can never import because
            # it will be raised before you can import it ... SIGH
            import orthauth as oa
            from pyontutils.config import auth as pauth
            auth = oa.configure(Path('neurondm/auth-config.py').resolve(),
                                include=pauth)
        ###

        olr = Path(auth.get_path('ontology-local-repo'))

        ### KILL IT WITH FIRE
        if not olr.exists():
            original = auth.get('ontology-local-repo')
            raise FileNotFoundError(
                f'ontology local repo does not exist: {olr}'
                f'path expanded from {original}')
        elif olr.repo.active_branch.name != auth.get('neurons-branch'):
            # FIXME yes indeed having to call Config in a way that is
            # invoked at import time is REALLY REALLY BAD :/
            raise ValueError('git is on the wrong branch! '
                             f'{olr.repo.active_branch}')
        ###

        resources = Path(resources)
        resources.mkdir(
        )  # if we add resources to git, this will error before we delete by accident
        paths = [olr / rp for rp in relpaths]
        for p in paths:
            p.copy_to(resources / p.name)

    else:
        from pathlib import Path
        resources = Path(resources)
        paths = [Path(rp) for rp in relpaths]

    return resources.absolute(), [(resources / p.name).as_posix()
                                  for p in paths]
Esempio n. 3
0
    def test_init_from_local_repo(self):
        rp = testing_base / 'test-repo'
        this_repo_path = RepoPath(__file__).working_dir
        if rp.working_dir is not None:
            pytest.skip('not testing inside another git repo')

        if this_repo_path is None:
            pytest.skip(
                'this test file is not under version control, so there is no local repo'
            )

        else:
            this_repo = this_repo_path.repo
            repo = rp.init(this_repo_path, depth=1)
            assert repo, f'{rp!r} {repo}'
            return rp
Esempio n. 4
0
    def test_stale_repo_cache(self):
        rp = self.test_init()
        rp.repo
        aug.AugmentedPath(
            rp).rmtree()  # have to call rmtree that won't invoke repo.close()
        try:
            rp.repo
            assert False, 'should have failed'
        except exc.NotInRepoError:
            pass

        rp2 = RepoPath(rp)
        try:
            rp2.repo
            assert False, 'should have failed'
        except exc.NotInRepoError:
            pass
Esempio n. 5
0
 def tearDown(self):
     RepoPath(testing_base).rmtree(onerror=onerror)
Esempio n. 6
0
 def test_working_dir(self):
     [RepoPath._repos.pop(k) for k in list(RepoPath._repos)]
     rp = RepoPath(str(self.test_file))
     assert rp.working_dir is not None, f'wat {rp}'
     assert rp.repo is not None, f'wat {rp} {rp.working_dir}'
Esempio n. 7
0
import os
import pathlib
import unittest
import pytest
import augpathlib as aug
from augpathlib import RepoPath, LocalPath, exceptions as exc
from .common import onerror, skipif_no_net, temp_path

testing_base = RepoPath(temp_path)


class HybridPath(RepoPath, LocalPath):
    """ Combined functionality """


HybridPath._bind_flavours()


class TestRepoPath(unittest.TestCase):
    def setUp(self):
        if not testing_base.exists():
            testing_base.mkdir()

    def tearDown(self):
        RepoPath(testing_base).rmtree(onerror=onerror)

    def test_init(self):
        rp = testing_base / 'test-repo'
        repo = rp.init()
        assert repo, f'hrm {rp!r} {repo}'
        return rp