Beispiel #1
0
 def __init__(self,
              session,
              path,
              python,
              requirements_manager,
              execution_info=None,
              **kwargs):
     # type: (Session, PathLike, float, RequirementsManager, ExecutionInfo, Any) -> None
     """
     :param python: base python version to use (e.g python3.6)
     :param path: path of env
     """
     self.session = session
     self.python = python
     self.source = None
     self.requirements_manager = requirements_manager
     self.path = path
     self.env_read_only = False
     self.extra_channels = self.session.config.get(
         'agent.package_manager.conda_channels', [])
     self.conda_env_as_base_docker = \
         self.session.config.get('agent.package_manager.conda_env_as_base_docker', None) or \
         bool(ENV_CONDA_ENV_PACKAGE.get())
     if ENV_CONDA_ENV_PACKAGE.get():
         self.conda_pre_build_env_path = ENV_CONDA_ENV_PACKAGE.get()
     else:
         self.conda_pre_build_env_path = execution_info.docker_cmd if execution_info else None
     self.pip = CondaPip(
         session=self.session,
         source=self.source,
         python=self.python,
         requirements_manager=self.requirements_manager,
         path=self.path,
     )
     try:
         self.conda = (find_executable("conda") or Argv(
             select_for_platform(windows="where", linux="which"),
             "conda").get_output(shell=select_for_platform(
                 windows=True, linux=False)).strip())
     except Exception:
         raise ValueError("ERROR: package manager \"conda\" selected, "
                          "but \'conda\' executable could not be located")
     try:
         output = Argv(self.conda,
                       "--version").get_output(stderr=subprocess.STDOUT)
     except subprocess.CalledProcessError as ex:
         raise CommandFailedError(
             "Unable to determine conda version: {ex}, output={ex.output}".
             format(ex=ex))
     self.conda_version = self.get_conda_version(output)
     if SimpleVersion.compare_versions(self.conda_version, '<',
                                       self.MINIMUM_VERSION):
         raise CommandFailedError(
             "conda version '{}' is smaller than minimum supported conda version '{}'"
             .format(self.conda_version, self.MINIMUM_VERSION))
Beispiel #2
0
 def __init__(self,
              session,
              python,
              requirements_manager,
              path,
              interpreter=None):
     # type: (Session, float, RequirementsManager, PathLike, PathLike) -> ()
     """
     Program interface to virtualenv pip.
     Must be given either path to virtualenv or source command.
     Either way, ``self.source`` is exposed.
     :param python: interpreter path
     :param path: path of virtual environment to create/manipulate
     :param python: python version
     :param interpreter: path of python interpreter
     """
     super(VirtualenvPip, self).__init__(interpreter or Path(
         path,
         select_for_platform(linux="bin/python",
                             windows="scripts/python.exe"),
     ))
     self.session = session
     self.path = path
     self.requirements_manager = requirements_manager
     self.python = python
Beispiel #3
0
 def __init__(self, session, path, python, requirements_manager):
     # type: (Session, PathLike, float, RequirementsManager) -> None
     """
     :param python: base python version to use (e.g python3.6)
     :param path: path of env
     """
     self.session = session
     self.python = python
     self.source = None
     self.requirements_manager = requirements_manager
     self.path = path
     self.extra_channels = self.session.config.get(
         'agent.package_manager.conda_channels', [])
     self.pip = CondaPip(
         session=self.session,
         source=self.source,
         python=self.python,
         requirements_manager=self.requirements_manager,
         path=self.path,
     )
     self.conda = (find_executable("conda") or Argv(
         select_for_platform(windows="where", linux="which"),
         "conda").get_output(shell=True).strip())
     try:
         output = Argv(self.conda, "--version").get_output()
     except subprocess.CalledProcessError as ex:
         raise CommandFailedError(
             "Unable to determine conda version: {ex}, output={ex.output}".
             format(ex=ex))
     self.conda_version = self.get_conda_version(output)
     if Version(self.conda_version, partial=True) < self.MINIMUM_VERSION:
         raise CommandFailedError(
             "conda version '{}' is smaller than minimum supported conda version '{}'"
             .format(self.conda_version, self.MINIMUM_VERSION))
Beispiel #4
0
 def executable_not_found_error_help(self):
     return 'Cannot find "{}" executable. {}'.format(
         self.executable_name,
         select_for_platform(
             linux="You can install it by running: sudo apt-get install {}".
             format(self.executable_name),
             windows="You can download it here: {}".format(
                 "https://www.mercurial-scm.org/wiki/Download"),
         ),
     )
Beispiel #5
0
 def call_subprocess(self, func, censor_password=False, *args, **kwargs):
     with self.normalize_exception(censor_password):
         return func(
             self.serialize(), *args,
             **chain_map(
                 dict(
                     executable=select_for_platform(linux="bash",
                                                    windows=None),
                     shell=True,
                 ),
                 kwargs,
             ))
Beispiel #6
0
    def __init__(self, foreground=False, queues=(), *args, **kwargs):
        super(DaemonParams, self).__init__(*args, **kwargs)
        self.foreground = foreground
        self.queues = tuple(queues)

    def get_worker_flags(self):
        global_args, worker_args = super(DaemonParams, self).get_worker_flags()
        if self.foreground:
            worker_args += ("--foreground",)
        if self.queues:
            worker_args += ("--queue",) + self.queues
        return global_args, worker_args


DEVNULL = open(devnull, "w+")
SOURCE_COMMAND = select_for_platform(linux="source", windows="call")


class ExitStatus(object):
    success = 0
    failure = 1
    interrupted = 2


COMMAND_SUCCESS = 0


_find_unsafe = re.compile(r"[^\w@%+=:,./-]", getattr(re, "ASCII", 0)).search


def quote(s):