def create(self, name=None, prefix=None, pkgs=None, channels=None):
        """Create an environment with a specified set of packages."""
        logger.debug(str((prefix, pkgs, channels)))

        # TODO: Fix temporal hack
        if (not pkgs or (not isinstance(pkgs, (list, tuple)) and
                         not is_text_string(pkgs))):
            raise TypeError('must specify a list of one or more packages to '
                            'install into new environment')

        cmd_list = ['create', '--yes', '--json', '--mkdir']
        if name:
            ref = name
            search = [os.path.join(d, name) for d in
                      self.info().communicate()[0]['envs_dirs']]
            cmd_list.extend(['--name', name])
        elif prefix:
            ref = prefix
            search = [prefix]
            cmd_list.extend(['--prefix', prefix])
        else:
            raise TypeError('must specify either an environment name or a '
                            'path for new environment')

        if any(os.path.exists(prefix) for prefix in search):
            raise CondaEnvExistsError('Conda environment {0} already '
                                      'exists'.format(ref))

        # TODO: Fix temporal hack
        if isinstance(pkgs, (list, tuple)):
            cmd_list.extend(pkgs)
        elif is_text_string(pkgs):
            cmd_list.extend(['--file', pkgs])

        # TODO: Check if correct
        if channels:
            cmd_list.extend(['--override-channels'])

            for channel in channels:
                cmd_list.extend(['--channel'])
                cmd_list.extend([channel])

        return self._call_and_parse(cmd_list)
def create ( self , name = None , prefix = None , pkgs = None , channels = None ) : logger . debug ( str ( ( prefix , pkgs , channels ) ) ) if ( not pkgs or ( not isinstance ( pkgs , ( list , tuple ) ) and not is_text_string ( pkgs ) ) ) : raise TypeError ( 'must specify a list of one or more packages to ' 'install into new environment' ) cmd_list = [ 'create' , '--yes' , '--json' , '--mkdir' ] if name : ref = name search = [ os . path . join ( d , name ) for d in self . info ( ) . communicate ( ) [ 0 ] [ 'envs_dirs' ] ] cmd_list . extend ( [ '--name' , name ] ) elif prefix : ref = prefix search = [ prefix ] cmd_list . extend ( [ '--prefix' , prefix ] ) else : raise TypeError ( 'must specify either an environment name or a ' 'path for new environment' ) if any ( os . path . exists ( prefix ) for prefix in search ) : raise CondaEnvExistsError ( 'Conda environment {0} already ' 'exists' . format ( ref ) ) if isinstance ( pkgs , ( list , tuple ) ) : cmd_list . extend ( pkgs ) elif is_text_string ( pkgs ) : cmd_list . extend ( [ '--file' , pkgs ] ) if channels : cmd_list . extend ( [ '--override-channels' ] ) for channel in channels : cmd_list . extend ( [ '--channel' ] ) cmd_list . extend ( [ channel ] ) return self . _call_and_parse ( cmd_list )
Create an environment with a specified set of packages.