Ejemplo n.º 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
     """
     super(CondaAPI, self).__init__()
     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))
Ejemplo n.º 2
0
 def upgrade_pip(self):
     # do not change pip version if pre built environement is used
     if self.env_read_only:
         print('Conda environment in read-only mode, skipping pip upgrade.')
         return ''
     return self._install(
         select_for_platform(windows='pip{}', linux='pip{}').format(
             self.pip.get_pip_version()))
Ejemplo n.º 3
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"),
         ),
     )
Ejemplo n.º 4
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,
             ))
Ejemplo n.º 5
0
 def _get_conda_sh(self):
     # type () -> Path
     base_conda_env = Path(self.conda).parent.parent / 'etc' / 'profile.d' / 'conda.sh'
     if base_conda_env.is_file():
         return base_conda_env
     for path in os.environ.get('PATH', '').split(select_for_platform(windows=';', linux=':')):
         conda = find_executable("conda", path=path)
         if not conda:
             continue
         conda_env = Path(conda).parent.parent / 'etc' / 'profile.d' / 'conda.sh'
         if conda_env.is_file():
             return conda_env
     return base_conda_env
Ejemplo n.º 6
0
 def upgrade_pip(self):
     result = self._install(
         select_for_platform(windows='pip{}',
                             linux='pip{}').format(self.get_pip_version()),
         "--upgrade")
     packages = self.run_with_env(('list', ), output=True).splitlines()
     # p.split is ('pip', 'x.y.z')
     pip = [
         p.split() for p in packages
         if len(p.split()) == 2 and p.split()[0] == 'pip'
     ]
     if pip:
         # noinspection PyBroadException
         try:
             from .requirements import MarkerRequirement
             pip = pip[0][1].split('.')
             MarkerRequirement.pip_new_version = bool(int(pip[0]) >= 20)
         except Exception:
             pass
     return result
Ejemplo n.º 7
0
 def __init__(self, session, python, requirements_manager, path, interpreter=None, execution_info=None, **kwargs):
     # type: (Session, float, RequirementsManager, PathLike, PathLike, ExecutionInfo, Any) -> ()
     """
     Program interface to virtualenv pip.
     Must be given either path to virtualenv or source command.
     Either way, ``self.source`` is exposed.
     :param session: a Session object for communication
     :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__(
         session=session,
         interpreter=interpreter or Path(
             path, select_for_platform(linux="bin/python", windows="scripts/python.exe"))
     )
     self.path = path
     self.requirements_manager = requirements_manager
     self.python = python
Ejemplo n.º 8
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):