Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_install_features(self):
with make_temp_env("python=2 numpy=1.13 nomkl") as prefix:
assert package_is_installed(prefix, "numpy")
assert package_is_installed(prefix, "nomkl")
assert not package_is_installed(prefix, "mkl")
numpy_prec = PrefixData(prefix).get("numpy")
assert "nomkl" in numpy_prec.build
with make_temp_env("python=2 numpy=1.13") as prefix:
assert package_is_installed(prefix, "numpy")
assert not package_is_installed(prefix, "nomkl")
assert package_is_installed(prefix, "mkl")
numpy_prec = PrefixData(prefix).get("numpy")
assert "nomkl" not in numpy_prec.build
run_command(Commands.INSTALL, prefix, "nomkl")
assert package_is_installed(prefix, "numpy")
assert package_is_installed(prefix, "nomkl")
assert package_is_installed(prefix, "mkl") # it's fine for mkl to still be here I guess
numpy_prec = PrefixData(prefix).get("numpy")
assert "nomkl" in numpy_prec.build
def get_solver(specs_to_add=(), specs_to_remove=(), prefix_records=(), history_specs=()):
PrefixData._cache_.clear()
pd = PrefixData(TEST_PREFIX)
pd._PrefixData__prefix_records = {rec.name: PrefixRecord.from_objects(rec) for rec in prefix_records}
spec_map = {spec.name: spec for spec in history_specs}
get_index_r_1(context.subdir)
with patch.object(History, 'get_requested_specs_map', return_value=spec_map):
solver = Solver(TEST_PREFIX, (Channel('channel-1'),), (context.subdir,),
specs_to_add=specs_to_add, specs_to_remove=specs_to_remove)
yield solver
if isinstall and args.revision:
get_revision(args.revision, json=context.json)
elif isinstall and not (args.file or args_packages):
raise CondaValueError("too few arguments, "
"must supply command line package specs or --file")
# for 'conda update', make sure the requested specs actually exist in the prefix
# and that they are name-only specs
if isupdate and context.update_modifier == UpdateModifier.UPDATE_ALL:
# Note: History(prefix).get_requested_specs_map()
print("Currently, mamba can only update explicit packages! (e.g. mamba update numpy python ...)")
exit()
if isupdate and context.update_modifier != UpdateModifier.UPDATE_ALL:
prefix_data = PrefixData(prefix)
for s in args_packages:
s = MatchSpec(s)
if not s.is_name_only_spec:
raise CondaError("Invalid spec for 'conda update': %s\n"
"Use 'conda install' instead." % s)
if not prefix_data.get(s.name, None):
raise PackageNotInstalledError(prefix, s.name)
if newenv and args.clone:
if args.packages:
raise TooManyArgumentsError(0, len(args.packages), list(args.packages),
'did not expect any arguments for --clone')
clone(args.clone, prefix, json=context.json, quiet=context.quiet, index_args=index_args)
touch_nonadmin(prefix)
print_activate(args.name if args.name else prefix)
yield gparent
yield parent
return tuple(_all_descendants())
has_children = property(lambda self: self.required_children or self.optional_children)
has_parents = property(lambda self: self.required_parents or self.optional_parents)
is_root = property(lambda self: self.has_children and not self.has_parents)
is_leaf = property(lambda self: self.has_parents and not self.has_children)
is_orphan = property(lambda self: not self.has_parents and not self.has_children)
if __name__ == "__main__":
from ..core.prefix_data import PrefixData
from ..history import History
prefix = sys.argv[1]
records = PrefixData(prefix).iter_records()
specs = itervalues(History(prefix).get_requested_specs_map())
PrefixDag(records, specs).open_url()
def get_installed_packages(prefix, show_channel_urls=None):
result = {'packages': {}}
# Currently, we need to have pip interop disabled :/
installed = list(PrefixData(prefix, pip_interop_enabled=False).iter_records())
for prec in installed:
json_rec = prec.dist_fields_dump()
json_rec['depends'] = prec.depends
json_rec['build'] = prec.build
result['packages'][prec.fn] = json_rec
return installed, result
def _prepare(cls, transaction_context, target_prefix, unlink_precs, link_precs,
remove_specs, update_specs, neutered_specs):
# make sure prefix directory exists
if not isdir(target_prefix):
try:
mkdir_p(target_prefix)
except (IOError, OSError) as e:
log.debug(repr(e))
raise CondaError("Unable to create prefix directory '%s'.\n"
"Check that you have sufficient permissions."
"" % target_prefix)
# gather information from disk and caches
prefix_data = PrefixData(target_prefix)
prefix_recs_to_unlink = (prefix_data.get(prec.name) for prec in unlink_precs)
# NOTE: load_meta can return None
# TODO: figure out if this filter shouldn't be an assert not None
prefix_recs_to_unlink = tuple(lpd for lpd in prefix_recs_to_unlink if lpd)
pkg_cache_recs_to_link = tuple(PackageCacheData.get_entry_to_link(prec)
for prec in link_precs)
assert all(pkg_cache_recs_to_link)
packages_info_to_link = tuple(read_package_info(prec, pcrec)
for prec, pcrec in zip(link_precs, pkg_cache_recs_to_link))
link_types = tuple(determine_link_type(pkg_info.extracted_package_dir, target_prefix)
for pkg_info in packages_info_to_link)
# make all the path actions
# no side effects allowed when instantiating these action objects
python_version = cls._get_python_version(target_prefix,
if specs_to_remove and force_remove:
if specs_to_add:
raise NotImplementedError()
index, r = self._prepare(specs_to_remove)
solution = tuple(Dist(rec) for rec in PrefixData(self.prefix).iter_records()
if not any(spec.match(rec) for spec in specs_to_remove))
return IndexedSet(index[d] for d in r.dependency_sort({d.name: d for d in solution}))
log.debug("solving prefix %s\n"
" specs_to_remove: %s\n"
" specs_to_add: %s\n"
" prune: %s", self.prefix, specs_to_remove, specs_to_add, prune)
# declare starting point, the initial state of the environment
# `solution` and `specs_map` are mutated throughout this method
prefix_data = PrefixData(self.prefix)
solution = tuple(Dist(d) for d in prefix_data.iter_records())
specs_from_history_map = History(self.prefix).get_requested_specs_map()
if prune: # or deps_modifier == DepsModifier.UPDATE_ALL # pending conda/constructor#138
# Users are struggling with the prune functionality in --update-all, due to
# https://github.com/conda/constructor/issues/138. Until that issue is resolved,
# and for the foreseeable future, it's best to be more conservative with --update-all.
# Start with empty specs map for UPDATE_ALL because we're optimizing the update
# only for specs the user has requested; it's ok to remove dependencies.
specs_map = odict()
# However, because of https://github.com/conda/constructor/issues/138, we need
# to hard-code keeping conda, conda-build, and anaconda, if they're already in
# the environment.
solution_pkg_names = set(d.name for d in solution)
ensure_these = (pkg_name for pkg_name in {
self.prefix_record = PrefixRecord.from_objects(
self.package_info.repodata_record,
self.package_info.index_json_record,
self.package_info.package_metadata,
requested_spec=text_type(self.requested_spec),
paths_data=paths_data,
files=files,
link=link,
url=self.package_info.url,
extracted_package_dir=extracted_package_dir,
package_tarball_full_path=package_tarball_full_path,
)
log.trace("creating linked package record %s", self.target_full_path)
PrefixData(self.target_prefix).insert(self.prefix_record)