"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "conda/core/link.py" between
conda-4.6.2.tar.gz and conda-4.6.3.tar.gz

About: Conda is a cross-platform, language-agnostic, system-level binary package manager and ecosystem.

link.py  (conda-4.6.2):link.py  (conda-4.6.3)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Anaconda, Inc # Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
from __future__ import absolute_import, division, print_function, unicode_litera ls from __future__ import absolute_import, division, print_function, unicode_litera ls
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
from logging import getLogger from logging import getLogger
import os import os
from os.path import basename, dirname, isdir, join from os.path import abspath, basename, dirname, isdir, join
from subprocess import CalledProcessError from subprocess import CalledProcessError
import sys import sys
import tempfile
from traceback import format_exception_only from traceback import format_exception_only
import warnings import warnings
from .package_cache_data import PackageCacheData from .package_cache_data import PackageCacheData
from .path_actions import (CompileMultiPycAction, CreateNonadminAction, CreatePr efixRecordAction, from .path_actions import (CompileMultiPycAction, CreateNonadminAction, CreatePr efixRecordAction,
CreatePythonEntryPointAction, LinkPathAction, MakeMen uAction, CreatePythonEntryPointAction, LinkPathAction, MakeMen uAction,
RegisterEnvironmentLocationAction, RemoveLinkedPackag eRecordAction, RegisterEnvironmentLocationAction, RemoveLinkedPackag eRecordAction,
RemoveMenuAction, UnlinkPathAction, UnregisterEnviron mentLocationAction, RemoveMenuAction, UnlinkPathAction, UnregisterEnviron mentLocationAction,
UpdateHistoryAction) UpdateHistoryAction)
from .prefix_data import PrefixData, get_python_version_for_prefix from .prefix_data import PrefixData, get_python_version_for_prefix
skipping to change at line 594 skipping to change at line 595
prec.dist_str(), target_prefix, prec.extracted_package_ dir) prec.dist_str(), target_prefix, prec.extracted_package_ dir)
if axngroup.type in ('unlink', 'link'): if axngroup.type in ('unlink', 'link'):
run_script(target_prefix if is_unlink else prec.extracted_packag e_dir, run_script(target_prefix if is_unlink else prec.extracted_packag e_dir,
prec, prec,
'pre-unlink' if is_unlink else 'pre-link', 'pre-unlink' if is_unlink else 'pre-link',
target_prefix) target_prefix)
for axn_idx, action in enumerate(axngroup.actions): for axn_idx, action in enumerate(axngroup.actions):
action.execute() action.execute()
if axngroup.type in ('unlink', 'link'): if axngroup.type in ('unlink', 'link'):
run_script(target_prefix, prec, 'post-unlink' if is_unlink else run_script(target_prefix, prec, 'post-unlink' if is_unlink else
'post-link') 'post-link',
activate=True)
except Exception as e: # this won't be a multi error except Exception as e: # this won't be a multi error
# reverse this package # reverse this package
log.debug("Error in action #%d for pkg_idx #%d %r", axn_idx, pkg_idx , action, log.debug("Error in action #%d for pkg_idx #%d %r", axn_idx, pkg_idx , action,
exc_info=True) exc_info=True)
reverse_excs = () reverse_excs = ()
if context.rollback_enabled: if context.rollback_enabled:
# log.error("An error occurred while %s package '%s'.\n" # log.error("An error occurred while %s package '%s'.\n"
# "%r\n" # "%r\n"
# "Attempting to roll back.\n", # "Attempting to roll back.\n",
# 'uninstalling' if is_unlink else 'installing', prec. dist_str(), e) # 'uninstalling' if is_unlink else 'installing', prec. dist_str(), e)
skipping to change at line 955 skipping to change at line 957
downgraded_precs[namekey] = (unlink_prec, link_prec) downgraded_precs[namekey] = (unlink_prec, link_prec)
else: else:
superseded_precs[namekey] = (unlink_prec, link_prec) superseded_precs[namekey] = (unlink_prec, link_prec)
fetch_precs = set(prec for prec in link_precs if prec.url in download_ur ls) fetch_precs = set(prec for prec in link_precs if prec.url in download_ur ls)
change_report = ChangeReport(prefix, specs_to_remove, specs_to_add, remo ved_precs, change_report = ChangeReport(prefix, specs_to_remove, specs_to_add, remo ved_precs,
new_precs, updated_precs, downgraded_precs, superseded_precs, new_precs, updated_precs, downgraded_precs, superseded_precs,
fetch_precs) fetch_precs)
return change_report return change_report
def run_script(prefix, prec, action='post-link', env_prefix=None): def run_script(prefix, prec, action='post-link', env_prefix=None, activate=False ):
""" """
call the post-link (or pre-unlink) script, and return True on success, call the post-link (or pre-unlink) script, and return True on success,
False on failure False on failure
""" """
path = join(prefix, path = join(prefix,
'Scripts' if on_win else 'bin', 'Scripts' if on_win else 'bin',
'.%s-%s.%s' % (prec.name, action, 'bat' if on_win else 'sh')) '.%s-%s.%s' % (prec.name, action, 'bat' if on_win else 'sh'))
if not isfile(path): if not isfile(path):
return True return True
skipping to change at line 991 skipping to change at line 993
if not is_old_noarch: if not is_old_noarch:
warnings.warn(dals(""" warnings.warn(dals("""
Package %s uses a pre-link script. Pre-link scripts are potentially dangerous. Package %s uses a pre-link script. Pre-link scripts are potentially dangerous.
This is because pre-link scripts have the ability to change the pack age contents in the This is because pre-link scripts have the ability to change the pack age contents in the
package cache, and therefore modify the underlying files for already -created conda package cache, and therefore modify the underlying files for already -created conda
environments. Future versions of conda may deprecate and ignore pre -link scripts. environments. Future versions of conda may deprecate and ignore pre -link scripts.
""") % prec.dist_str()) """) % prec.dist_str())
if on_win: if on_win:
try: try:
command_args = [os.environ[str('COMSPEC')], '/d', '/c', path] comspec = os.environ[str('COMSPEC')]
except KeyError: except KeyError:
log.info("failed to run %s for %s due to COMSPEC KeyError", action, prec.dist_str()) log.info("failed to run %s for %s due to COMSPEC KeyError", action, prec.dist_str())
return False return False
if activate:
conda_bat = env.get("CONDA_BAT", abspath(join(context.root_prefix, '
bin', 'conda')))
with tempfile.NamedTemporaryFile(
mode='w', prefix=prefix, suffix='.bat', delete=False) as fh:
fh.write('@CALL \"{0}\" activate \"{1}\"\n'.format(conda_bat, pr
efix))
fh.write('echo "PATH: %PATH%\n')
fh.write('@CALL \"{0}\"\n'.format(path))
script_caller = fh.name
command_args = [comspec, '/d', '/c', script_caller]
else:
command_args = [comspec, '/d', '/c', path]
else: else:
shell_path = 'sh' if 'bsd' in sys.platform else 'bash' shell_path = 'sh' if 'bsd' in sys.platform else 'bash'
command_args = [shell_path, "-x", path] if activate:
conda_exe = env.get("CONDA_EXE", abspath(join(context.root_prefix, '
bin', 'conda')))
with tempfile.NamedTemporaryFile(mode='w', prefix=prefix, delete=Fal
se) as fh:
fh.write("eval \"$(\"{0}\" \"shell.posix\" \"hook\")\"\n".format
(conda_exe)),
fh.write("conda activate \"{0}\"\n".format(prefix)),
fh.write("source \"{}\"\n".format(path))
script_caller = fh.name
command_args = [shell_path, "-x", script_caller]
else:
command_args = [shell_path, "-x", path]
script_caller = None
env['ROOT_PREFIX'] = context.root_prefix env['ROOT_PREFIX'] = context.root_prefix
env['PREFIX'] = env_prefix or prefix env['PREFIX'] = env_prefix or prefix
env['PKG_NAME'] = prec.name env['PKG_NAME'] = prec.name
env['PKG_VERSION'] = prec.version env['PKG_VERSION'] = prec.version
env['PKG_BUILDNUM'] = prec.build_number env['PKG_BUILDNUM'] = prec.build_number
env['PATH'] = os.pathsep.join((dirname(path), env.get('PATH', ''))) env['PATH'] = os.pathsep.join((dirname(path), env.get('PATH', '')))
try: try:
log.debug("for %s at %s, executing script: $ %s", log.debug("for %s at %s, executing script: $ %s",
skipping to change at line 1033 skipping to change at line 1057
%s %s
""") % (action, prec.dist_str(), path, m or "<None>") """) % (action, prec.dist_str(), path, m or "<None>")
raise LinkError(message) raise LinkError(message)
else: else:
log.warn("%s script failed for package %s\n" log.warn("%s script failed for package %s\n"
"consider notifying the package maintainer", action, prec.d ist_str()) "consider notifying the package maintainer", action, prec.d ist_str())
return False return False
else: else:
messages(prefix) messages(prefix)
return True return True
finally:
if script_caller is not None:
os.remove(script_caller)
def messages(prefix): def messages(prefix):
path = join(prefix, '.messages.txt') path = join(prefix, '.messages.txt')
try: try:
if isfile(path): if isfile(path):
with open(path) as fi: with open(path) as fi:
m = fi.read() m = fi.read()
print(m, file=sys.stderr if context.json else sys.stdout) print(m, file=sys.stderr if context.json else sys.stdout)
return m return m
finally: finally:
 End of changes. 8 change blocks. 
6 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)