def invoke(self) -> None:
        """Invoke the command."""

        development_container = container.DevContainer()

        try:
            development_container.container_valid_exception()
            click.echo(_("This container is valid."))
        except exceptions.DevContainerException:
            click.echo(_("No compatible PIB container found."))
            sys.exit(development_container.incompatible_container_exit_code)
    def invoke(self) -> None:
        """Invoke the command."""

        development_container = container.DevContainer()

        try:
            version_data = development_container.get_container_version()
            click.echo(
                _("Container version: {version_data}").format(
                    version_data=version_data))
        except exceptions.DevContainerException:
            click.echo(_("No PIB container found."))
            sys.exit(development_container.incompatible_container_exit_code)
Exemple #3
0
  def invoke(self) -> None:
    """Invoke the command."""

    version_data = pkg_resources.get_distribution('pib_cli').version
    click.echo(
        _("pib_cli version: {version_data}").format(version_data=version_data),
    )
class DevContainerInstaller(container.DevContainer):
    """Configure a development container with PIB resources."""

    bash_setup_success_message = _("Setup Succeeded!")

    def setup(self, notifier: Callable[[str], None]) -> None:
        """Copy pib_cli assets to the container to configure BASH and Python.

    :param notifier: An event handler to notify the user of progress.
    """

        os.makedirs(self.local_executable_folder, exist_ok=True)

        for file in self.get_installation_files():
            shutil.copy(file.source, file.destination)
            notifier(
                _("Copied: {source} -> {destination}").format(
                    source=file.source, destination=file.destination))

        notifier(self.bash_setup_success_message)

    def get_installation_files(
            self) -> List[file_copy_base.SourceDestinationPair]:
        """Create a list of source / destination file pairs for installation.

    :returns: A list of source / destination file pairs.
    """

        return (list(container_bash_files.ContainerBashFilesIterator()) +
                list(container_shim_file.ContainerShimFileIterator()))
    def invoke(self) -> None:
        """Invoke the command."""

        user_config = self.user_config_file.parse()
        click.echo(
            _("Configuration file: {path}\n"
              "This configuration is valid.").format(
                  name=user_config.get_project_name(),
                  path=self.user_config_file.get_config_file_name(),
              ))
    def invoke(self) -> None:
        """Invoke the command."""

        user_config = self.user_config_file.parse()
        click.echo(
            _("Configuration file: {path}\n"
              "Configuration version: {version}").format(
                  path=self.user_config_file.get_config_file_name(),
                  version=user_config.version,
              ))
Exemple #7
0
  def invoke(self) -> None:
    """Invoke the command."""

    try:
      self.command_configuration.is_executable_exception()
      self._call_runner()
    except exceptions.DevContainerException as exc:
      click.echo(
          _("ERROR: {container_error}").format(container_error=exc.args[0])
      )
      exc.exit()
Exemple #8
0
    def invoke(self) -> None:
        """Invoke the command."""

        try:
            container_installer = installer.DevContainerInstaller()
            container_installer.container_valid_exception()
            container_installer.setup(click.echo)
        except exceptions.DevContainerException as exc:
            click.echo(
                _("ERROR: {container_error}").format(
                    container_error=exc.args[0]))
            exc.exit()
    def setup(self, notifier: Callable[[str], None]) -> None:
        """Copy pib_cli assets to the container to configure BASH and Python.

    :param notifier: An event handler to notify the user of progress.
    """

        os.makedirs(self.local_executable_folder, exist_ok=True)

        for file in self.get_installation_files():
            shutil.copy(file.source, file.destination)
            notifier(
                _("Copied: {source} -> {destination}").format(
                    source=file.source, destination=file.destination))

        notifier(self.bash_setup_success_message)
Exemple #10
0
    def project_root_path(self) -> pathlib.Path:
        """Return the path to the project root."""

        if not self._project_root_path:
            project_relative_path = state.State().\
              user_config.get_project_name()
            project_absolute_path = self.repo_root_path / project_relative_path
            self._path_does_not_exist(
                project_absolute_path,
                _("ERROR: Project not found: {path}"
                  " (config: {key}, env: {env})").format(
                      path=project_absolute_path,
                      key=yaml_keys.V210_CLI_CONFIG_PROJECT_NAME,
                      env=config.ENV_OVERRIDE_PROJECT_NAME,
                  ), config.EXIT_CODE_PROJECT_NAME_ROOT_NOT_FOUND)
            self._project_root_path = project_absolute_path
        return self._project_root_path
Exemple #11
0
    def repo_root_path(self) -> pathlib.Path:
        """Return the path to the repository's root folder."""

        if not self._repo_root_path:
            try:
                root = git.Repo(
                    os.curdir,
                    search_parent_directories=True,
                ).working_tree_dir
                if not root:
                    raise git.InvalidGitRepositoryError
                pathlib.Path(root).absolute()
                self._repo_root_path = pathlib.Path(root).absolute()
            except git.InvalidGitRepositoryError:
                click.echo(_("No git repository not found."))
                sys.exit(config.EXIT_CODE_NOT_A_REPOSITORY)
        return self._repo_root_path
    def parse(self) -> version_base.UserConfigurationVersionBase:
        """Load, validate and detect the version of the UserConfiguration.

    :returns: A class representing the detected version of config.
    :raises: :class:`NotImplementedError`
    """

        configuration_yaml = self.load_yaml_file(self.get_config_file_name())
        configuration_validator = validator.UserConfigurationValidator()
        detected_version = configuration_validator.validate(configuration_yaml)

        for user_configuration in self.supported_versions:
            if detected_version == user_configuration.version:
                return user_configuration(configuration_yaml)

        raise NotImplementedError(
            _("Configuration version {detected_version} is not supported!").
            format(detected_version=detected_version))
Exemple #13
0
    def documentation_root_path(self) -> pathlib.Path:
        """Return the path to the documentation root."""

        if not self._documentation_root_path:
            documentation_relative_path = state.State().\
              user_config.get_documentation_root()
            documentation_absolute_path = (self.repo_root_path /
                                           documentation_relative_path)
            self._path_does_not_exist(
                documentation_absolute_path,
                _("ERROR: Documentation not found: {path} "
                  "(config: {key}, env: {env})").format(
                      path=documentation_absolute_path,
                      key=yaml_keys.V210_CLI_CONFIG_DOCS_FOLDER,
                      env=config.ENV_OVERRIDE_DOCUMENTATION_ROOT,
                  ), config.EXIT_CODE_DOCUMENTATION_ROOT_NOT_FOUND)
            self._documentation_root_path = documentation_absolute_path.absolute(
            )
        return self._documentation_root_path
    def invoke(self) -> None:
        """Invoke the command."""

        click.echo(
            _("Configuration file: {config_filename}").format(
                config_filename=self.user_config_file.get_config_file_name()))
"""Built in CLI configuration commands."""

from typing import Optional

import click
from pib_cli.cli.commands import (
    config_show,
    config_validate,
    config_version,
    config_where,
    handler,
)
from pib_cli.config.locale import _


@click.group(_("config"))
@click.option(
    "-c",
    "--config-file",
    help="A config file to use instead of the active one.",
    type=click.Path(
        exists=True,
        file_okay=True,
        dir_okay=False,
        readable=True,
    ),
    required=False,
)
@click.pass_context
def config(ctx: click.Context, config_file: Optional[str]) -> None:
    """PIB CLI configuration commands."""
"""Built in CLI container commands."""

import click
from pib_cli.cli.commands import (
    container_setup,
    container_validate,
    container_version,
    handler,
)
from pib_cli.config.locale import _


@click.group(_("container"))
def container() -> None:
  """PIB container commands."""


@container.command(_("setup"))
def setup_container_builtin() -> None:
  """Copy file assets to setup the development container."""

  handler(container_setup.ContainerSetupCommand)

@container.command(_("validate"))
def validate_container_builtin() -> None:
  """Validate the current container is compatible with the CLI."""

  handler(container_validate.ContainerValidateCommand)

@container.command(_("version"))
def version_container_builtin() -> None:
from pib_cli.config import yaml_keys
from pib_cli.config.locale import _

PIB_URL = "https://github.com/niall-byrne/python-in-a-box"
PIB_CONFIG_FILE_NAME = ".pib.yml"

DEFAULT_DOCUMENTATION_FOLDER_NAME = "documentation"

ENV_OVERLOAD_ARGUMENTS = 'PIB_OVERLOAD_ARGUMENTS'
ENV_OVERRIDE_CONFIG_LOCATION = "PIB_CONFIG_FILE_LOCATION"
ENV_OVERRIDE_DOCUMENTATION_ROOT = "PIB_DOCUMENTATION_ROOT"
ENV_OVERRIDE_PROJECT_NAME = "PIB_PROJECT_NAME"


ERROR_CONTAINER_ONLY = _(
    "This command can only be run inside a PIB container.\n"
    "Find out more here: {PIB_URL}"
).format(PIB_URL=PIB_URL)

ERROR_CONTAINER_VERSION: Callable[[str], str] = \
    lambda minimum_version: _(
        "This command can only be run inside a PIB container with version "
        "{minimum_version} or greater.\n"
        "Find out more here: {PIB_URL}"
    ).format(minimum_version=minimum_version, PIB_URL=PIB_URL)
ERROR_PROJECT_NAME_NOT_SET = (
    f"You must set the {ENV_OVERRIDE_PROJECT_NAME} variable, or the "
    f"'{yaml_keys.V210_CLI_CONFIG_PROJECT_NAME}' config key "
    "to use this tool."
)

EXIT_CODE_CONTAINER_ONLY = 127
Exemple #18
0
"""Configuration managed CLI commands."""

import copy

import click
from pib_cli.config.locale import _
from pib_cli.support import state
from pib_cli.support.iterators import cli_custom_commands


@click.group(_("configuration_commands"))
def document_custom_commands() -> None:
  """Click group of all custom defined commands."""


def load_custom_commands() -> click.Group:
  """Create and attach the custom commands to the click group.

  :returns: The click group, with all custom commands attached.
  """

  state.State().load()
  for custom_command in cli_custom_commands.CustomClickCommandIterator():
    document_custom_commands.add_command(custom_command)
  return document_custom_commands


# Create a copy of the click group to allow Sphinx to reference the original
custom_commands: click.Group = copy.deepcopy(load_custom_commands())
Exemple #19
0
 def _default_config_warning(self) -> None:
     config_file_in_use = self.user_config_file.get_config_file_name()
     if self.user_config_file.default_config == config_file_in_use:
         click.echo(_("** PIB DEFAULT CONFIG IN USE **"))
"""Built in CLI commands."""

import click
from pib_cli.cli.commands import handler, version
from pib_cli.config.locale import _

from .config import config_commands
from .container import container_commands


@click.group(_("@pib"))
def builtins() -> None:
    """PIB built-in commands."""


@builtins.command(_("version"))
def version_builtin() -> None:
    """Display the current CLI version."""

    handler(version.VersionCommand)


builtin_commands: click.Group = builtins
builtin_commands.add_command(config_commands)
builtin_commands.add_command(container_commands)