-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup VsCode settings for remote development during
mila init
(#71)
* Make functions for each chunk of `mila init` fn Signed-off-by: Fabrice Normandin <[email protected]> * Setup VsCode settings during `mila init` Signed-off-by: Fabrice Normandin <[email protected]> * Add test for the VsCode settings part of mila init Signed-off-by: Fabrice Normandin <[email protected]> * Add another test to check overwriting of setting Signed-off-by: Fabrice Normandin <[email protected]> * Fix indent of generated VsCode settings file Signed-off-by: Fabrice Normandin <[email protected]> * Fix the indent in the regression files Signed-off-by: Fabrice Normandin <[email protected]> * Use indent=4 spaces instead of tab in json file Signed-off-by: Fabrice Normandin <[email protected]> * Fix isort issue Signed-off-by: Fabrice Normandin <[email protected]> * Add tests for the vscode utils Signed-off-by: Fabrice Normandin <[email protected]> --------- Signed-off-by: Fabrice Normandin <[email protected]>
- Loading branch information
Showing
10 changed files
with
325 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
from logging import getLogger as get_logger | ||
from pathlib import Path | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
def running_inside_WSL() -> bool: | ||
return sys.platform == "linux" and bool(shutil.which("powershell.exe")) | ||
|
||
|
||
def get_expected_vscode_settings_json_path() -> Path: | ||
if sys.platform == "win32": | ||
return Path.home() / "AppData\\Roaming\\Code\\User\\settings.json" | ||
if sys.platform == "darwin": # MacOS | ||
return ( | ||
Path.home() | ||
/ "Library" | ||
/ "Application Support" | ||
/ "Code" | ||
/ "User" | ||
/ "settings.json" | ||
) | ||
if running_inside_WSL(): | ||
# Need to get the Windows Home directory, not the WSL one! | ||
windows_username = subprocess.getoutput("powershell.exe '$env:UserName'") | ||
return Path( | ||
f"/mnt/c/Users/{windows_username}/AppData/Roaming/Code/User/settings.json" | ||
) | ||
# Linux: | ||
return Path.home() / ".config/Code/User/settings.json" | ||
|
||
|
||
def vscode_installed() -> bool: | ||
return bool(shutil.which(os.environ.get("MILATOOLS_CODE_COMMAND", "code"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/cli/test_init_command/test_setup_vscode_settings_accept_None_.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Calling `setup_vscode_settings()` with no initial VsCode settings file | ||
|
||
and these user inputs: ('y',) | ||
leads the following VsCode settings file: | ||
|
||
```json | ||
{ | ||
"remote.SSH.connectTimeout": 60 | ||
} | ||
``` |
14 changes: 14 additions & 0 deletions
14
...s/cli/test_init_command/test_setup_vscode_settings_accept_initial_settings1_.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Calling `setup_vscode_settings()` with this initial content: | ||
|
||
```json | ||
{} | ||
``` | ||
|
||
and these user inputs: ('y',) | ||
leads the following VsCode settings file: | ||
|
||
```json | ||
{ | ||
"remote.SSH.connectTimeout": 60 | ||
} | ||
``` |
Oops, something went wrong.