Пример #1
0
def commit_files(folder: PurePath):
    """Save staged files to the local repository.

    :param folder: project folder."""
    print("\nCommiting files...")
    try:
        output = helpers.execute_subprocess(
            [
                "git", "commit", "-m", "initial commit", "-m",
                f"by `{consts.PROGRAM}/{consts.VERSION}`"
            ],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        message = "Local commit completed."
        logging.info(message)
        logging.debug(f"Local commit output:\n{output}")
        print(message)
Пример #2
0
def add_origin(folder: PurePath, remote_path: str):
    """Add a remote pointing to GitHub repository.

    :param folder: project repository.
    :param remote_path: remote repository path."""
    remote_repo = f"https://github.com/{remote_path}"
    try:
        helpers.execute_subprocess(
            ["git", "remote", "add", "origin", f"{remote_repo}.git"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        logging.info("Remote repository added.")
Пример #3
0
def build_environment(folder: PurePath, python_version: str):
    """Create Python virtual environment.

    :param folder: project folder.
    :param pytyhon_version: Python version to install."""
    print("\nThis can take a while...")
    try:
        helpers.execute_subprocess(
            ["pipenv", "--python", f"{python_version}"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        message = f"Python {python_version} virtual environment created."
        logging.info(message)
        print(message)
Пример #4
0
def install_linter(folder: PurePath, linter: str):
    """Install linter as a dev package in the current virtual environment.

    :param folder: project folder.
    :param linter: linter to install."""
    print("\nThis can take a while...")
    try:
        helpers.execute_subprocess(
            ["pipenv", "install", linter, "--dev"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        message = f"`{linter}` linter installed."
        logging.info(message)
        print(message)
Пример #5
0
def stage_files(folder: PurePath):
    """Add files in the folder to the stage area.

    :param folder: project folder."""
    print("\nStaging files...")
    try:
        helpers.execute_subprocess(
            ["git", "add", "-A"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        message = ("All not ignored files in project directory have been "
                   "staged.")
        logging.info(message)
        print(message)
Пример #6
0
def initialise_git(folder: PurePath):
    """Initialise local repository.

    :param folder: project folder."""
    print("\nInitialising git...")
    try:
        output = helpers.execute_subprocess(
            ["git", "init"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        message = output.strip()
        logging.info(message)
        print(message)
Пример #7
0
def update_remote(folder: PurePath):
    """Update remote repository.

    :param folder: project folder."""
    print("\nUpdating remote repository...")
    try:
        output = helpers.execute_subprocess(
            ["git", "push", "-u", "origin", "master"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        message = "Push to remote repository completed."
        logging.info(message)
        logging.debug(output)
        print(message)
Пример #8
0
def get_interpreter_path(folder: str) -> str:
    """Get interpreter path inside the virtual environment.

    :param folder: project folder.
    :returns: path to Python interpreter."""
    try:
        output = helpers.execute_subprocess(
            ["pipenv", "--py"],
            folder,
        )

    except (OSError, CalledProcessError) as e:
        error = f"Subprocess error: {e}"
        logging.critical(error)
        print(error)
        print("\nCancelling...")
        exit()

    else:
        interpreter = output.strip()
        logging.debug(f"Interpreter path: `{interpreter}`")

    return interpreter