Exemplo n.º 1
0
Arquivo: common.py Projeto: abn/pipx
def package_name_from_spec(package_spec: str, python: str, *,
                           pip_args: List[str], verbose: bool) -> str:
    start_time = time.time()

    # shortcut if valid PyPI name
    pypi_name = valid_pypi_name(package_spec)
    if pypi_name is not None:
        # NOTE: if pypi name and installed package name differ, this means pipx
        #       will use the pypi name
        package_name = pypi_name
        logging.info(f"Determined package name: {package_name}")
        logging.info(
            f"Package name determined in {time.time()-start_time:.1f}s")
        return package_name

    # check syntax and clean up spec and pip_args
    (package_spec,
     pip_args) = parse_specifier_for_install(package_spec, pip_args)

    with tempfile.TemporaryDirectory() as temp_venv_dir:
        venv = Venv(Path(temp_venv_dir), python=python, verbose=verbose)
        venv.create_venv(venv_args=[], pip_args=[])
        package_name = venv.install_package_no_deps(
            package_or_url=package_spec, pip_args=pip_args)

    logging.info(f"Package name determined in {time.time()-start_time:.1f}s")
    return package_name
Exemplo n.º 2
0
def test_valid_pypi_name(package_spec_in, package_name_out):
    assert valid_pypi_name(package_spec_in) == package_name_out