How to use pythonfinder - 10 common examples

To help you get started, we’ve selected a few pythonfinder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_shims_are_removed(monkeypatch, setup_pythons):
    with monkeypatch.context() as m:
        pyenv_dir = pythonfinder.utils.normalize_path("./.pyenv")
        asdf_dir = pythonfinder.utils.normalize_path("./.asdf")
        six.moves.reload_module(pythonfinder.environment)
        six.moves.reload_module(pythonfinder.models.path)
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
                iter(
                    p
                    for p in os_path
                    if pythonfinder.utils.is_in_path(p, os.environ["VIRTUAL_ENV"])
                ),
                None,
            )
            if env_path is not None:
                os_path.remove(env_path)
                os.environ["PATH"] = os.pathsep.join(os_path)
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_shims_are_kept(monkeypatch, setup_pythons):
    with monkeypatch.context() as m:
        pyenv_dir = pythonfinder.utils.normalize_path("./.pyenv")
        asdf_dir = pythonfinder.utils.normalize_path("./.asdf")
        m.delenv("PYENV_ROOT")
        m.delenv("ASDF_DATA_DIR")
        six.moves.reload_module(pythonfinder.environment)
        six.moves.reload_module(pythonfinder.models.path)
        m.setattr(pythonfinder.environment, "PYENV_INSTALLED", False)
        m.setattr(pythonfinder.environment, "ASDF_INSTALLED", False)
        m.setattr(pythonfinder.environment, "PYENV_ROOT", pyenv_dir)
        m.setattr(pythonfinder.environment, "ASDF_DATA_DIR", asdf_dir)
        m.setattr(
            pythonfinder.environment,
            "SHIM_PATHS",
            pythonfinder.environment.get_shim_paths(),
        )
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_shims_are_kept(monkeypatch, setup_pythons):
    with monkeypatch.context() as m:
        pyenv_dir = pythonfinder.utils.normalize_path("./.pyenv")
        asdf_dir = pythonfinder.utils.normalize_path("./.asdf")
        m.delenv("PYENV_ROOT")
        m.delenv("ASDF_DATA_DIR")
        six.moves.reload_module(pythonfinder.environment)
        six.moves.reload_module(pythonfinder.models.path)
        m.setattr(pythonfinder.environment, "PYENV_INSTALLED", False)
        m.setattr(pythonfinder.environment, "ASDF_INSTALLED", False)
        m.setattr(pythonfinder.environment, "PYENV_ROOT", pyenv_dir)
        m.setattr(pythonfinder.environment, "ASDF_DATA_DIR", asdf_dir)
        m.setattr(
            pythonfinder.environment,
            "SHIM_PATHS",
            pythonfinder.environment.get_shim_paths(),
        )
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_shims_are_removed(monkeypatch, setup_pythons):
    with monkeypatch.context() as m:
        pyenv_dir = pythonfinder.utils.normalize_path("./.pyenv")
        asdf_dir = pythonfinder.utils.normalize_path("./.asdf")
        six.moves.reload_module(pythonfinder.environment)
        six.moves.reload_module(pythonfinder.models.path)
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
                iter(
                    p
                    for p in os_path
                    if pythonfinder.utils.is_in_path(p, os.environ["VIRTUAL_ENV"])
                ),
                None,
            )
            if env_path is not None:
                os_path.remove(env_path)
                os.environ["PATH"] = os.pathsep.join(os_path)
            del os.environ["VIRTUAL_ENV"]
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_shims_are_kept(monkeypatch, setup_pythons):
    with monkeypatch.context() as m:
        pyenv_dir = pythonfinder.utils.normalize_path("./.pyenv")
        asdf_dir = pythonfinder.utils.normalize_path("./.asdf")
        m.delenv("PYENV_ROOT")
        m.delenv("ASDF_DATA_DIR")
        six.moves.reload_module(pythonfinder.environment)
        six.moves.reload_module(pythonfinder.models.path)
        m.setattr(pythonfinder.environment, "PYENV_INSTALLED", False)
        m.setattr(pythonfinder.environment, "ASDF_INSTALLED", False)
        m.setattr(pythonfinder.environment, "PYENV_ROOT", pyenv_dir)
        m.setattr(pythonfinder.environment, "ASDF_DATA_DIR", asdf_dir)
        m.setattr(
            pythonfinder.environment,
            "SHIM_PATHS",
            pythonfinder.environment.get_shim_paths(),
        )
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
                iter(
                    [
                        p
                        for p in os_path
                        if pythonfinder.utils.is_in_path(p, os.environ["VIRTUAL_ENV"])
                    ]
                ),
                None,
            )
            if env_path is not None:
                os_path.remove(env_path)
                os.environ["PATH"] = os.pathsep.join(os_path)
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_shims_are_removed(monkeypatch, setup_pythons):
    with monkeypatch.context() as m:
        pyenv_dir = pythonfinder.utils.normalize_path("./.pyenv")
        asdf_dir = pythonfinder.utils.normalize_path("./.asdf")
        six.moves.reload_module(pythonfinder.environment)
        six.moves.reload_module(pythonfinder.models.path)
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
                iter(
                    p
                    for p in os_path
                    if pythonfinder.utils.is_in_path(p, os.environ["VIRTUAL_ENV"])
                ),
                None,
            )
            if env_path is not None:
                os_path.remove(env_path)
                os.environ["PATH"] = os.pathsep.join(os_path)
            del os.environ["VIRTUAL_ENV"]
        m.setattr(
            pythonfinder.environment,
            "SHIM_PATHS",
            pythonfinder.environment.get_shim_paths(),
        )
        f = pythonfinder.pythonfinder.Finder(
            global_search=True, system=False, ignore_unsupported=True
        )
        f.rehash()
github sarugaku / pythonfinder / tests / test_python.py View on Github external
m.setattr(pythonfinder.environment, "ASDF_INSTALLED", False)
        m.setattr(pythonfinder.environment, "PYENV_ROOT", pyenv_dir)
        m.setattr(pythonfinder.environment, "ASDF_DATA_DIR", asdf_dir)
        m.setattr(
            pythonfinder.environment,
            "SHIM_PATHS",
            pythonfinder.environment.get_shim_paths(),
        )
        if "VIRTUAL_ENV" in os.environ:
            os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
                iter(
                    [
                        p
                        for p in os_path
                        if pythonfinder.utils.is_in_path(p, os.environ["VIRTUAL_ENV"])
                    ]
                ),
                None,
            )
            if env_path is not None:
                os_path.remove(env_path)
                os.environ["PATH"] = os.pathsep.join(os_path)
            del os.environ["VIRTUAL_ENV"]
        f = pythonfinder.pythonfinder.Finder(
            global_search=True, system=False, ignore_unsupported=True
        )
        f.rehash()
        assert pythonfinder.environment.get_shim_paths() == []
        assert os.path.join(pyenv_dir, "shims") in os.environ["PATH"]
        assert not f.system_path.finders
        assert os.path.join(pyenv_dir, "shims") in f.system_path.path_order
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_python_versions(monkeypatch, special_character_python):
    def mock_version(*args, **kwargs):
        version_output = "2.7.15+ (default, Jun 28 2018, 13:15:42)\n[GCC 7.2.0]"

        class FakeObj(object):
            def __init__(self, out):
                self.out = out

        c = FakeObj(version_output.split()[0])
        return c

    os.environ["PYTHONFINDER_IGNORE_UNSUPPORTED"] = str("1")
    with monkeypatch.context() as m:
        m.setattr("vistir.misc.run", mock_version)
        parsed = pythonfinder.models.python.PythonVersion.from_path(
            special_character_python.strpath
        )
        assert isinstance(parsed.version, Version)
github sarugaku / pythonfinder / tests / test_python.py View on Github external
def test_python_version_output_variants(monkeypatch, path, version_output, version):
    def mock_version(*args, **kwargs):
        class FakeObj(object):
            def __init__(self, out):
                self.out = out

        c = FakeObj(version_output.split()[0])
        return c

    with monkeypatch.context() as m:
        os.environ["PYTHONFINDER_IGNORE_UNSUPPORTED"] = str("1")
        m.setattr("vistir.misc.run", mock_version)
        parsed = pythonfinder.models.python.PythonVersion.from_path(path)
        assert isinstance(parsed.version, Version)
github sarugaku / pythonfinder / tests / test_python.py View on Github external
os_path = os.environ["PATH"].split(os.pathsep)
            env_path = next(
                iter(
                    [
                        p
                        for p in os_path
                        if pythonfinder.utils.is_in_path(p, os.environ["VIRTUAL_ENV"])
                    ]
                ),
                None,
            )
            if env_path is not None:
                os_path.remove(env_path)
                os.environ["PATH"] = os.pathsep.join(os_path)
            del os.environ["VIRTUAL_ENV"]
        f = pythonfinder.pythonfinder.Finder(
            global_search=True, system=False, ignore_unsupported=True
        )
        f.rehash()
        assert pythonfinder.environment.get_shim_paths() == []
        assert os.path.join(pyenv_dir, "shims") in os.environ["PATH"]
        assert not f.system_path.finders
        assert os.path.join(pyenv_dir, "shims") in f.system_path.path_order
        python_versions = f.find_all_python_versions()
        anaconda = f.find_python_version("anaconda3-5.3.0")
        assert anaconda is not None, python_versions
        assert "shims" in anaconda.path.as_posix(), [
            f.system_path.path_order,
            f.system_path.pyenv_finder.roots,
        ]
        assert "shims" in f.which("anaconda3-5.3.0").path.as_posix()