示例#1
0
    def install_editable(
        self,
        install_options,  # type: List[str]
        global_options=(),  # type: Sequence[str]
        prefix=None  # type: Optional[str]
    ):
        # type: (...) -> None
        logger.info('Running setup.py develop for %s', self.name)

        if self.isolated:
            global_options = list(global_options) + ["--no-user-cfg"]

        if prefix:
            prefix_param = ['--prefix={}'.format(prefix)]
            install_options = list(install_options) + prefix_param

        with indent_log():
            # FIXME: should we do --install-headers here too?
            with self.build_env:
                call_subprocess(
                    [
                        sys.executable,
                        '-c',
                        SETUPTOOLS_SHIM % self.setup_py
                    ] +
                    list(global_options) +
                    ['develop', '--no-deps'] +
                    list(install_options),

                    cwd=self.setup_py_dir,
                )

        self.install_succeeded = True
示例#2
0
 def run_egg_info(self):
     # type: () -> None
     if self.name:
         logger.debug(
             'Running setup.py (path:%s) egg_info for package %s',
             self.setup_py, self.name,
         )
     else:
         logger.debug(
             'Running setup.py (path:%s) egg_info for package from %s',
             self.setup_py, self.link,
         )
     script = SETUPTOOLS_SHIM % self.setup_py
     base_cmd = [sys.executable, '-c', script]
     if self.isolated:
         base_cmd += ["--no-user-cfg"]
     egg_info_cmd = base_cmd + ['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 = []  # type: List[str]
     else:
         egg_info_dir = os.path.join(self.setup_py_dir, 'ins-egg-info')
         ensure_dir(egg_info_dir)
         egg_base_option = ['--egg-base', 'ins-egg-info']
     with self.build_env:
         call_subprocess(
             egg_info_cmd + egg_base_option,
             cwd=self.setup_py_dir,
             command_desc='python setup.py egg_info')
示例#3
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)
            return True
        except Exception:
            logger.error('Failed cleaning build dir for %s', req.name)
            return False
示例#4
0
 def runner(
     cmd,  # type: List[str]
     cwd=None,  # type: Optional[str]
     extra_environ=None  # type: Optional[Mapping[str, Any]]
 ):
     # type: (...) -> None
     with open_spinner(self.spin_message) as spinner:
         call_subprocess(
             cmd,
             cwd=cwd,
             extra_environ=extra_environ,
             spinner=spinner
         )
     self.spin_message = ""
示例#5
0
    def _build_one_legacy(self, req, tempd, python_tag=None):
        """Build one InstallRequirement using the "legacy" build process.

        Returns path to wheel if successfully built. Otherwise, returns None.
        """
        base_args = self._base_setup_args(req)

        spin_message = 'Building wheel for %s (setup.py)' % (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:
                output = call_subprocess(wheel_args,
                                         cwd=req.setup_py_dir,
                                         spinner=spinner)
            except Exception:
                spinner.finish("error")
                logger.error('Failed building wheel for %s', req.name)
                return None
            names = os.listdir(tempd)
            wheel_path = get_legacy_build_wheel_path(
                names=names,
                temp_dir=tempd,
                req=req,
                command_args=wheel_args,
                command_output=output,
            )
            return wheel_path
示例#6
0
 def install_requirements(
     self,
     finder,  # type: PackageFinder
     requirements,  # type: Iterable[str]
     prefix_as_string,  # type: str
     message  # type: Optional[str]
 ):
     # type: (...) -> None
     prefix = self._prefixes[prefix_as_string]
     assert not prefix.setup
     prefix.setup = True
     if not requirements:
         return
     args = [
         sys.executable, os.path.dirname(ins_location), 'install',
         '--ignore-installed', '--no-user', '--prefix', prefix.path,
         '--no-warn-script-location',
     ]  # type: List[str]
     if logger.getEffectiveLevel() <= logging.DEBUG:
         args.append('-v')
     for format_control in ('no_binary', 'only_binary'):
         formats = getattr(finder.format_control, format_control)
         args.extend(('--' + format_control.replace('_', '-'),
                      ','.join(sorted(formats or {':none:'}))))
     if finder.index_urls:
         args.extend(['-i', finder.index_urls[0]])
         for extra_index in finder.index_urls[1:]:
             args.extend(['--extra-index-url', extra_index])
     else:
         args.append('--no-index')
     for link in finder.find_links:
         args.extend(['--find-links', link])
     for _, host, _ in finder.secure_origins:
         args.extend(['--trusted-host', host])
     if finder.allow_all_prereleases:
         args.append('--pre')
     args.append('--')
     args.extend(requirements)
     with open_spinner(message) as spinner:
         call_subprocess(args, spinner=spinner)
示例#7
0
 def run_command(
     cls,
     cmd,  # type: List[str]
     show_stdout=True,  # type: bool
     cwd=None,  # type: Optional[str]
     on_returncode='raise',  # type: str
     extra_ok_returncodes=None,  # type: Optional[Iterable[int]]
     command_desc=None,  # type: Optional[str]
     extra_environ=None,  # type: Optional[Mapping[str, Any]]
     spinner=None  # type: Optional[SpinnerInterface]
 ):
     # type: (...) -> Optional[Text]
     """
     Run a VCS subcommand
     This is simply a wrapper around call_subprocess that adds the VCS
     command name, and checks that the VCS is available
     """
     cmd = [cls.name] + cmd
     try:
         return call_subprocess(cmd,
                                show_stdout,
                                cwd,
                                on_returncode=on_returncode,
                                extra_ok_returncodes=extra_ok_returncodes,
                                command_desc=command_desc,
                                extra_environ=extra_environ,
                                unset_environ=cls.unset_environ,
                                spinner=spinner)
     except OSError as e:
         # errno.ENOENT = no such file or directory
         # In other words, the VCS executable isn't available
         if e.errno == errno.ENOENT:
             raise BadCommand('Cannot find command %r - do you have '
                              '%r installed and in your '
                              'PATH?' % (cls.name, cls.name))
         else:
             raise  # re-raise exception if a different error occurred
示例#8
0
    def install(
        self,
        install_options,  # type: List[str]
        global_options=None,  # type: Optional[Sequence[str]]
        root=None,  # type: Optional[str]
        home=None,  # type: Optional[str]
        prefix=None,  # type: Optional[str]
        warn_script_location=True,  # type: bool
        use_user_site=False,  # type: bool
        pycompile=True  # type: bool
    ):
        # type: (...) -> None
        global_options = global_options if global_options is not None else []
        if self.editable:
            self.install_editable(
                install_options, global_options, prefix=prefix,
            )
            return
        if self.is_wheel:
            version = wheel.wheel_version(self.source_dir)
            wheel.check_compatibility(version, self.name)

            self.move_wheel_files(
                self.source_dir, root=root, prefix=prefix, home=home,
                warn_script_location=warn_script_location,
                use_user_site=use_user_site, pycompile=pycompile,
            )
            self.install_succeeded = True
            return

        # Extend the list of global and install options passed on to
        # the setup.py call with the ones from the requirements file.
        # Options specified in requirements file override those
        # specified on the command line, since the last option given
        # to setup.py is the one that is used.
        global_options = list(global_options) + \
            self.options.get('global_options', [])
        install_options = list(install_options) + \
            self.options.get('install_options', [])

        if self.isolated:
            # https://github.com/python/mypy/issues/1174
            global_options = global_options + ["--no-user-cfg"]  # type: ignore

        with TempDirectory(kind="record") as temp_dir:
            record_filename = os.path.join(temp_dir.path, 'install-record.txt')
            install_args = self.get_install_args(
                global_options, record_filename, root, prefix, pycompile,
            )
            msg = 'Running setup.py install for %s' % (self.name,)
            with open_spinner(msg) as spinner:
                with indent_log():
                    with self.build_env:
                        call_subprocess(
                            install_args + install_options,
                            cwd=self.setup_py_dir,
                            spinner=spinner,
                        )

            if not os.path.exists(record_filename):
                logger.debug('Record file %s not found', record_filename)
                return
            self.install_succeeded = True

            def prepend_root(path):
                # type: (str) -> str
                if root is None or not os.path.isabs(path):
                    return path
                else:
                    return change_root(root, path)

            with open(record_filename) as f:
                for line in f:
                    directory = os.path.dirname(line)
                    if directory.endswith('.egg-info'):
                        egg_info_dir = prepend_root(directory)
                        break
                else:
                    logger.warning(
                        'Could not find .egg-info directory in install record'
                        ' for %s',
                        self,
                    )
                    # FIXME: put the record somewhere
                    # FIXME: should this be an error?
                    return
            new_lines = []
            with open(record_filename) as f:
                for line in f:
                    filename = line.strip()
                    if os.path.isdir(filename):
                        filename += os.path.sep
                    new_lines.append(
                        os.path.relpath(prepend_root(filename), egg_info_dir)
                    )
            new_lines.sort()
            ensure_dir(egg_info_dir)
            inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
            with open(inst_files_path, 'w') as f:
                f.write('\n'.join(new_lines) + '\n')