def to_json(self): """JSON/YAML version of the lock set.""" yaml_dict = _CommentedMap() yaml_dict['locked'] = self.enabled if self.env_spec_hash is not None: yaml_dict['env_spec_hash'] = self.env_spec_hash platforms_list = _CommentedSeq() for platform in self.platforms: platforms_list.append(platform) yaml_dict['platforms'] = platforms_list packages_dict = _CommentedMap() for platform in conda_api.sort_platform_list( self._package_specs_by_platform.keys()): packages = _CommentedSeq() for package in self._package_specs_by_platform[platform]: packages.append(package) packages_dict[platform] = packages yaml_dict['packages'] = packages_dict _block_style_all_nodes(yaml_dict) return yaml_dict
def __init__(self, package_specs_by_platform, platforms, enabled=True, env_spec_hash=None, missing=False): """Construct a ``CondaLockSet``. The passed-in dict should be like: { "all" : [ "bokeh=0.12.4=1" ], "linux-64" : [ "libffi=1.2=0" ] } Args: packages_by_platform (dict): dict from platform to spec list platforms (list of str): platform list """ assert package_specs_by_platform is not None assert platforms is not None # we deepcopy this to avoid sharing issues self._package_specs_by_platform = deepcopy(package_specs_by_platform) self._platforms = tuple(conda_api.sort_platform_list(platforms)) self._enabled = enabled self._env_spec_hash = env_spec_hash self._missing = missing
def diff_from(self, old): """A string showing the comparison between this lock set and another one. "old" can be None to mean diff vs. nothing. """ keys = list(self._package_specs_by_platform.keys()) if old is not None: keys = keys + list(old._package_specs_by_platform.keys()) # de-dup keys = list(set(keys)) # sort nicely keys = conda_api.sort_platform_list(keys) packages_diff = [] for key in keys: if old is None: old_list = [] else: old_list = old._package_specs_by_platform.get(key, []) new_list = self._package_specs_by_platform.get(key, []) diff = _pretty_diff(old_list, new_list, indent=" ") if diff: if old is None or key not in old._package_specs_by_platform: packages_diff.append("+ %s:" % key) elif key not in self._package_specs_by_platform: packages_diff.append("- %s:" % key) else: packages_diff.append(" %s:" % key) packages_diff.extend(map(lambda x: x, diff)) if packages_diff: packages_diff = [' packages:'] + packages_diff if old is None: old_platforms = [] else: old_platforms = old.platforms platforms_diff = _pretty_diff(old_platforms, self.platforms, indent=" ") if platforms_diff: platforms_diff = [' platforms:'] + platforms_diff return "\n".join(platforms_diff + packages_diff)
def test_sort_platform_list(): everything_sorted = ('all', 'linux', 'osx', 'win') + conda_api.default_platforms_plus_32_bit backward = list(reversed(everything_sorted)) shuffled = list(everything_sorted) random.shuffle(shuffled) assert everything_sorted == tuple(conda_api.sort_platform_list(backward)) assert everything_sorted == tuple(conda_api.sort_platform_list(shuffled)) assert everything_sorted == tuple( conda_api.sort_platform_list(tuple(backward))) assert everything_sorted == tuple( conda_api.sort_platform_list(tuple(shuffled))) assert [] == conda_api.sort_platform_list([]) assert [] == conda_api.sort_platform_list(()) assert ['linux-64', 'osx-64', 'win-64' ] == conda_api.sort_platform_list(['win-64', 'osx-64', 'linux-64'])
def __init__(self, name, conda_packages, channels, pip_packages=(), description=None, inherit_from_names=(), inherit_from=(), platforms=(), lock_set=None): """Construct a package set with the given name and packages. Args: name (str): name of the package set conda_packages (list): list of package specs to pass to conda install channels (list): list of channel names pip_packages (list): list of pip package specs to pass to pip description (str or None): one-sentence-ish summary of what this env is inherit_from_name (str or None): name of what we inherit from inherit_from (EnvSpec or None): pull in packages and channels from lock_set (CondaLockSet): locked packages or None """ assert inherit_from_names is not None assert inherit_from is not None self._name = name self._conda_packages = tuple(conda_packages) self._channels = tuple(channels) self._pip_packages = tuple(pip_packages) self._description = description self._logical_hash = None self._locked_hash = None self._import_hash = None self._inherit_from_names = inherit_from_names self._inherit_from = inherit_from self._lock_set = lock_set self._platforms = tuple(conda_api.sort_platform_list(platforms)) # inherit_from must be a subset of inherit_from_names # except that we can have an anonymous base env spec for # the global packages/channels sections; if there was an # error that kept us from creating one of the specs we # name as a parent, then self._inherit_from would be a # subset rather than equal. for name in tuple([spec.name for spec in self._inherit_from]): assert name is None or name in self._inherit_from_names conda_specs_by_name = dict() for spec in self.conda_packages_for_create: # we quietly skip invalid specs here and let them fail # somewhere we can more easily report an error message. parsed = conda_api.parse_spec(spec) if parsed is not None: conda_specs_by_name[parsed.name] = spec self._conda_specs_for_create_by_name = conda_specs_by_name name_set = set() conda_constrained_packages = [] for spec in self.conda_packages: parsed = conda_api.parse_spec(spec) if parsed is not None: name_set.add(parsed.name) if parsed.conda_constraint is not None or parsed.pip_constraint is not None: conda_constrained_packages.append(spec) self._conda_logical_specs_name_set = name_set self.conda_constrained_packages = sorted(conda_constrained_packages) pip_specs_by_name = dict() for spec in self.pip_packages: # we quietly skip invalid specs here and let them fail # somewhere we can more easily report an error message. parsed = pip_api.parse_spec(spec) if parsed is not None: pip_specs_by_name[parsed.name] = spec self._pip_specs_by_name = pip_specs_by_name