Skip to content

Mono Repo Set‐up Guide

Luciana Abud edited this page Dec 13, 2023 · 2 revisions

This guide will walk you through the process of setting up a Python mono repo in Visual Studio Code for two different dependency management scenarios.

Scenario 1: Shared Dependencies

There are cases where all the projects under the root folder of a mono repo don't have conflicting dependencies, which means they can all be installed successfully into the same virtual environment. In such scenarios, you can just open the mono repo root folder in VS Code, create a virtual environment at the root folder level, and install all the project dependencies.

Example repo: Azure SDK for Python repo

Set up steps

In VS Code, open the mono repo folder in VS Code:

  1. Click on File > Open Folder....
  2. Select the root folder of your mono repo.

Then create a virtual environment:

  1. Open the command palette (Ctrl/Cmd + Shift + P).
  2. Run the Python: Create Environment command.
  3. Select the type of environment you want to create (e.g. venv) and the Python version (e.g. 3.11).
  4. Select all the dependencies files you wish to install.

Scenario 2: Separate Virtual Environments

In cases where each project folder may have different dependencies that may conflict with each other, and therefore can't be installed in the same virtual environment, you can take advantage of multi-root workspaces.

Example repo: Responsible AI Toolbox

Note: this repository is currently not set up to be used as a multi-root workspace. It's an example of a codebase that can be set up by following the steps below.

Set up steps

In VS Code, open one of the project folders in your mono repo in VS Code:

  1. Click on File > Open folder... and select one of the project folders from the mono repo.

Then add the remaining project folders to this workspace:

  1. Click on File > Add Folder to Workspace...
  2. Select all project folders you want to add as a workspace (you can select multiple at once by Ctrl/Cmd + Click depending on your OS's file explorer)

For each project within your multi-root workspace you want to work on, create a virtual environment:

  1. Open the command palette (Ctrl/Cmd + Shift + P).
  2. Run the Python: Create Environment command.
  3. Select the folder you want to create an environment for.
  4. Select the type of environment you want to create (e.g. venv) and the Python version (e.g. 3.11).
  5. Select all the dependencies files you wish to install in that particular environment.

If the root folder contains files or metadata you need for your development, you can also open it as a separate workspace. To avoid having duplicated files and directories in the File Explorer view, you can set up the files.exclude VS Code setting to "hide" the projects under this folder:

  1. Click on File > Add Folder to Workspace... and select the mono repo root folder.

  2. If this folder doesn't have a settings.json file under a .vscode directory at the root, create it.

  3. Then add the "files.exclude" setting, with a list of the paths to the folders you added as workspaces in step 3.

    For example, if project1, project2, and project3 were project folders that I had opened as their own workspaces in my multi-root workspace, and rootproject is the root folder for my mono repo, I'd add the following to the rootproject/.vscode/settings.json file: "files.exclude" : { "project1": true, "project2": true, "project3": true}

If for some reason multi-root workspaces aren't a good fit for your use case, there are a few helpful extensions that may offer a suitable workaround for your workflow if you open the root folder of your mono repo as a folder in VS Code:

  • If you are using the Pylint extension in VS Code, you can set the pylint.cwd directory to ${fileDirname} so it can dynamically set the linter's currently working directory to the parent folder of the current file you have open in VS Code.
  • You can install a few extensions built and maintained by the community:
    • Suspenders: this extension an be helpful if you are using Pants as your mono repo build system.
    • Python Environment Manager: this extension adds a Python environment and package viewer, and provides a convenient way to activate different environments in the terminal through the UI, as well as change the selected interpreter for your workspace. python environment and package viewer

If none of these work for you, we would appreciate it if you could share a comment to https://github.com/microsoft/vscode-python/issues/21204 providing more details about your workflow and project structure. We are always looking for ways to improve the Python extension and your feedback is very valuable to us!

Clone this wiki locally