Skip to content

Commit

Permalink
Merge pull request conda#9877 from kalefranz/fix-ppc64le-order
Browse files Browse the repository at this point in the history
fix linux-ppc64 for linux-ppc64le subdir recognition
  • Loading branch information
kalefranz authored Apr 27, 2020
2 parents 682d623 + a8ae23b commit 13dac97
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion conda/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
ERROR_UPLOAD_URL = 'https://conda.io/conda-post/unexpected-error'
DEFAULTS_CHANNEL_NAME = 'defaults'

PLATFORM_DIRECTORIES = (
KNOWN_SUBDIRS = PLATFORM_DIRECTORIES = (
"noarch",
"linux-32",
"linux-64",
Expand Down
4 changes: 2 additions & 2 deletions conda/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .constants import (APP_NAME, ChannelPriority, DEFAULTS_CHANNEL_NAME, REPODATA_FN,
DEFAULT_AGGRESSIVE_UPDATE_PACKAGES, DEFAULT_CHANNELS,
DEFAULT_CHANNEL_ALIAS, DEFAULT_CUSTOM_CHANNELS, DepsModifier,
ERROR_UPLOAD_URL, PLATFORM_DIRECTORIES, PREFIX_MAGIC_FILE, PathConflict,
ERROR_UPLOAD_URL, KNOWN_SUBDIRS, PREFIX_MAGIC_FILE, PathConflict,
ROOT_ENV_NAME, SEARCH_PATH, SafetyChecks, SatSolverChoice, UpdateModifier)
from .. import __version__ as CONDA_VERSION
from .._vendor.appdirs import user_data_dir
Expand Down Expand Up @@ -469,7 +469,7 @@ def subdirs(self):

@memoizedproperty
def known_subdirs(self):
return frozenset(concatv(PLATFORM_DIRECTORIES, self.subdirs))
return frozenset(concatv(KNOWN_SUBDIRS, self.subdirs))

@property
def bits(self):
Expand Down
21 changes: 13 additions & 8 deletions conda/common/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,27 @@ def split_anaconda_token(url):
return cleaned_url.rstrip('/'), token


def split_platform(url, known_subdirs):
def split_platform(known_subdirs, url):
"""
Examples:
>>> from conda.base.constants import PLATFORM_DIRECTORIES
>>> split_platform("https://1.2.3.4/t/tk-123/osx-64/path", PLATFORM_DIRECTORIES)
(u'https://1.2.3.4/t/tk-123/path', u'osx-64')
>>> from conda.base.constants import KNOWN_SUBDIRS
>>> split_platform(KNOWN_SUBDIRS, "https://1.2.3.4/t/tk-123/linux-ppc64le/path")
(u'https://1.2.3.4/t/tk-123/path', u'linux-ppc64le')
"""
_platform_match_regex = r'/(%s)/?' % r'|'.join(r'%s' % d for d in known_subdirs)
_platform_match = re.search(_platform_match_regex, url, re.IGNORECASE)
_platform_match = _split_platform_re(known_subdirs).search(url)
platform = _platform_match.groups()[0] if _platform_match else None
cleaned_url = url.replace('/' + platform, '', 1) if platform is not None else url
return cleaned_url.rstrip('/'), platform


@memoize
def _split_platform_re(known_subdirs):
_platform_match_regex = r'/(%s)(?:/|$)' % r'|'.join(r'%s' % d for d in known_subdirs)
return re.compile(_platform_match_regex, re.IGNORECASE)


def has_platform(url, known_subdirs):
url_no_package_name, _ = split_filename(url)
if not url_no_package_name:
Expand All @@ -315,10 +320,10 @@ def split_scheme_auth_token(url):
return remainder_url, url_parts.scheme, url_parts.auth, token


def split_conda_url_easy_parts(url, known_subdirs):
def split_conda_url_easy_parts(known_subdirs, url):
# scheme, auth, token, platform, package_filename, host, port, path, query
cleaned_url, token = split_anaconda_token(url)
cleaned_url, platform = split_platform(cleaned_url, known_subdirs)
cleaned_url, platform = split_platform(known_subdirs, cleaned_url)
_, ext = strip_pkg_extension(cleaned_url)
cleaned_url, package_filename = cleaned_url.rsplit('/', 1) if ext else (cleaned_url, None)

Expand Down
6 changes: 3 additions & 3 deletions conda/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def from_value(value):
else:
# at this point assume we don't have a bare (non-scheme) url
# e.g. this would be bad: repo.anaconda.com/pkgs/free
_stripped, platform = split_platform(value, context.known_subdirs)
_stripped, platform = split_platform(context.known_subdirs, value)
if _stripped in context.custom_multichannels:
return MultiChannel(_stripped, context.custom_multichannels[_stripped], platform)
else:
Expand Down Expand Up @@ -364,7 +364,7 @@ def _get_channel_for_name_helper(name):
return None
return _get_channel_for_name_helper(test_name)

_stripped, platform = split_platform(channel_name, context.known_subdirs)
_stripped, platform = split_platform(context.known_subdirs, channel_name)
channel = _get_channel_for_name_helper(_stripped)

if channel is not None:
Expand Down Expand Up @@ -447,7 +447,7 @@ def _read_channel_configuration(scheme, host, port, path):

def parse_conda_channel_url(url):
(scheme, auth, token, platform, package_filename,
host, port, path, query) = split_conda_url_easy_parts(url, context.known_subdirs)
host, port, path, query) = split_conda_url_easy_parts(context.known_subdirs, url)

# recombine host, port, path to get a channel_name and channel_location
(channel_location, channel_name, configured_scheme, configured_auth,
Expand Down
23 changes: 23 additions & 0 deletions tests/models/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,26 @@ def test_multichannel_priority():
('https://conda.anaconda.org/conda-forge/linux-32', ('conda-forge', 3)),
('https://conda.anaconda.org/conda-forge/noarch', ('conda-forge', 3)),
])


def test_ppc64le_vs_ppc64():
Channel._cache_.clear()

ppc64_channel = Channel("https://conda.anaconda.org/dummy-channel/linux-ppc64")
assert ppc64_channel.subdir == "linux-ppc64"
assert ppc64_channel.url(with_credentials=True) == "https://conda.anaconda.org/dummy-channel/linux-ppc64"

ppc64le_channel = Channel("https://conda.anaconda.org/dummy-channel/linux-ppc64le")
assert ppc64le_channel.subdir == "linux-ppc64le"
assert ppc64le_channel.url(with_credentials=True) == "https://conda.anaconda.org/dummy-channel/linux-ppc64le"
print(Channel._cache_)
Channel._cache_.clear()

ppc64le_channel = Channel("https://conda.anaconda.org/dummy-channel/linux-ppc64le")
assert ppc64le_channel.subdir == "linux-ppc64le"
assert ppc64le_channel.url(with_credentials=True) == "https://conda.anaconda.org/dummy-channel/linux-ppc64le"

ppc64_channel = Channel("https://conda.anaconda.org/dummy-channel/linux-ppc64")
assert ppc64_channel.subdir == "linux-ppc64"
assert ppc64_channel.url(with_credentials=True) == "https://conda.anaconda.org/dummy-channel/linux-ppc64"

4 changes: 3 additions & 1 deletion tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,9 @@ def test_conda_pip_interop_conda_editable_package(self):
assert package_is_installed(prefix, "urllib3>=1.21")
assert not stderr
json_obj = json_loads(stdout)
unlink_dists = json_obj["actions"]["UNLINK"]
unlink_dists = [
dist_obj for dist_obj in json_obj["actions"]["UNLINK"] if dist_obj.get("platform") == "pypi"
] # filter out conda package upgrades like python and libffi
assert len(unlink_dists) == 1
assert unlink_dists[0]["name"] == "urllib3"
assert unlink_dists[0]["channel"] == "pypi"
Expand Down

0 comments on commit 13dac97

Please sign in to comment.