Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalefranz committed Jan 20, 2017
2 parents 949d5a9 + 4f56a09 commit d9e4e20
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 32 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
* general support for all bourne- and c-based shells #3175


## 4.3.7 (2017-01-20)

### Bug Fixes
* actually revert json output for leaky plan (#4383)
* fix not raising on pre/post-link error (#4382)
* fix find_commands and find_executable for symlinks (#4387)


## 4.3.6 (2017-01-18)

### Bug Fixes
Expand Down Expand Up @@ -247,7 +255,7 @@
* context-dependent setup.py files (#4057)


## 4.2.16 (unreleased)
## 4.2.16 (2017-01-20)

### Improvements
* vendor url parsing from urllib3 (#4289)
Expand All @@ -258,6 +266,7 @@
* include aliases for first command-line argument (#4279)
* fix for multi-line FTP status codes (#4276)
* fix errors with unknown type channels (#4291)
* change sys.exit to raise UpgradeError when info/files not found (#4388)

### Non-User-Facing Changes
* start using doctests in test runs and coverage (#4304)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

.. image:: https://img.shields.io/codecov/c/github/conda/conda/4.3.x.svg?label=coverage
:alt: Codecov Status
:target: https://codecov.io/github/conda/conda?branch=master
:target: https://codecov.io/gh/conda/conda/branch/4.3.x

.. image:: https://img.shields.io/github/release/conda/conda.svg
:alt: latest release version
Expand Down
9 changes: 5 additions & 4 deletions conda/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,11 @@ def stdout_json_success(success=True, **kwargs):

# this code reverts json output for plan back to previous behavior
# relied on by Anaconda Navigator and nb_conda
if 'LINK' in kwargs:
kwargs['LINK'] = [str(d) for d in kwargs['LINK']]
if 'UNLINK' in kwargs:
kwargs['UNLINK'] = [str(d) for d in kwargs['UNLINK']]
actions = kwargs.get('actions', {})
if 'LINK' in actions:
actions['LINK'] = [str(d) for d in actions['LINK']]
if 'UNLINK' in actions:
actions['UNLINK'] = [str(d) for d in actions['UNLINK']]

result.update(kwargs)
stdout_json(result)
Expand Down
30 changes: 19 additions & 11 deletions conda/cli/find_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
import os
import re
import sys
from os.path import isdir, isfile, join, expanduser

import sysconfig
from ..common.compat import on_win
from ..utils import memoized
from os.path import isdir, isfile, join, expanduser, basename

from ..utils import memoized, sys_prefix_unfollowed

def find_executable(executable, include_others=True):
# backwards compatibility
global dir_paths

if include_others:
prefixes = [sys_prefix_unfollowed()]
if sys.prefix != prefixes[0]:
prefixes.append(sys.prefix)
dir_paths = [join(p, basename(sysconfig.get_path('scripts')))
for p in prefixes]
# Is this still needed?
if on_win:
dir_paths = [join(sys.prefix, 'Scripts'),
'C:\\cygwin\\bin']
else:
dir_paths = [join(sys.prefix, 'bin')]
dir_paths.append('C:\\cygwin\\bin')
else:
dir_paths = []

Expand All @@ -37,12 +41,16 @@ def find_executable(executable, include_others=True):

@memoized
def find_commands(include_others=True):

if include_others:
prefixes = [sys_prefix_unfollowed()]
if sys.prefix != prefixes[0]:
prefixes.append(sys.prefix)
dir_paths = [join(p, basename(sysconfig.get_path('scripts')))
for p in prefixes]
# Is this still needed?
if on_win:
dir_paths = [join(sys.prefix, 'Scripts'),
'C:\\cygwin\\bin']
else:
dir_paths = [join(sys.prefix, 'bin')]
dir_paths.append('C:\\cygwin\\bin')
else:
dir_paths = []

Expand Down
31 changes: 19 additions & 12 deletions conda/core/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
get_major_minor_version,
get_python_site_packages_short_path)
from ..exceptions import (KnownPackageClobberError, SharedLinkPathClobberError,
UnknownPackageClobberError, maybe_raise)
UnknownPackageClobberError, maybe_raise, LinkError)
from ..gateways.disk.delete import rm_rf
from ..gateways.disk.read import isfile, lexists, read_package_info
from ..gateways.disk.test import hardlink_supported, softlink_supported
Expand Down Expand Up @@ -463,24 +463,31 @@ def run_script(prefix, dist, action='post-link', env_prefix=None):
try:
log.debug("for %s at %s, executing script: $ %s",
dist, env['PREFIX'], ' '.join(command_args))
return _run_script(command_args, env)
finally:
messages(prefix)


def _run_script(command_args, env):
try:
check_call(command_args, env={str(k): str(v) for k, v in iteritems(env)})
except CalledProcessError:
m = messages(prefix)
if action in ('pre-link', 'post-link'):
if m:
raise LinkError("Error: %s failed for: %s\n%s" % (action, dist, m))
else:
raise LinkError("Error: %s failed for: %s" % (action, dist))
else:
return False
except:
messages(prefix)
return False
else:
messages(prefix)
return True


def messages(prefix):
path = join(prefix, '.messages.txt')
if isfile(path):
with open(path) as fi:
fh = sys.stderr if context.json else sys.stdout
fh.write(fi.read())
try:
if isfile(path):
with open(path) as fi:
m = fi.read()
print(m, file=sys.stderr if context.json else sys.stdout)
return m
finally:
rm_rf(path)
6 changes: 6 additions & 0 deletions conda/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ def __init__(self, message):
super(CondaVerificationError, self).__init__(message)


class CondaUpgradeError(CondaError):
def __init__(self, message):
msg = "Conda upgrade error: %s" % message
super(CondaUpgradeError, self).__init__(msg)


def print_conda_exception(exception):
from conda.base.context import context

Expand Down
27 changes: 25 additions & 2 deletions conda/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import collections
from functools import partial
import hashlib
import logging
from os.path import dirname
import re
import sys
import threading
from functools import partial
from textwrap import dedent
import threading

from .common.compat import on_win
from .common.url import path_to_url
Expand Down Expand Up @@ -444,3 +445,25 @@ def human_bytes(n):

# put back because of conda build
urlpath = url_path = path_to_url


@memoized
def sys_prefix_unfollowed():
"""Since conda is installed into non-root environments as a symlink only
and because sys.prefix follows symlinks, this function can be used to
get the 'unfollowed' sys.prefix.
This value is usually the same as the prefix of the environment into
which conda has been symlinked. An example of when this is necessary
is when conda looks for external sub-commands in find_commands.py
"""
try:
frame = sys._current_frames().values()[0]
while frame.f_back:
frame = frame.f_back
code = frame.f_code
filename = code.co_filename
unfollowed = dirname(dirname(filename))
except:
return sys.prefix
return unfollowed
2 changes: 1 addition & 1 deletion tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ def test_transactional_rollback_upgrade_downgrade(self):
@pytest.mark.skipif(on_win, reason="openssl only has a postlink script on unix")
def test_run_script_called(self):
import conda.core.link
with patch.object(conda.core.link, '_run_script') as rs:
with patch.object(conda.core.link, 'check_call') as rs:
with make_temp_env("openssl=1.0.2j --no-deps") as prefix:
assert_package_is_installed(prefix, 'openssl-')
assert rs.call_count == 1
Expand Down

0 comments on commit d9e4e20

Please sign in to comment.