コード例 #1
0
    def get_command(self, ctx, name):
        """
        MultiCommand classes must implement this function.

        Returns the CLI command w/the given name. The following load order
        is used:
        * Project-specific commands
        * Core commands
        * Core project-specific commands

        If a command is found it is returned immediately. For example, if
        both a custom project-specific command and a core project-specific
        command exist with the same name the custom command is returned,
        overriding the default.
        """
        project = Project()

        if project.in_project():
            fn = os.path.join(self.project_commands_dir(), name + '.py')
            ns = self._eval_file(fn)

            if ns:
                return ns

        fn = os.path.join(self.core_commands_dir(), name + '.py')
        ns = self._eval_file(fn)

        if ns:
            return ns

        fn = os.path.join(self.core_project_commands_dir(), name + '.py')
        ns = self._eval_file(fn)
        return ns
コード例 #2
0
ファイル: setup.py プロジェクト: whisk-ml/whisk
def setup(dir):
    """
    Sets up the project environment.

    Setup performs the following actions after changing the working
    directory to ``dir``:

    * Creates a `Python3 venv <https://docs.python.org/3/library/venv.html />`_
      named "venv"
    * Installs the dependencies listed in the project's requirements.txt.
    * Initializes a Git repo
    * Creates an iPython kernel for use in Jupyter notebooks with
      name = <project_name>.
    * Creates a ``.envrc`` file based on ``.envrc.example`` for use with
      `direnv <https://github.com/direnv/direnv />`_. direnv loads environment
      variables listed in ``.envrc`` into the shell and is also used to
      auto-activate and deactivate the venv when entering and exiting the
      project directory.
    * Calls ``direnv allow .`` so the ``.envrc`` file can be loaded.
    * Makes an initial Git commit

    Parameters
    ----------
    dir : str
        The full path to the project directory.
    """
    project = Project(dir)
    project.validate_in_project()
    with cd(dir):
        logger.debug("cwd={}".format(os.getcwd()))
        exec_setup(project)
    log_success(dir)
    log_pip_freeze()
コード例 #3
0
    def list_commands(self, ctx):
        """
        MultiCommand classes must implement this function.
        This returns a set of file names across all directories.
        """
        project = Project()
        rv = []
        rv = rv + self._command_file_names(self.core_commands_dir())
        if project.in_project():
            rv = rv + self._command_file_names(
                self.core_project_commands_dir())
            # Possible commands directory is deleted in project
            if project.commands_dir.exists():
                rv = rv + self._command_file_names(project.commands_dir)

        rv.sort()
        return set(rv)
コード例 #4
0
ファイル: notebook.py プロジェクト: whisk-ml/whisk
def run(relative_path):
    """
    Run a notebook from the command line with the given RELATIVE_PATH.
    """
    project = Project()
    subprocess.call(
        "jupyter nbconvert --clear-output --ExecutePreprocessor.timeout=1000 --execute {}"
        .format(relative_path),
        shell=True)
コード例 #5
0
ファイル: dvc.py プロジェクト: whisk-ml/whisk
import click
from whisk.project import Project
import os
from subprocess import call
project = Project()


@click.group()
def cli():
    pass


@cli.command()
@click.option("--bucket",
              default="whisk-" + project.name.replace("_", "-"),
              show_default=True)
def remote_add(bucket):
    """
    Adds a DVC S3 remote as the default remote using the provided S3 bucket.
    """
    call("dvc remote add -d s3 s3://{}/".format(bucket), shell=True)


@cli.command()
@click.option("--name", default="s3", show_default=True)
def remote_remove(name):
    """
    Removes the DVC S3 remote.
    """
    call("dvc remote remove {}".format(name), shell=True)
コード例 #6
0
from os.path import realpath
import whisk
from whisk.project import Project

"""
Initializes the whisk.project attribute so project helpers can be accessed via
whisk.project.*.
"""
whisk.project = Project.from_module(realpath(__file__))
whisk.data_dir = whisk.project.data_dir
whisk.artifacts_dir = whisk.project.artifacts_dir
コード例 #7
0
 def project_commands_dir(self):
     """Custom project commands directory."""
     return Project().commands_dir