Scenario: using project-specific sets of aliases

We will again continue where we left off in part 2 (Scenario: local development with Docker). This time we will see how commands that were created in one Dodo Commands environment can be reused in a different environemnt. If you haven’t done the steps of the previous scenario, run this to get started:

cd /tmp
git clone git@github.com:mnieber/dodo_commands_tutorial.git

# Copy the end state of part 2 of the tutorial
cp -rf ./dodo_commands_tutorial/part2/after ./tutorial

# Create and activate a dodo environment for our project
cd ./tutorial
$(dodo env --init tutorial)

Activating the default Dodo Commands environment

Let’s start by deactivating the current tutorial environment. You do this by activating the default environment:

# activate default environment
$(dodo env default)

dodo which

    default

Tip

In the output of dodo print-config we see that all command directories in ~/.dodo_commands/default_project/commands/* are in the command path. This is true for all Dodo Commands environments (unless if you explitly remove this path from the command path).

Installing more commands

We will now see how additional default commands can be installed.

# If you haven't activated the default environment yet, do so now
$(dodo env default)

# Install the dodo-git-commands pip package
dodo install-commands --pip dodo-git-commands --to-defaults --confirm

    (/) python3.5 -m pip install --upgrade --target ~/.dodo_commands/commands dodo_git_commands

    confirm? [Y/n]

    Collecting dodo-git-commands
    Successfully installed dodo-git-commands-0.3.0

    (/) ln -s \
      ~/.dodo_commands/commands/dodo_git_commands \
      ~/.dodo_commands/default_project/commands/dodo_git_commands

    confirm? [Y/n]

Creating a new environment

Now we’ll create a new project in the ~/projects directory. The new project will have a python virtual environment.

# create a new project with python virtual environment
$(dodo env --create --create-python-env foo)

    Creating project directory ~/projects/foo ... done

Tip

You can change the standard location for creating new projects in the ~/.dodo_commands/config file. You can edit this file or call

dodo global-config settings.projects_dir /path/to/projects

Using the mk.py script in the new environment

To use the mk command script that we created in the tutorial environment, we need to have /tmp/tutorial/commands in our command_path. Surely, we can simply add this path to ${/ROOT/command_path}. The problem with this approach is that we may move the tutorial project to a new location, and then the hard-coded path will no longer be correct. In the steps below, we will use an alternative option that is a bit more robust.

In this step, we use dodo install-commands to create a symlink in the global commands directory that points to /tmp/tutorial/commands. Note that we use the --as option to give a more recognizable name (dodo_tutorial_commands) to the new command path.

dodo install-commands /tmp/tutorial/commands --as dodo_tutorial_commands --confirm

    (/tmp) ln -s \
      /tmp/tutorial/commands \
      ~/.dodo_commands/commands/dodo_tutorial_commands

    confirm? [Y/n]

Importing symbols from a command script

So far, we’ve kept our mk script deliberately very simple. Let’s refactor it by extracting a function for running make. We can then use this function in our mk-greet script.

# In: /tmp/tutorial/commands/mk.py

from dodo_commands import Dodo

def run_make(*what):
    Dodo.run(["make", *what], cwd=Dodo.get("/MAKE/cwd"))

if Dodo.is_main(__name__):
    Dodo.parser.add_argument("what")
    run_make(Dodo.args.what)

Detail sections

Open the adjacent tabs for more detail sections