Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a wiki page for monorepo setups #21969

Closed
luabud opened this issue Sep 11, 2023 · 3 comments
Closed

Write a wiki page for monorepo setups #21969

luabud opened this issue Sep 11, 2023 · 3 comments
Assignees
Labels
area-editor-* User-facing catch-all documentation on-testplan Added to test plan
Milestone

Comments

@luabud
Copy link
Member

luabud commented Sep 11, 2023

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

@luabud luabud added feature-request Request for new features or functionality documentation needs PR Ready to be worked on area-editor-* User-facing catch-all and removed feature-request Request for new features or functionality labels Sep 11, 2023
@luabud luabud self-assigned this Sep 11, 2023
@luabud luabud added needs proposal Need to make some design decisions and removed needs PR Ready to be worked on labels Sep 11, 2023
@luabud luabud added this to the September 2023 milestone Sep 11, 2023
@luabud luabud modified the milestones: September 2023, October 2023 Sep 25, 2023
@luabud
Copy link
Member Author

luabud commented Oct 24, 2023

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!

@github-actions github-actions bot added the on-testplan Added to test plan label Oct 24, 2023
@luabud luabud closed this as completed Oct 24, 2023
@github-actions github-actions bot removed the needs proposal Need to make some design decisions label Oct 24, 2023
@cwebster-99
Copy link
Member

Made some small grammar edits inline otherwise the content LGTM!

@luabud
Copy link
Member Author

luabud commented Oct 25, 2023

@cwebster-99 thank you so much!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-editor-* User-facing catch-all documentation on-testplan Added to test plan
Projects
None yet
Development

No branches or pull requests

2 participants