from pathlib import Path
import re


def find_version(*file_paths):
    """
    Find the package version for the given path.

    Taken from https://github.com/pypa/pip/blob/master/setup.py and modified
    to suit my needs/tastes.
    """
    version_file = Path(__file__).parent.joinpath(*file_paths)
    with open(str(version_file), 'r') as openf:
        data = openf.read()
    version_match = re.search(
        r"^__version__ = ['\"]([^'\"]*)['\"]",
        data,
        re.M,
    )
    if version_match:
        return version_match.group(1)

    raise RuntimeError("Unable to find version string.")