Beispiel #1
0
    def conda_and_pip_install(self, create=True):
        """Return Dockerfile instructions to create conda environment with
        desired version of Python and desired conda and pip packages.
        """
        conda_cmd = "conda create" if create else "conda install"
        cmd = "{} -y -q --name {}".format(conda_cmd, self.env_name)

        if self.conda_opts:
            cmd = "{} {}".format(cmd, self.conda_opts)

        if self.conda_install:
            if isinstance(self.conda_install, str):
                self.conda_install = self.conda_install.split()
            pkgs = _indent_pkgs(len(cmd.split('\n')[-1]), self.conda_install)
            cmd += pkgs
            # cmd += "\n\t{}".format(self.conda_install)

        cmd += "\n&& sync && conda clean -tipsy && sync"

        if not self.conda_install and not create:
            cmd = ""
        if self.pip_install:
            if self.conda_install or create:
                cmd += "\n&& "
            cmd += self._pip_install()

        if self.activate:
            cmd += self._get_source_activate_cmd()

        cmd = indent("RUN", cmd)
        self.created_envs.append(self.env_name)
        return cmd
Beispiel #2
0
    def _pip_install(self):
        """Return Dockerfile instruction to install desired pip packages."""
        if isinstance(self.pip_install, str):
            self.pip_install = self.pip_install.split()

        cmd = ('/bin/bash -c "source activate {}'
               '\n  && pip install -q --no-cache-dir').format(self.env_name)

        if self.pip_opts:
            cmd = "{} {}".format(cmd, self.pip_opts)

        pkgs = _indent_pkgs(len(cmd.split('\n')[-1]), self.pip_install)

        return '{}{}"\n&& sync'.format(cmd, pkgs)
Beispiel #3
0
    def conda_and_pip_install(self, create=True):
        """Return Dockerfile instructions to create conda environment with
        desired version of Python and desired conda and pip packages.
        """
        conda_cmd = "conda create" if create else "conda install"
        cmd = "{} -y -q --name {}".format(conda_cmd, self.env_name)

        if self.conda_opts:
            cmd = "{} {}".format(cmd, self.conda_opts)

        if self.conda_install:
            if isinstance(self.conda_install, str):
                self.conda_install = self.conda_install.split()
            pkgs = _indent_pkgs(len(cmd.split('\n')[-1]), self.conda_install)
            cmd += pkgs
            # cmd += "\n\t{}".format(self.conda_install)

        cmd += "\n&& sync && conda clean -tipsy && sync"

        if not self.conda_install and not create:
            cmd = ""
        if self.pip_install:
            if self.conda_install or create:
                cmd += "\n&& "
            cmd += self._pip_install()

        cmd = indent("RUN", cmd)

        self.created_envs.append(self.env_name)

        if self.add_to_path:
            bin_path = posixpath.join(Miniconda.INSTALL_PATH, 'envs',
                                      self.env_name, 'bin')
            env_cmd = "ENV PATH={}:$PATH".format(bin_path)
            return "\n".join((cmd, env_cmd))
        return cmd