Skip to content

Write a wiki page for monorepo setups #21969

Closed

Description

@luabud

Related to #21204

There are a couple of existing workarounds to manage mono repos with Python, and a few extensions that can be helpful. This issue is to track documenting them into a page in our wiki

Activity

  1. luabud commented on Oct 24, 2023

    @luabud
    MemberAuthor

    Below is the proposal of what we'd add to the Python extension wiki page:


    Python in VS Code – 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.

    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

    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 #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!

  2. cwebster-99 commented on Oct 24, 2023

    @cwebster-99
    Member

    Made some small grammar edits inline otherwise the content LGTM!

  3. luabud commented on Oct 25, 2023

    @luabud
    MemberAuthor
  4. locked as resolved and limited conversation to collaborators on Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions