コード例 #1
0
ファイル: env_tools.py プロジェクト: zx616/OpenFermion-Cirq
def prepare_temporary_test_environment(
    destination_directory: str,
    repository: GithubRepository,
    pull_request_number: Optional[int],
    verbose: bool,
    env_name: str = '.test_virtualenv',
    python_path: str = '/usr/bin/python3.5',
    commit_ids_known_callback: Callable[[PreparedEnv], None] = None
) -> PreparedEnv:
    """Prepares a temporary test environment at the (existing empty) directory.

    Args:
        destination_directory: The location to put files. The caller is
            responsible for deleting the directory, whether or not this method
             succeeds or fails.
        repository: The github repository to download content from, if a pull
            request number is given.
        pull_request_number: If set, test content is fetched from github.
            Otherwise copies of local files are used.
        verbose: When set, more progress output is produced.
        env_name: The name to use for the virtual environment.
        python_path: Location of the python binary to use within the
            virtual environment.
        commit_ids_known_callback: A function to call when the actual commit id
            being tested is known, before the virtual environment is ready.

    Returns:
        Commit ids corresponding to content to test/compare.
    """
    # Fetch content.
    if pull_request_number is not None:
        env = git_env_tools.fetch_github_pull_request(
            destination_directory=destination_directory,
            repository=repository,
            pull_request_number=pull_request_number,
            verbose=verbose)
    else:
        env = git_env_tools.fetch_local_files(
            destination_directory=destination_directory, verbose=verbose)

    if commit_ids_known_callback is not None:
        commit_ids_known_callback(env)

    # Create virtual environment.
    base_path = cast(str, env.destination_directory)
    env_path = os.path.join(base_path, env_name)
    req_path = os.path.join(base_path, 'requirements.txt')
    req_path_2 = os.path.join(base_path, 'dev_tools', 'conf',
                              'pip-list-dev-tools.txt')
    create_virtual_env(venv_path=env_path,
                       python_path=python_path,
                       requirements_paths=[req_path, req_path_2],
                       verbose=verbose)

    return PreparedEnv(github_repo=env.repository,
                       actual_commit_id=env.actual_commit_id,
                       compare_commit_id=env.compare_commit_id,
                       destination_directory=env.destination_directory,
                       virtual_env_path=env_path)
コード例 #2
0
ファイル: env_tools.py プロジェクト: google2013/Cirq
def prepare_temporary_test_environment(
        destination_directory: str,
        repository: GithubRepository,
        pull_request_number: Optional[int],
        verbose: bool,
        env_name: str = '.test_virtualenv',
        python_path: str = '/usr/bin/python3.5',
        commit_ids_known_callback: Callable[[PreparedEnv], None] = None
) -> PreparedEnv:
    """Prepares a temporary test environment at the (existing empty) directory.

    Args:
        destination_directory: The location to put files. The caller is
            responsible for deleting the directory, whether or not this method
             succeeds or fails.
        repository: The github repository to download content from, if a pull
            request number is given.
        pull_request_number: If set, test content is fetched from github.
            Otherwise copies of local files are used.
        verbose: When set, more progress output is produced.
        env_name: The name to use for the virtual environment.
        python_path: Location of the python binary to use within the
            virtual environment.
        commit_ids_known_callback: A function to call when the actual commit id
            being tested is known, before the virtual environment is ready.

    Returns:
        Commit ids corresponding to content to test/compare.
    """
    # Fetch content.
    if pull_request_number is not None:
        env = git_env_tools.fetch_github_pull_request(
            destination_directory=destination_directory,
            repository=repository,
            pull_request_number=pull_request_number,
            verbose=verbose)
    else:
        env = git_env_tools.fetch_local_files(
            destination_directory=destination_directory,
            verbose=verbose)

    if commit_ids_known_callback is not None:
        commit_ids_known_callback(env)

    # Create virtual environment.
    base_path = cast(str, env.destination_directory)
    env_path = os.path.join(base_path, env_name)
    req_path = os.path.join(base_path, 'dev-requirements.txt')
    create_virtual_env(venv_path=env_path,
                       python_path=python_path,
                       requirements_path=req_path,
                       verbose=verbose)

    return PreparedEnv(github_repo=env.repository,
                       actual_commit_id=env.actual_commit_id,
                       compare_commit_id=env.compare_commit_id,
                       destination_directory=env.destination_directory,
                       virtual_env_path=env_path)