diff --git a/conda/core/index.py b/conda/core/index.py index a6c81504330..25dc634b7ea 100644 --- a/conda/core/index.py +++ b/conda/core/index.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function, unicode_literals import os +import re from itertools import chain from logging import getLogger import platform @@ -172,11 +173,17 @@ def _supplement_index_with_system(index): libc_family, libc_version = context.libc_family_version is_linux = context.subdir.startswith("linux-") if is_linux: + # By convention, the kernel release string should be three or four + # numeric components, separated by dots, followed by vendor-specific + # bits. For the purposes of versioning the `__linux` virtual package, + # discard everything after the last digit of the third or fourth + # numeric component; note that this breaks version ordering for + # development (`-rcN`) kernels, but we'll deal with that later. dist_version = os.environ.get('CONDA_OVERRIDE_LINUX', context.platform_system_release[1]) - if '-' in dist_version: - dist_version = dist_version.split('-')[0] - rec = _make_virtual_package('__linux', dist_version) + m = re.match(r'\d+\.\d+(\.\d+)?(\.\d+)?', dist_version) + rec = _make_virtual_package('__linux', m.group() if m else "0") index[rec] = rec + if not (libc_family and libc_version): # Default to glibc when using CONDA_SUBDIR var libc_family = "glibc" diff --git a/tests/core/test_index.py b/tests/core/test_index.py index 81b4d2d4d32..465ac3f568e 100644 --- a/tests/core/test_index.py +++ b/tests/core/test_index.py @@ -66,25 +66,25 @@ def test_supplement_index_with_system_osx(): @pytest.mark.skipif(not on_linux, reason="linux-only test") -def test_supplement_index_with_system_linux(): - index = {} - with env_vars({'CONDA_OVERRIDE_LINUX': '4.2.0'}): - _supplement_index_with_system(index) - - linux_pkg = next(iter(_ for _ in index if _.name == '__linux')) - assert linux_pkg.version == '4.2.0' - assert linux_pkg.package_type == PackageType.VIRTUAL_SYSTEM - - -@pytest.mark.skipif(not on_linux, reason="linux-only test") -def test_supplement_index_with_system_linux_extended(): - index = {} - with env_vars({'CONDA_OVERRIDE_LINUX': '4.2.0-42-generic'}): - _supplement_index_with_system(index) +@pytest.mark.parametrize("release_str,version", [ + ("1.2.3.4", "1.2.3.4"), # old numbering system + ("4.2", "4.2"), + ("4.2.1", "4.2.1"), + ("4.2.0-42-generic", "4.2.0"), + ("5.4.89+", "5.4.89"), + ("5.5-rc1", "5.5"), + ("9.1.a", "9.1"), # should probably be "0" + ("9.1.a.2", "9.1"), # should probably be "0" + ("9.a.1", "0"), + ]) +def test_supplement_index_with_system_linux(release_str, version): + index = {} + with env_vars({'CONDA_OVERRIDE_LINUX': release_str}): + _supplement_index_with_system(index) - linux_pkg = next(iter(_ for _ in index if _.name == '__linux')) - assert linux_pkg.version == '4.2.0' - assert linux_pkg.package_type == PackageType.VIRTUAL_SYSTEM + linux_pkg = next(iter(_ for _ in index if _.name == '__linux')) + assert linux_pkg.version == version + assert linux_pkg.package_type == PackageType.VIRTUAL_SYSTEM @pytest.mark.skipif(on_win or on_mac, reason="linux-only test")