def install_editable(self, install_options, global_options=()):
        logger.notify('Running setup.py develop for %s' % self.name)
        logger.indent += 2
        try:
            # FIXME: should we do --install-headers here too?
            cwd = self.source_dir
            if self.editable_options and \
                    'subdirectory' in self.editable_options:
                cwd = os.path.join(cwd, self.editable_options['subdirectory'])
            call_subprocess(
                [
                    sys.executable,
                    '-c',
                    "import setuptools, tokenize; __file__=%r; exec(compile("
                    "getattr(tokenize, 'open', open)(__file__).read().replace"
                    "('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py
                ]
                + list(global_options)
                + ['develop', '--no-deps']
                + list(install_options),

                cwd=cwd, filter_stdout=self._filter_install,
                show_stdout=False)
        finally:
            logger.indent -= 2
        self.install_succeeded = True
    def install_editable(self, install_options, global_options=()):
        logger.notify('Running setup.py develop for %s' % self.name)
        logger.indent += 2
        try:
            # FIXME: should we do --install-headers here too?
            cwd = self.source_dir
            if self.editable_options and \
                    'subdirectory' in self.editable_options:
                cwd = os.path.join(cwd, self.editable_options['subdirectory'])
            call_subprocess(
                [
                    sys.executable,
                    '-c',
                    "import setuptools, tokenize; __file__=%r; exec(compile("
                    "getattr(tokenize, 'open', open)(__file__).read().replace"
                    "('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py
                ]
                + list(global_options)
                + ['develop', '--no-deps']
                + list(install_options),

                cwd=cwd, filter_stdout=self._filter_install,
                show_stdout=False)
        finally:
            logger.indent -= 2
        self.install_succeeded = True
示例#3
0
文件: git.py 项目: elisamerida/TFG
 def update_submodules(self, location):
     if not os.path.exists(os.path.join(location, '.gitmodules')):
         return
     call_subprocess(
         [self.cmd, 'submodule', 'update', '--init', '--recursive', '-q'],
         cwd=location,
     )
示例#4
0
    def switch(self, dest, url, rev_options):
        call_subprocess(
            [self.cmd, 'config', 'remote.origin.url', url], cwd=dest)
        call_subprocess(
            [self.cmd, 'checkout', '-q'] + rev_options, cwd=dest)

        self.update_submodules(dest)
示例#5
0
 def update_submodules(self, location):
     if not os.path.exists(os.path.join(location, '.gitmodules')):
         return
     call_subprocess(
         [self.cmd, 'submodule', 'update', '--init', '--recursive', '-q'],
         cwd=location,
     )
示例#6
0
 def copy_to_build_dir(self, req_to_install):
     target_dir = req_to_install.editable and self.src_dir or self.build_dir
     logger.info("Copying %s to %s" % (req_to_install.name, target_dir))
     dest = os.path.join(target_dir, req_to_install.name)
     shutil.copytree(req_to_install.source_dir, dest)
     call_subprocess(["python", "%s/setup.py" % dest, "clean"], cwd=dest,
                     command_desc='python setup.py clean')
示例#7
0
 def _get_all_branch_names(self, location):
     remote_branches = call_subprocess([self.cmd, 'branch', '-r'],
                                       show_stdout=False,
                                       cwd=location)
     local_branches = call_subprocess([self.cmd, 'branch', '-l'],
                                      show_stdout=False,
                                      cwd=location)
     return remote_branches + local_branches
    def run_egg_info(self):
        assert self.source_dir
        if self.name:
            logger.notify(
                'Running setup.py (path:%s) egg_info for package %s' %
                (self.setup_py, self.name)
            )
        else:
            logger.notify(
                'Running setup.py (path:%s) egg_info for package from %s' %
                (self.setup_py, self.url)
            )
        logger.indent += 2
        try:

            # if it's distribute>=0.7, it won't contain an importable
            # setuptools, and having an egg-info dir blocks the ability of
            # setup.py to find setuptools plugins, so delete the egg-info dir
            # if no setuptools. it will get recreated by the run of egg_info
            # NOTE: this self.name check only works when installing from a
            #       specifier (not archive path/urls)
            # TODO: take this out later
            if (self.name == 'distribute'
                    and not os.path.isdir(
                        os.path.join(self.source_dir, 'setuptools'))):
                rmtree(os.path.join(self.source_dir, 'distribute.egg-info'))

            script = self._run_setup_py
            script = script.replace('__SETUP_PY__', repr(self.setup_py))
            script = script.replace('__PKG_NAME__', repr(self.name))
            egg_info_cmd = [sys.executable, '-c', script, 'egg_info']
            # We can't put the .egg-info files at the root, because then the
            # source code will be mistaken for an installed egg, causing
            # problems
            if self.editable:
                egg_base_option = []
            else:
                egg_info_dir = os.path.join(self.source_dir, 'pip-egg-info')
                if not os.path.exists(egg_info_dir):
                    os.makedirs(egg_info_dir)
                egg_base_option = ['--egg-base', 'pip-egg-info']
            cwd = self.source_dir
            if self.editable_options and \
                    'subdirectory' in self.editable_options:
                cwd = os.path.join(cwd, self.editable_options['subdirectory'])
            call_subprocess(
                egg_info_cmd + egg_base_option,
                cwd=cwd,
                filter_stdout=self._filter_install,
                show_stdout=False,
                command_level=logger.VERBOSE_DEBUG,
                command_desc='python setup.py egg_info')
        finally:
            logger.indent -= 2
        if not self.req:
            self.req = pkg_resources.Requirement.parse(
                "%(Name)s==%(Version)s" % self.pkg_info())
            self.correct_build_location()
    def run_egg_info(self, force_root_egg_info=False):
        assert self.source_dir
        if self.name:
            logger.notify(
                'Running setup.py (path:%s) egg_info for package %s' %
                (self.setup_py, self.name)
            )
        else:
            logger.notify(
                'Running setup.py (path:%s) egg_info for package from %s' %
                (self.setup_py, self.url)
            )
        logger.indent += 2
        try:

            # if it's distribute>=0.7, it won't contain an importable
            # setuptools, and having an egg-info dir blocks the ability of
            # setup.py to find setuptools plugins, so delete the egg-info dir
            # if no setuptools. it will get recreated by the run of egg_info
            # NOTE: this self.name check only works when installing from a
            #       specifier (not archive path/urls)
            # TODO: take this out later
            if (self.name == 'distribute'
                    and not os.path.isdir(
                        os.path.join(self.source_dir, 'setuptools'))):
                rmtree(os.path.join(self.source_dir, 'distribute.egg-info'))

            script = self._run_setup_py
            script = script.replace('__SETUP_PY__', repr(self.setup_py))
            script = script.replace('__PKG_NAME__', repr(self.name))
            egg_info_cmd = [sys.executable, '-c', script, 'egg_info']
            # We can't put the .egg-info files at the root, because then the
            # source code will be mistaken for an installed egg, causing
            # problems
            if self.editable or force_root_egg_info:
                egg_base_option = []
            else:
                egg_info_dir = os.path.join(self.source_dir, 'pip-egg-info')
                if not os.path.exists(egg_info_dir):
                    os.makedirs(egg_info_dir)
                egg_base_option = ['--egg-base', 'pip-egg-info']
            cwd = self.source_dir
            if self.editable_options and \
                    'subdirectory' in self.editable_options:
                cwd = os.path.join(cwd, self.editable_options['subdirectory'])
            call_subprocess(
                egg_info_cmd + egg_base_option,
                cwd=cwd,
                filter_stdout=self._filter_install,
                show_stdout=False,
                command_level=logger.VERBOSE_DEBUG,
                command_desc='python setup.py egg_info')
        finally:
            logger.indent -= 2
        if not self.req:
            self.req = pkg_resources.Requirement.parse(
                "%(Name)s==%(Version)s" % self.pkg_info())
            self.correct_build_location()
示例#10
0
 def update(self, dest, rev_options):
     # First fetch changes from the default remote
     call_subprocess([self.cmd, 'fetch', '-q'], cwd=dest)
     # Then reset to wanted revision (maby even origin/master)
     if rev_options:
         rev_options = self.check_rev_options(rev_options[0], dest, rev_options)
     call_subprocess([self.cmd, 'reset', '--hard', '-q'] + rev_options, cwd=dest)
     #: update submodules
     self.update_submodules(dest)
示例#11
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     rev_options = get_rev_options(url, rev)
     if rev:
         rev_display = " (to revision %s)" % rev
     else:
         rev_display = ""
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify("Checking out %s%s to %s" % (url, rev_display, display_path(dest)))
         call_subprocess([self.cmd, "checkout", "-q"] + rev_options + [url, dest])
示例#12
0
 def export(self, location):
     """Export the Hg repository at the url to the destination location"""
     temp_dir = tempfile.mkdtemp('-export', 'pip-')
     self.unpack(temp_dir)
     try:
         call_subprocess(
             [self.cmd, 'archive', location],
             filter_stdout=self._filter, show_stdout=False, cwd=temp_dir)
     finally:
         rmtree(temp_dir)
示例#13
0
 def export(self, location):
     """Export the Hg repository at the url to the destination location"""
     temp_dir = tempfile.mkdtemp('-export', 'pip-')
     self.unpack(temp_dir)
     try:
         call_subprocess(
             [self.cmd, 'archive', location],
             filter_stdout=self._filter, show_stdout=False, cwd=temp_dir)
     finally:
         rmtree(temp_dir)
示例#14
0
    def _clean_one(self, req):
        base_args = self._base_setup_args(req)

        logger.info('Running setup.py clean for %s', req.name)
        clean_args = base_args + ['clean', '--all']
        try:
            call_subprocess(clean_args, cwd=req.source_dir, show_stdout=False)
            return True
        except:
            logger.error('Failed cleaning build dir for %s', req.name)
            return False
示例#15
0
 def export(self, location):
     """Export the Git repository at the url to the destination location"""
     temp_dir = tempfile.mkdtemp('-export', 'pip-')
     self.unpack(temp_dir)
     try:
         if not location.endswith('/'):
             location = location + '/'
         call_subprocess(
             [self.cmd, 'checkout-index', '-a', '-f', '--prefix', location],
             filter_stdout=self._filter, show_stdout=False, cwd=temp_dir)
     finally:
         rmtree(temp_dir)
示例#16
0
 def export(self, location):
     """Export the Bazaar repository at the url to the destination location"""
     temp_dir = tempfile.mkdtemp('-export', 'pip-')
     self.unpack(temp_dir)
     if os.path.exists(location):
         # Remove the location to make sure Bazaar can export it correctly
         rmtree(location)
     try:
         call_subprocess([self.cmd, 'export', location], cwd=temp_dir,
                         filter_stdout=self._filter, show_stdout=False)
     finally:
         rmtree(temp_dir)
示例#17
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     rev_options = get_rev_options(url, rev)
     if rev:
         rev_display = ' (to revision %s)' % rev
     else:
         rev_display = ''
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify('Checking out %s%s to %s' %
                       (url, rev_display, display_path(dest)))
         call_subprocess([self.cmd, 'checkout', '-q'] + rev_options +
                         [url, dest])
示例#18
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     if rev:
         rev_options = [rev]
         rev_display = " (to revision %s)" % rev
     else:
         rev_options = []
         rev_display = ""
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify("Cloning hg %s%s to %s" % (url, rev_display, display_path(dest)))
         call_subprocess([self.cmd, "clone", "--noupdate", "-q", url, dest])
         call_subprocess([self.cmd, "update", "-q"] + rev_options, cwd=dest)
示例#19
0
 def export(self, location):
     """Export the Bazaar repository at the url to the destination location"""
     temp_dir = tempfile.mkdtemp('-export', 'pip-')
     self.unpack(temp_dir)
     if os.path.exists(location):
         # Remove the location to make sure Bazaar can export it correctly
         rmtree(location)
     try:
         call_subprocess([self.cmd, 'export', location], cwd=temp_dir,
                         filter_stdout=self._filter, show_stdout=False)
     finally:
         rmtree(temp_dir)
示例#20
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     rev_options = get_rev_options(url, rev)
     if rev:
         rev_display = ' (to revision %s)' % rev
     else:
         rev_display = ''
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify('Checking out %s%s to %s'
                       % (url, rev_display, display_path(dest)))
         call_subprocess(
             [self.cmd, 'checkout', '-q'] + rev_options + [url, dest])
示例#21
0
 def upload_to_repository(self, options):
     current = os.path.abspath(os.curdir)
     opts = ['sdist', 'register', '-r', options.req_repository,
             'upload', '-r', options.req_repository]
     setup = ' '.join(['setup.py'] + opts)
     logger.notify('Running %s for packages in %s' % (setup, options.req_cache_dir))
     pkgs = self._individual_packages(options)
     logger.indent += 2
     for n in pkgs:
         os.chdir(n)
         call_subprocess([sys.executable, 'setup.py'] + opts)
         os.chdir(current)
     logger.indent -= 2
示例#22
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     if rev:
         rev_options = [rev]
         rev_display = ' (to revision %s)' % rev
     else:
         rev_options = []
         rev_display = ''
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify('Cloning hg %s%s to %s'
                       % (url, rev_display, display_path(dest)))
         call_subprocess([self.cmd, 'clone', '--noupdate', '-q', url, dest])
         call_subprocess([self.cmd, 'update', '-q'] + rev_options, cwd=dest)
示例#23
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     if rev:
         rev_options = [rev]
         rev_display = ' (to revision %s)' % rev
     else:
         rev_options = []
         rev_display = ''
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify('Cloning hg %s%s to %s'
                       % (url, rev_display, display_path(dest)))
         call_subprocess([self.cmd, 'clone', '--noupdate', '-q', url, dest])
         call_subprocess([self.cmd, 'update', '-q'] + rev_options, cwd=dest)
示例#24
0
 def switch(self, dest, url, rev_options):
     repo_config = os.path.join(dest, self.dirname, "hgrc")
     config = ConfigParser.SafeConfigParser()
     try:
         config.read(repo_config)
         config.set("paths", "default", url)
         config_file = open(repo_config, "w")
         config.write(config_file)
         config_file.close()
     except (OSError, ConfigParser.NoSectionError):
         e = sys.exc_info()[1]
         logger.warn("Could not switch Mercurial repository to %s: %s" % (url, e))
     else:
         call_subprocess([self.cmd, "update", "-q"] + rev_options, cwd=dest)
示例#25
0
 def switch(self, dest, url, rev_options):
     repo_config = os.path.join(dest, self.dirname, 'hgrc')
     config = ConfigParser.SafeConfigParser()
     try:
         config.read(repo_config)
         config.set('paths', 'default', url)
         config_file = open(repo_config, 'w')
         config.write(config_file)
         config_file.close()
     except (OSError, ConfigParser.NoSectionError) as exc:
         logger.warn('Could not switch Mercurial repository to %s: %s' %
                     (url, exc))
     else:
         call_subprocess([self.cmd, 'update', '-q'] + rev_options, cwd=dest)
示例#26
0
 def switch(self, dest, url, rev_options):
     repo_config = os.path.join(dest, self.dirname, 'hgrc')
     config = ConfigParser.SafeConfigParser()
     try:
         config.read(repo_config)
         config.set('paths', 'default', url)
         config_file = open(repo_config, 'w')
         config.write(config_file)
         config_file.close()
     except (OSError, ConfigParser.NoSectionError) as exc:
         logger.warn(
             'Could not switch Mercurial repository to %s: %s'
             % (url, exc))
     else:
         call_subprocess([self.cmd, 'update', '-q'] + rev_options, cwd=dest)
示例#27
0
 def get_info(self, location):
     """Returns (url, revision), where both are strings"""
     assert not location.rstrip('/').endswith(self.dirname), \
         'Bad directory: %s' % location
     output = call_subprocess(
         [self.cmd, 'info', location],
         show_stdout=False,
         extra_environ={'LANG': 'C'},
     )
     match = _svn_url_re.search(output)
     if not match:
         logger.warn(
             'Cannot determine URL of svn checkout %s' %
             display_path(location)
         )
         return None, None
     url = match.group(1).strip()
     match = _svn_revision_re.search(output)
     if not match:
         logger.warn(
             'Cannot determine revision of svn checkout %s' %
             display_path(location)
         )
         logger.info('Output that cannot be parsed: \n%s' % output)
         return url, None
     return url, match.group(1)
示例#28
0
 def export(self, location):
     """Export the svn repository at the url to the destination location"""
     url, rev = self.get_url_rev()
     rev_options = get_rev_options(url, rev)
     logger.notify('Exporting svn repository %s to %s' % (url, location))
     logger.indent += 2
     try:
         if os.path.exists(location):
             # Subversion doesn't like to check out over an existing
             # directory --force fixes this, but was only added in svn 1.5
             rmtree(location)
         call_subprocess(
             [self.cmd, 'export'] + rev_options + [url, location],
             filter_stdout=self._filter, show_stdout=False)
     finally:
         logger.indent -= 2
示例#29
0
    def _get_svn_url_rev(self, location):
        f = open(os.path.join(location, self.dirname, 'entries'))
        data = f.read()
        f.close()
        if data.startswith('8') or data.startswith('9') or data.startswith(
                '10'):
            data = list(map(str.splitlines, data.split('\n\x0c\n')))
            del data[0][0]  # get rid of the '8'
            url = data[0][3]
            revs = [int(d[9]) for d in data if len(d) > 9 and d[9]] + [0]
        elif data.startswith('<?xml'):
            match = _svn_xml_url_re.search(data)
            if not match:
                raise ValueError('Badly formatted data: %r' % data)
            url = match.group(1)  # get repository URL
            revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
        else:
            try:
                # subversion >= 1.7
                xml = call_subprocess([self.cmd, 'info', '--xml', location],
                                      show_stdout=False)
                url = _svn_info_xml_url_re.search(xml).group(1)
                revs = [
                    int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)
                ]
            except InstallationError:
                url, revs = None, []

        if revs:
            rev = max(revs)
        else:
            rev = 0

        return url, rev
示例#30
0
class WheelBuilder(object):
    """Build wheels from a RequirementSet."""

    def __init__(self, requirement_set, finder, wheel_dir, build_options=[], global_options=[]):
        self.requirement_set = requirement_set
        self.finder = finder
        self.wheel_dir = normalize_path(wheel_dir)
        self.build_options = build_options
        self.global_options = global_options

    def _build_one(self, req):
        """Build one wheel."""

        base_args = [
            sys.executable, '-c',
            "import setuptools;__file__=%r;"\
            "exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" % req.setup_py] + \
            list(self.global_options)

        logger.notify('Running setup.py bdist_wheel for %s' % req.name)
        logger.notify('Destination directory: %s' % self.wheel_dir)
        wheel_args = base_args + ['bdist_wheel', '-d', self.wheel_dir] + self.build_options
        try:
            call_subprocess(wheel_args, cwd=req.source_dir, show_stdout=False)
            return True
        except:
            logger.error('Failed building wheel for %s' % req.name)
            return False
示例#31
0
    def _get_svn_url_rev(self, location):
        f = open(os.path.join(location, self.dirname, 'entries'))
        data = f.read()
        f.close()
        if data.startswith('8') or data.startswith('9') or data.startswith('10'):
            data = list(map(str.splitlines, data.split('\n\x0c\n')))
            del data[0][0]  # get rid of the '8'
            url = data[0][3]
            revs = [int(d[9]) for d in data if len(d) > 9 and d[9]] + [0]
        elif data.startswith('<?xml'):
            match = _svn_xml_url_re.search(data)
            if not match:
                raise ValueError('Badly formatted data: %r' % data)
            url = match.group(1)    # get repository URL
            revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
        else:
            try:
                # subversion >= 1.7
                xml = call_subprocess([self.cmd, 'info', '--xml', location], show_stdout=False)
                url = _svn_info_xml_url_re.search(xml).group(1)
                revs = [int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)]
            except InstallationError:
                url, revs = None, []

        if revs:
            rev = max(revs)
        else:
            rev = 0

        return url, rev
示例#32
0
 def export(self, location):
     """Export the svn repository at the url to the destination location"""
     url, rev = self.get_url_rev()
     rev_options = get_rev_options(url, rev)
     logger.notify('Exporting svn repository %s to %s' % (url, location))
     logger.indent += 2
     try:
         if os.path.exists(location):
             # Subversion doesn't like to check out over an existing directory
             # --force fixes this, but was only added in svn 1.5
             rmtree(location)
         call_subprocess(
             [self.cmd, 'export'] + rev_options + [url, location],
             filter_stdout=self._filter, show_stdout=False)
     finally:
         logger.indent -= 2
示例#33
0
 def get_url(self, location):
     url = call_subprocess(
         [self.cmd, 'showconfig', 'paths.default'],
         show_stdout=False, cwd=location).strip()
     if self._is_local_repository(url):
         url = path_to_url(url)
     return url.strip()
示例#34
0
 def get_url(self, location):
     url = call_subprocess(
         [self.cmd, 'showconfig', 'paths.default'],
         show_stdout=False, cwd=location).strip()
     if self._is_local_repository(url):
         url = path_to_url2(url)
     return url.strip()
示例#35
0
    def __build_one(self, req, tempd, python_tag=None):
        base_args = self._base_setup_args(req)

        spin_message = 'Running setup.py bdist_wheel for %s' % (req.name,)
        with open_spinner(spin_message) as spinner:
            logger.debug('Destination directory: %s', tempd)
            wheel_args = base_args + ['bdist_wheel', '-d', tempd] \
                + self.build_options

            if python_tag is not None:
                wheel_args += ["--python-tag", python_tag]

            try:
                call_subprocess(wheel_args, cwd=req.source_dir,
                                show_stdout=False, spinner=spinner)
                return True
            except:
    def _build_one(self, req):
        """Build one wheel."""

        base_args = [
            sys.executable, '-c',
            "import setuptools;__file__=%r;"\
            "exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" % req.setup_py] + \
            list(self.global_options)

        logger.notify('Running setup.py bdist_wheel for %s' % req.name)
        logger.notify('Destination directory: %s' % self.wheel_dir)
        wheel_args = base_args + ['bdist_wheel', '-d', self.wheel_dir] + self.build_options
        try:
            call_subprocess(wheel_args, cwd=req.source_dir, show_stdout=False)
            return True
        except:
            logger.error('Failed building wheel for %s' % req.name)
            return False
示例#37
0
    def _build_one(self, req):
        """Build one wheel."""

        base_args = [
                        sys.executable, '-c',
                        "import setuptools;__file__=%r;" \
                        "exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" % req.setup_py] + \
                    list(self.global_options)

        logger.notify('Running setup.py bdist_wheel for %s' % req.name)
        logger.notify('Destination directory: %s' % self.wheel_dir)
        wheel_args = base_args + ['bdist_wheel', '-d', self.wheel_dir] + self.build_options
        try:
            call_subprocess(wheel_args, cwd=req.source_dir, show_stdout=False)
            return True
        except:
            logger.error('Failed building wheel for %s' % req.name)
            return False
示例#38
0
 def obtain(self, dest):
     url, rev = self.get_url_rev()
     if rev:
         rev_options = [rev]
         rev_display = ' (to %s)' % rev
     else:
         rev_options = ['origin/master']
         rev_display = ''
     if self.check_destination(dest, url, rev_options, rev_display):
         logger.notify('Cloning %s%s to %s' % (url, rev_display, display_path(dest)))
         call_subprocess([self.cmd, 'clone', '-q', url, dest])
         #: repo may contain submodules
         self.update_submodules(dest)
         if rev:
             rev_options = self.check_rev_options(rev, dest, rev_options)
             # Only do a checkout if rev_options differs from HEAD
             if not self.get_revision(dest).startswith(rev_options[0]):
                 call_subprocess([self.cmd, 'checkout', '-q'] + rev_options, cwd=dest)
示例#39
0
 def get_tag_revs(self, svn_tag_url):
     stdout = call_subprocess([self.cmd, "ls", "-v", svn_tag_url], show_stdout=False)
     results = []
     for line in stdout.splitlines():
         parts = line.split()
         rev = int(parts[0])
         tag = parts[-1].strip("/")
         results.append((tag, rev))
     return results
示例#40
0
 def get_tag_revs(self, svn_tag_url):
     stdout = call_subprocess([self.cmd, 'ls', '-v', svn_tag_url],
                              show_stdout=False)
     results = []
     for line in stdout.splitlines():
         parts = line.split()
         rev = int(parts[0])
         tag = parts[-1].strip('/')
         results.append((tag, rev))
     return results
示例#41
0
 def get_tag_revs(self, location):
     tags = call_subprocess([self.cmd, "tags"], show_stdout=False, cwd=location)
     tag_revs = []
     for line in tags.splitlines():
         tags_match = re.search(r"([\w\d\.-]+)\s*([\d]+):.*$", line)
         if tags_match:
             tag = tags_match.group(1)
             rev = tags_match.group(2)
             if "tip" != tag:
                 tag_revs.append((rev.strip(), tag.strip()))
     return dict(tag_revs)
示例#42
0
 def get_branch_revs(self, location):
     branches = call_subprocess([self.cmd, "branches"], show_stdout=False, cwd=location)
     branch_revs = []
     for line in branches.splitlines():
         branches_match = re.search(r"([\w\d\.-]+)\s*([\d]+):.*$", line)
         if branches_match:
             branch = branches_match.group(1)
             rev = branches_match.group(2)
             if "default" != branch:
                 branch_revs.append((rev.strip(), branch.strip()))
     return dict(branch_revs)
示例#43
0
 def get_tag_revs(self, location):
     tags = call_subprocess(
         [self.cmd, 'tags'], show_stdout=False, cwd=location)
     tag_revs = []
     for line in tags.splitlines():
         tags_match = re.search(r'([.\w-]+)\s*(.*)$', line)
         if tags_match:
             tag = tags_match.group(1)
             rev = tags_match.group(2)
             tag_revs.append((rev.strip(), tag.strip()))
     return dict(tag_revs)
示例#44
0
 def get_tag_revs(self, location):
     tags = call_subprocess(
         [self.cmd, 'tags'], show_stdout=False, cwd=location)
     tag_revs = []
     for line in tags.splitlines():
         tags_match = re.search(r'([.\w-]+)\s*(.*)$', line)
         if tags_match:
             tag = tags_match.group(1)
             rev = tags_match.group(2)
             tag_revs.append((rev.strip(), tag.strip()))
     return dict(tag_revs)
示例#45
0
 def is_valid_commit_hash(self, hash_candidate):
     if re.match(self.commit_hash_re, hash_candidate) is None:
         return False
     try:
         ret = call_subprocess(['git', 'log', '-n', '1', hash_candidate, '--pretty=oneline'],
             show_stdout=False, cwd=self.checkout_dir)
         return ret.split(" ")[0] == hash_candidate
     except InstallationError:
         # call_subprocess returns raises an InstallationError when the return value of a command is not 0.
         # In this case it just means the given commit is not in the git repo.
         return False
示例#46
0
 def get_branch_revs(self, location):
     branches = call_subprocess(
         [self.cmd, 'branches'], show_stdout=False, cwd=location)
     branch_revs = []
     for line in branches.splitlines():
         branches_match = re.search(r'([\w\d\.-]+)\s*([\d]+):.*$', line)
         if branches_match:
             branch = branches_match.group(1)
             rev = branches_match.group(2)
             if "default" != branch:
                 branch_revs.append((rev.strip(), branch.strip()))
     return dict(branch_revs)
示例#47
0
    def from_dist(cls, dist, pre_installed=False):
        # dist is either an InstallRequirement or a FrozenRequirement.
        # We have to deal with installs from a URL (no name), pypi installs (with and without explicit versions)
        # and editable installs from git.
        name = None if not hasattr(dist, "name") else dist.name
        editable = False if not hasattr(dist, "editable") else dist.editable
        comes_from = None if not hasattr(dist, "comes_from") else dist.comes_from
        url = None
        location = None
        version = None

        if comes_from is None and pre_installed:
            comes_from = "[already available]"

        if hasattr(dist, "req"):
            if type(dist.req) == str:
                url = dist.req
                version = GitVersionComparator.get_version_string_from_url(url)
            elif (
                hasattr(dist.req, "specs")
                and len(dist.req.specs) == 1
                and len(dist.req.specs[0]) == 2
                and dist.req.specs[0][0] == "=="
            ):
                version = dist.req.specs[0][1]
        if url is None and hasattr(dist, "url"):
            url = dist.url
        if hasattr(dist, "location"):
            location = dist.location
        elif name is not None and url is not None and editable:
            location_candidate = os.path.join(sys.prefix, "src", dist.name, ".git")
            if os.path.exists(location_candidate):
                location = location_candidate
                if hasattr(dist, "url") and dist.url:
                    version = GitVersionComparator.get_version_string_from_url(dist.url)
                if version is None:
                    ret = call_subprocess(
                        ["git", "log", "-n", "1", "--pretty=oneline"], show_stdout=False, cwd=location
                    )
                    version = ret.split(" ")[0]
        pd = cls(
            name=name,
            url=url,
            location=location,
            editable=editable,
            version=version,
            comes_from=comes_from,
            requirement=dist,
        )
        if pre_installed:
            pd.state = PackageData.PREINSTALLED
        return pd
示例#48
0
 def get_url(self, location):
     urls = call_subprocess([self.cmd, 'info'],
                            show_stdout=False,
                            cwd=location)
     for line in urls.splitlines():
         line = line.strip()
         for x in ('checkout of branch: ', 'parent branch: '):
             if line.startswith(x):
                 repo = line.split(x)[1]
                 if self._is_local_repository(repo):
                     return path_to_url(repo)
                 return repo
     return None
示例#49
0
 def get_refs(self, location):
     """Return map of named refs (branches or tags) to commit hashes."""
     output = call_subprocess([self.cmd, 'show-ref'],
                              show_stdout=False, cwd=location)
     rv = {}
     for line in output.strip().splitlines():
         commit, ref = line.split(' ', 1)
         ref = ref.strip()
         ref_name = None
         if ref.startswith('refs/remotes/'):
             ref_name = ref[len('refs/remotes/'):]
         elif ref.startswith('refs/heads/'):
             ref_name = ref[len('refs/heads/'):]
         elif ref.startswith('refs/tags/'):
             ref_name = ref[len('refs/tags/'):]
         if ref_name is not None:
             rv[ref_name] = commit.strip()
     return rv
示例#50
0
    def from_dist(cls, dist, pre_installed=False):
        # dist is either an InstallRequirement or a FrozenRequirement.
        # We have to deal with installs from a URL (no name), pypi installs (with and without explicit versions)
        # and editable installs from git.
        name = None if not hasattr(dist, 'name') else dist.name
        editable = False if not hasattr(dist, 'editable') else dist.editable
        comes_from = None if not hasattr(dist, 'comes_from') else dist.comes_from
        url = None
        location = None
        version = None

        if comes_from is None and pre_installed:
            comes_from = "[already available]"

        if hasattr(dist, 'req'):
            if type(dist.req) == str:
                url = dist.req
                version = GitVersionComparator.get_version_string_from_url(url)
            elif hasattr(dist.req, 'specs') and len(dist.req.specs) == 1 and len(dist.req.specs[0]) == 2 and dist.req.specs[0][0] == '==':
                version = dist.req.specs[0][1]
        if url is None and hasattr(dist, 'url'):
            url = dist.url
        if hasattr(dist, 'location'):
            location = dist.location
        elif name is not None and url is not None and editable:
            location_candidate = os.path.join(sys.prefix, 'src', dist.name, '.git')
            if os.path.exists(location_candidate):
                location = location_candidate
                if hasattr(dist, 'url') and dist.url:
                    version = GitVersionComparator.get_version_string_from_url(dist.url)
                if version is None:
                    ret = call_subprocess(['git', 'log', '-n', '1', '--pretty=oneline'], show_stdout=False, cwd=location)
                    version = ret.split(" ")[0]
        pd = cls(
            name=name,
            url=url,
            location=location,
            editable=editable,
            version=version,
            comes_from=comes_from,
            requirement=dist)
        if pre_installed:
            pd.state = PackageData.PREINSTALLED
        return pd
示例#51
0
 def _get_all_tag_names(self, location):
     return call_subprocess([self.cmd, 'tag', '-l'],
                            show_stdout=False,
                            raise_on_returncode=False,
                            cwd=location)
示例#52
0
 def _get_revision_from_rev_parse(self, name, location):
     return call_subprocess([self.cmd, 'rev-parse', name],
                            show_stdout=False,
                            cwd=location)
示例#53
0
 def get_revision(self, location):
     current_rev = call_subprocess([self.cmd, 'rev-parse', 'HEAD'],
                                   show_stdout=False,
                                   cwd=location)
     return current_rev.strip()