Ejemplo n.º 1
0
 def test_ssh_urls(self):
     self.assertEqual(
         normalize_git_url('ssh://[email protected]/path/to/repo'),
         'ssh://[email protected]/path/to/repo')
     self.assertEqual(
         normalize_git_url('git+ssh://example.com/path/to/repo'),
         'ssh://example.com/path/to/repo')
Ejemplo n.º 2
0
 def test_http_urls(self):
     self.assertEqual(
         normalize_git_url('http://[email protected]/path/to/repo'),
         'http://[email protected]/path/to/repo')
     self.assertEqual(
         normalize_git_url('git+http://example.com/path/to/repo'),
         'http://example.com/path/to/repo')
Ejemplo n.º 3
0
 def test_file_urls(self):
     self.assertEqual(normalize_git_url('git+file:///path/to/repo'),
                      'file:///path/to/repo')
     self.assertEqual(normalize_git_url('git+/path/to/repo'),
                      '/path/to/repo')
     self.assertEqual(normalize_git_url('git+path/to/repo'), 'path/to/repo')
     self.assertEqual(normalize_git_url('git+/path/to/repo', prefix=True),
                      'git+/path/to/repo')
Ejemplo n.º 4
0
 def test_github(self):
     self.assertEqual(normalize_git_url('[email protected]:example/repo.git'),
                      '[email protected]:example/repo')
     self.assertEqual(
         normalize_git_url(
             'git+https://github.com/snide/sphinx_rtd_theme.git'),
         'https://github.com/snide/sphinx_rtd_theme',
     )
Ejemplo n.º 5
0
 def test_github_transforms(self):
     self.assertEqual(
         normalize_git_url('[email protected]:org/repo.git', prefer='https'),
         'https://github.com/org/repo',
     )
     self.assertEqual(
         normalize_git_url('https://github.com/org/repo.git', prefer='scp'),
         '[email protected]:org/repo',
     )
Ejemplo n.º 6
0
 def test_scp_urls(self):
     self.assertEqual(normalize_git_url('[email protected]:path/to/repo'),
                      '[email protected]:path/to/repo')
     self.assertEqual(normalize_git_url('[email protected]:/path/to/repo'),
                      '[email protected]:/path/to/repo')
     self.assertEqual(normalize_git_url('example.com:path/to/repo'),
                      'example.com:path/to/repo')
     self.assertEqual(
         normalize_git_url('[email protected]:path/to/repo'),
         '[email protected]:path/to/repo')
Ejemplo n.º 7
0
 def test_ext(self):
     self.assertEqual(
         normalize_git_url('[email protected]:/path/to/repo.git'),
         '[email protected]:/path/to/repo')
     self.assertEqual(
         normalize_git_url('[email protected]:/path/to/repo.git',
                           keep_ext=True),
         '[email protected]:/path/to/repo.git')
     self.assertEqual(
         normalize_git_url('[email protected]:/path/to/repo', keep_ext=True),
         '[email protected]:/path/to/repo')
Ejemplo n.º 8
0
def iter_availible_requirements(home):
    repo = home.get_repo()
    req_set = repo.requirement_set()
    pkg_set = PackageSet(home=home)
    for req in req_set.iter_packages():
        pkg = pkg_set.resolve(req, check_existing=False)
        if pkg.type != 'git':
            return
        yield req, normalize_git_url(req.url, prefix=False)
Ejemplo n.º 9
0
    def init(self, pkg):

        pkg.url = normalize_git_url(pkg.url, prefix=True) or pkg.url
        pkg._assert_paths(package=True)
        self.repo = GitRepo(work_tree=pkg.package_path,
                            remote_url=re.sub(r'^git[:\+]', '', pkg.url))

        # Resolve branches by fetching.
        if pkg.version and not re.match(r'^[0-9a-f]{8,}$', pkg.version):
            self.repo.clone_if_not_exists()
            rev = self.repo.fetch(ref=pkg.version)
            pkg.version = rev[:8]
Ejemplo n.º 10
0
def init(args, do_clone=False, do_install=False, do_add=False, is_find=False):

    do_init = not (do_clone or do_install or do_add)

    name = args.name
    home = args.assert_home()

    con = home.db.connect()

    path = os.path.abspath(args.path or os.path.join(home.dev_root, name))

    dev_repo = GitRepo(path)

    if do_init:
        log.info(style_note('Initing %s' % dev_repo.work_tree))
        makedirs(dev_repo.work_tree)
        dev_repo.git('init')

    elif do_clone:
        log.info(style_note('Cloning %s' % args.url))
        makedirs(dev_repo.work_tree)
        dev_repo.clone_if_not_exists(args.url)

    elif do_install:
        # Find an existing tool.
        # TODO: put more of this into EnvironmentRepo or Manifest
        repo = home.get_repo(args.repo)
        manifest_path = os.path.join(repo.work_tree, 'manifest.txt')
        manifest = Manifest(manifest_path, home=home)
        for req in manifest.iter_packages():
            if req.name.lower() == name.lower():
                # Make sure it is a Git package.
                url = normalize_git_url(req.url, prefix=False)
                if url:
                    break
        else:
            log.error('Could not find git-based "%s" in "%s" repo.' %
                      (name, repo.name))
            return 2
        log.info(style_note('Found %s in %s' % (name, repo.name), str(req)))
        makedirs(dev_repo.work_tree)
        dev_repo.clone_if_not_exists(url, shallow=False)

    elif do_add:
        log.info(style_note('Adding %s from %s' % (name, path)))

    if not os.path.exists(path):
        log.error('%s does not exist' % path)
        return 1

    package = Package([path], home=home, dev=True)
    try:
        package.pipeline.run_to('develop')
    except Exception as e:
        print_cli_exc(e)
        return 1

    log.info(style_note('Linking dev package', name, path))

    dev_pkg = DevPackage(
        {
            'name': name,
            'path': path,
            'environ': package.environ
        }, home=home)
    dev_pkg.save_tag()
Ejemplo n.º 11
0
Archivo: add.py Proyecto: westernx/vee
def add(args):

    home = args.assert_home()
    env_repo = home.get_env_repo(args.repo)
    req_set = env_repo.load_requirements()
    pkg_set = PackageSet(home=home)

    baked_any = None

    if args.update:
        baked_any = False
        for req in req_set.iter_packages():
            pkg = pkg_set.resolve(req, check_existing=False)
            if pkg.fetch_type != 'git':
                continue
            print style_note('Fetching', str(req))
            pkg.repo.fetch('origin',
                           'master')  # TODO: track these another way?
            if pkg.repo.check_ff_safety('origin/master'):
                pkg.repo.checkout('origin/master')
                head = pkg.repo.head[:8]
                if head != req.revision:
                    req.revision = pkg.repo.head[:8]
                    print style_note('Updated', str(req))
                    baked_any = True

    if args.bake_installed:
        baked_any = False

        for req in req_set.iter_packages():

            pkg = pkg_set.resolve(req)
            if pkg.fetch_type != 'git':
                continue
            repo = pkg.pipeline.steps['fetch'].repo

            if req.name and req.name == guess_name(req.url):
                req.name = None
                baked_any = True
                print style_note('Unset redundant name', req.name)

            if pkg.installed and req.revision != repo.head[:8]:
                req.revision = repo.head[:8]
                baked_any = True
                print style_note('Pinned', req.name, req.revision)

    if args.checksum:
        baked_any = False

        for req in req_set.iter_packages():
            pkg = pkg_set.resolve(req)
            if pkg.checksum:
                continue
            if not pkg.package_path or not os.path.isfile(pkg.package_path):
                continue
            req.checksum = checksum_file(pkg.package_path)
            print style_note('Checksummed', pkg.name, req.checksum)
            baked_any = True

    if baked_any is not None:
        if baked_any:
            env_repo.dump_requirements(req_set)
        else:
            print style_note('No changes.')
        return

    row = home.get_development_record(os.path.abspath(args.package))

    if not row:
        raise ValueError('No development package %r' % args.package)

    dev_repo = GitRepo(row['path'])

    # Get the normalized origin.
    dev_remote_urls = set()
    for url in dev_repo.remotes().itervalues():
        url = normalize_git_url(url, prefer='scp') or url
        log.debug('adding dev remote url: %s' % url)
        dev_remote_urls.add(url)
    if not dev_remote_urls:
        print style_error('No git remotes for %s' % row['path'])
        return 1

    for req in req_set.iter_packages(eval_control=False):

        # We only deal with git packages.
        pkg = pkg_set.resolve(req, check_existing=False)
        if pkg.fetch_type != 'git':
            continue

        req_url = normalize_git_url(req.url, prefer='scp')
        log.debug('does match package url?: %s' % req_url)
        if req_url in dev_remote_urls:
            if req.revision == dev_repo.head[:8]:
                print style_note('No change to', str(req))
            else:
                req.revision = dev_repo.head[:8]
                print style_note('Updated', str(req))
            break

    else:
        if not args.init:
            print '{error}: No required package {name}; would match one of:'.format(
                error=style('Error', 'red'),
                name=style(args.package, bold=True))
            for url in sorted(dev_remote_urls):
                print '    {}'.format(url)
            print 'Use {} to setup: git+{} --revision {}'.format(
                style('vee add --init %s' % args.package, 'green'),
                dev_repo.remotes()['origin'], dev_repo.head[:8])
            return 1

        req = Package(
            url=normalize_git_url(dev_repo.remotes()['origin'], prefix=True),
            revision=dev_repo.head[:8],
            home=home,
        )
        req_set.append(('', req, ''))

    env_repo.dump_requirements(req_set)
Ejemplo n.º 12
0
def init(args, do_clone=False, do_install=False, do_add=False, is_find=False):

    do_init = not (do_clone or do_install or do_add)

    name = args.name
    home = args.assert_home()

    con = home.db.connect()

    # Make sure there are no other packages already, and clear out old ones
    # which no longer exist.
    for row in con.execute('SELECT * FROM development_packages WHERE name = ?',
                           [name]):
        if not args.force and os.path.exists(os.path.join(row['path'],
                                                          '.git')):
            if is_find:
                print style_note('"%s" already exists:' % name, row['path'])
                return
            else:
                print style_error('"%s" already exists:' % name, row['path'])
                return 1
        else:
            con.execute('DELETE FROM development_packages WHERE id = ?',
                        [row['id']])

    path = os.path.abspath(args.path or os.path.join(home.dev_root, name))

    dev_repo = GitRepo(path)

    if do_init:
        print style_note('Initing %s' % dev_repo.work_tree)
        makedirs(dev_repo.work_tree)
        dev_repo.git('init')

    elif do_clone:
        print style_note('Cloning %s' % args.url)
        makedirs(dev_repo.work_tree)
        dev_repo.clone_if_not_exists(args.url)

    elif do_install:
        # Find an existing tool.
        # TODO: put more of this into EnvironmentRepo or Requirements
        env_repo = home.get_env_repo(args.repo)
        req_path = os.path.join(env_repo.work_tree, 'requirements.txt')
        reqs = Requirements(req_path, home=home)
        for req in reqs.iter_packages():
            if req.name.lower() == name.lower():
                # Make sure it is a Git package.
                url = normalize_git_url(req.url, prefix=False)
                if url:
                    break
        else:
            print style_error('Could not find git-based "%s" in "%s" repo.' %
                              (name, env_repo.name))
            return 2
        print style_note('Found %s in %s' % (name, env_repo.name), str(req))
        makedirs(dev_repo.work_tree)
        dev_repo.clone_if_not_exists(url, shallow=False)

    elif do_add:
        print style_note('Adding %s from %s' % (name, path))

    if not os.path.exists(path):
        log.error('%s does not exist' % path)
        return 1

    package = Package([path], home=home, dev=True)
    try:
        package.pipeline.run_to('develop')
    except Exception as e:
        print_cli_exc(e)
        return 1

    print style_note('Linking dev package', name, path)
    con.execute(
        'INSERT INTO development_packages (name, path, environ) VALUES (?, ?, ?)',
        [name, path, json.dumps(package.environ)])

    dev_pkg = DevPackage(
        {
            'name': name,
            'path': path,
            'environ': package.environ
        }, home=home)
    dev_pkg.save_tag()
Ejemplo n.º 13
0
Archivo: git.py Proyecto: westernx/vee
 def init(self):
     pkg = self.package
     pkg.url = normalize_git_url(pkg.url, prefix=True) or pkg.url
     pkg._assert_paths(package=True)
     self.repo = GitRepo(work_tree=pkg.package_path,
                         remote_url=re.sub(r'^git[:\+]', '', pkg.url))