-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Mono Repo Set‐up Guide
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.
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
In VS Code, open the mono repo folder in VS Code:
- Click on File > Open Folder....
- Select the root folder of your mono repo.
Then create a virtual environment:
- Open the command palette (
Ctrl/Cmd + Shift + P
). - Run the Python: Create Environment command.
- Select the type of environment you want to create (e.g.
venv
) and the Python version (e.g. 3.11). - Select all the dependencies files you wish to install.
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.
In VS Code, open one of the project folders in your mono repo in VS Code:
- 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:
- Click on File > Add Folder to Workspace...
- 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:
- Open the command palette (Ctrl/Cmd + Shift + P).
- Run the Python: Create Environment command.
- Select the folder you want to create an environment for.
- Select the type of environment you want to create (e.g.
venv
) and the Python version (e.g. 3.11). - 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:
-
Click on File > Add Folder to Workspace... and select the mono repo root folder.
-
If this folder doesn't have a
settings.json
file under a.vscode
directory at the root, create it. -
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
, andproject3
were project folders that I had opened as their own workspaces in my multi-root workspace, androotproject
is the root folder for my mono repo, I'd add the following to therootproject/.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:
- Try the new Python Environments extension in preview
- 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.
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!