Mephisto and dev containers

Aug 6, 2023 · 4 min read

I’m currently looking into what Mephisto can do. Mephisto describes itself as

Mephisto was designed from the ground up to work with different “crowd providers”. You can use Amazon Mechanical Turk, an internal platform for your organization, or something else. Additionally, launch your tasks on Heroku, EC2, etc.

So I wanted to check it out and run it locally to see for myself. I started with the 10-minute Quickstart guide but hit issues with the installation of dependencies. I tried Python 3.8, and 3.11, and with pip install and poetry install. I am fairly confident this is to do with my Apple Silicon Mac (I have issues with other Python projects too!). So rather than get bogged down in that world, I thought it would be easier to spin up a dev container in VS Code. This post is going to show you how you can do that (and provides a reference for me as to what the configuration is).

Clone the Mephisto repo, as documentation says.

git clone https://github.com/facebookresearch/Mephisto.git
cd Mephisto

Make sure you have the “Dev Containers” (identifier: ms-vscode-remote.remote-containers) extension for VS Code installed. Now you can create the .devcontainer/devcontainer.json file inside the repo. I’ve augmented the comments inline as to why the line exists, so you can decide to omit if you would prefer.

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
  // You can name this anything you like really. It appears at the bottom left of VS Code.
  "name": "mephisto",
  // This is the base image for the dev container.
  // I've gone with 3.8 as that is referenced in the GitHub Actions as the Python version
  // being installed for their workflows.
  "image": "mcr.microsoft.com/devcontainers/python:1-3.8-bookworm",
  // Poetry as the tool to install dependencies.
  "features": {
    "ghcr.io/devcontainers-contrib/features/poetry:2": {},
    // Vim as a standard dev tool I install in containers.
    "ghcr.io/guiyomh/features/vim:0": {},
    // Part of the project has Node dependencies, so makes sense to add Node too.
    "ghcr.io/devcontainers/features/node:1": {}
  }

  // There are other configuration options for dev containers, but currently
  // not using them here
}

If you save this file and open VS Code, it should see the configuration file and ask you if you want to build the dev container and use it. If it doesn’t, open the Command Palette and then search for “Dev Containers: Rebuild and Reopen in Container”.

This will build the dev container for you. Once this is completed, your project is now operating inside a dev container. This means your terminal inside VS Code is running inside Docker with the right environment.

Now we can install the dependencies:

poetry install

Hopefully, that has worked for you. Now let’s get to running the Mephisto web client. First, we want to get inside a poetry shell, so let’s run that command.

poetry shell

This should now allow us to run the mephisto CLI. Let’s confirm that.

mephisto

 Usage: mephisto [OPTIONS] COMMAND [ARGS]...

 Bring your research ideas to life with powerful crowdsourcing tooling

╭─ Options ───────────────────────────────────────────────────────────────────────────╮
│ --help      Show this message and exit.                                             │
╰─────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ──────────────────────────────────────────────────────────────────────────╮
│ check              Checks that mephisto is setup correctly                          │
│ config                                                                              │
│ metrics                                                                             │
│ register           Register a requester with a crowd provider                       │
│ requesters         Lists all registered requesters                                  │
│ review             Launch a local review UI server. Reads in rows froms stdin       │
│                    and outputs to either a file or stdout.                          │
│ scripts            Run one of the many mephisto scripts.                            │
│ web                Launch a local webserver with the Mephisto UI                    │
│ wut                Discover the configuration arguments for different abstractions  │
╰─────────────────────────────────────────────────────────────────────────────────────╯

(mephisto-py3.8)

Now let’s go ahead and run the webserver:

mephisto web

This should allow you to view the web client on http://127.0.0.1:5000. It should look something similar to this.

Mephisto web home page

That’s it for now 😀

See also