How to use the virtualenv.run.run_via_cli function in virtualenv

To help you get started, we’ve selected a few virtualenv 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 pypa / virtualenv / tests / unit / interpreters / boostrap / test_boostrap_link_via_app_data.py View on Github external
def test_base_bootstrap_link_via_app_data(tmp_path, coverage_env):
    bundle_ver = BUNDLE_SUPPORT[CURRENT.version_release_str]
    create_cmd = [
        str(tmp_path / "env"),
        "--seeder",
        "link-app-data",
        "--download",
        "--pip",
        bundle_ver["pip"].split("-")[1],
        "--setuptools",
        bundle_ver["setuptools"].split("-")[1],
    ]
    result = run_via_cli(create_cmd)
    coverage_env()
    assert result

    # uninstalling pip/setuptools now should leave us with a clean env
    site_package = result.creator.site_packages[0]
    pip = site_package / "pip"
    setuptools = site_package / "setuptools"

    files_post_first_create = list(site_package.iterdir())
    assert pip in files_post_first_create
    assert setuptools in files_post_first_create

    env_exe = result.creator.exe
    for pip_exe in [
        env_exe.with_name("pip{}{}".format(suffix, env_exe.suffix))
        for suffix in (
github pypa / virtualenv / tests / unit / interpreters / create / test_creator.py View on Github external
def _non_success_exit_code(capsys, target):
    with pytest.raises(SystemExit) as context:
        run_via_cli(args=[target])
    assert context.value.code != 0
    out, err = capsys.readouterr()
    assert not out, out
    return err
github pypa / virtualenv / tests / unit / interpreters / boostrap / test_boostrap_link_via_app_data.py View on Github external
"pip",
        "--verbose",
        "--disable-pip-version-check",
        "uninstall",
        "-y",
        "setuptools",
    ]
    assert not subprocess.check_call(remove_cmd)
    assert site_package.exists()

    files_post_first_uninstall = list(site_package.iterdir())
    assert pip in files_post_first_uninstall
    assert setuptools not in files_post_first_uninstall

    # check we can run it again and will work - checks both overwrite and reuse cache
    result = run_via_cli(create_cmd)
    coverage_env()
    assert result
    files_post_second_create = list(site_package.iterdir())
    assert files_post_first_create == files_post_second_create

    assert not subprocess.check_call(remove_cmd + ["pip"])
    # pip is greedy here, removing all packages removes the site-package too
    if site_package.exists():
        post_run = list(site_package.iterdir())
        assert not post_run, "\n".join(str(i) for i in post_run)

    if sys.version_info[0:2] == (3, 4) and "PIP_REQ_TRACKER" in os.environ:
        os.environ.pop("PIP_REQ_TRACKER")
github pypa / virtualenv / tests / unit / interpreters / create / test_creator.py View on Github external
def test_create_clear_resets(tmp_path, use_venv, clear):
    marker = tmp_path / "magic"
    cmd = [str(tmp_path), "--without-pip"]
    if use_venv:
        cmd.extend(["--creator", "venv"])
    run_via_cli(cmd)

    marker.write_text("")  # if we a marker file this should be gone on a clear run, remain otherwise
    assert marker.exists()

    run_via_cli(cmd + (["--clear"] if clear else []))
    assert marker.exists() is not clear
github pypa / virtualenv / tests / unit / interpreters / create / test_creator.py View on Github external
def test_debug_bad_virtualenv(tmp_path):
    cmd = [str(tmp_path), "--without-pip"]
    result = run_via_cli(cmd)
    # if the site.py is removed/altered the debug should fail as no one is around to fix the paths
    site_py = result.creator.lib_dir / "site.py"
    site_py.unlink()
    # insert something that writes something on the stdout
    site_py.write_text('import sys; sys.stdout.write(repr("std-out")); sys.stderr.write("std-err"); raise ValueError')
    debug_info = result.creator.debug
    assert debug_info["returncode"]
    assert debug_info["err"].startswith("std-err")
    assert debug_info["out"] == "'std-out'"
    assert debug_info["exception"]
github pypa / virtualenv / tests / unit / interpreters / create / test_creator.py View on Github external
def test_prompt_set(tmp_path, use_venv, prompt):
    cmd = [str(tmp_path), "--without-pip"]
    if prompt is not None:
        cmd.extend(["--prompt", "magic"])
    if not use_venv:
        cmd.extend(["--creator", "venv"])

    result = run_via_cli(cmd)
    actual_prompt = tmp_path.name if prompt is None else prompt
    cfg = PyEnvCfg.from_file(result.creator.pyenv_cfg.path)
    if prompt is None:
        assert "prompt" not in cfg
    else:
        if use_venv is False:
            assert "prompt" in cfg, list(cfg.content.keys())
            assert cfg["prompt"] == actual_prompt
github pypa / virtualenv / tests / unit / interpreters / create / test_creator.py View on Github external
def test_create_no_seed(python, use_venv, global_access, tmp_path, coverage_env):
    cmd = ["-v", "-v", "-p", str(python), str(tmp_path), "--without-pip", "--activators", ""]
    if global_access:
        cmd.append("--system-site-packages")
    if use_venv:
        cmd.extend(["--creator", "venv"])
    result = run_via_cli(cmd)
    coverage_env()
    for site_package in result.creator.site_packages:
        content = list(site_package.iterdir())
        assert not content, "\n".join(str(i) for i in content)
    assert result.creator.env_name == tmp_path.name
    sys_path = cleanup_sys_path(result.creator.debug["sys"]["path"])
    system_sys_path = cleanup_sys_path(SYSTEM["sys"]["path"])
    our_paths = set(sys_path) - set(system_sys_path)
    our_paths_repr = "\n".join(repr(i) for i in our_paths)

    # ensure we have at least one extra path added
    assert len(our_paths) >= 1, our_paths_repr
    # ensure all additional paths are related to the virtual environment
    for path in our_paths:
        assert str(path).startswith(str(tmp_path)), path
    # ensure there's at least a site-packages folder as part of the virtual environment added
github pypa / virtualenv / tests / unit / interpreters / create / test_creator.py View on Github external
def test_create_clear_resets(tmp_path, use_venv, clear):
    marker = tmp_path / "magic"
    cmd = [str(tmp_path), "--without-pip"]
    if use_venv:
        cmd.extend(["--creator", "venv"])
    run_via_cli(cmd)

    marker.write_text("")  # if we a marker file this should be gone on a clear run, remain otherwise
    assert marker.exists()

    run_via_cli(cmd + (["--clear"] if clear else []))
    assert marker.exists() is not clear