def strip_version_suffixes()

in lib/ramble/spack/url.py [0:0]


def strip_version_suffixes(path):
    """Some tarballs contain extraneous information after the version:

    * ``bowtie2-2.2.5-source``
    * ``libevent-2.0.21-stable``
    * ``cuda_8.0.44_linux.run``

    These strings are not part of the version number and should be ignored.
    This function strips those suffixes off and returns the remaining string.
    The goal is that the version is always the last thing in ``path``:

    * ``bowtie2-2.2.5``
    * ``libevent-2.0.21``
    * ``cuda_8.0.44``

    Args:
        path (str): The filename or URL for the package

    Returns:
        str: The ``path`` with any extraneous suffixes removed
    """
    # NOTE: This could be done with complicated regexes in parse_version_offset
    # NOTE: The problem is that we would have to add these regexes to the end
    # NOTE: of every single version regex. Easier to just strip them off
    # NOTE: permanently

    suffix_regexes = [
        # Download type
        r'[Ii]nstall',
        r'all',
        r'code',
        r'[Ss]ources?',
        r'file',
        r'full',
        r'single',
        r'with[a-zA-Z_-]+',
        r'rock',
        r'src(_0)?',
        r'public',
        r'bin',
        r'binary',
        r'run',
        r'[Uu]niversal',
        r'jar',
        r'complete',
        r'dynamic',
        r'oss',
        r'gem',
        r'tar',
        r'sh',

        # Download version
        r'release',
        r'bin',
        r'stable',
        r'[Ff]inal',
        r'rel',
        r'orig',
        r'dist',
        r'\+',

        # License
        r'gpl',

        # Arch
        # Needs to come before and after OS, appears in both orders
        r'ia32',
        r'intel',
        r'amd64',
        r'linux64',
        r'x64',
        r'64bit',
        r'x86[_-]64',
        r'i586_64',
        r'x86',
        r'i[36]86',
        r'ppc64(le)?',
        r'armv?(7l|6l|64)',

        # Other
        r'cpp',
        r'gtk',
        r'incubating',

        # OS
        r'[Ll]inux(_64)?',
        r'LINUX',
        r'[Uu]ni?x',
        r'[Ss]un[Oo][Ss]',
        r'[Mm]ac[Oo][Ss][Xx]?',
        r'[Oo][Ss][Xx]',
        r'[Dd]arwin(64)?',
        r'[Aa]pple',
        r'[Ww]indows',
        r'[Ww]in(64|32)?',
        r'[Cc]ygwin(64|32)?',
        r'[Mm]ingw',
        r'centos',

        # Arch
        # Needs to come before and after OS, appears in both orders
        r'ia32',
        r'intel',
        r'amd64',
        r'linux64',
        r'x64',
        r'64bit',
        r'x86[_-]64',
        r'i586_64',
        r'x86',
        r'i[36]86',
        r'ppc64(le)?',
        r'armv?(7l|6l|64)?',

        # PyPI
        r'[._-]py[23].*\.whl',
        r'[._-]cp[23].*\.whl',
        r'[._-]win.*\.exe',
    ]

    for regex in suffix_regexes:
        # Remove the suffix from the end of the path
        # This may be done multiple times
        path = re.sub(r'[._-]?' + regex + '$', '', path)

    return path