Skip to content

Commit 1702fb1

Browse files
tonybaloneybrettcannon
authored andcommitted
Extend pvsc dev script to support branch and repo URL (microsoft#3838)
1 parent 064b837 commit 1702fb1

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

news/3 Code Health/3837.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bugfix to `pvsc-dev-ext.py` where arguments to git would not be passed on POSIX-based environments. Extended `pvsc-dev-ext.py setup` command with 2
2+
optional flags-- `--repo` and `--branch` to override the default git repository URL and the branch used to clone and install the extension.
3+
(thanks [Anthony Shaw](https://github.com/tonybaloney/))

pvsc-dev-ext.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class VSCode(enum.Enum):
3232

3333
def run_command(command, cwd=None):
3434
"""Run the specified command in a subprocess shell."""
35-
cmd = subprocess.run(command, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
35+
cmd = subprocess.run(command, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
3636
cmd.check_returncode()
3737

3838

3939
def checkout_directory(install_type, dir_name="vscode-python"):
4040
return pathlib.Path.home() / install_type.value / "extensions" / dir_name
4141

4242

43-
def clone_repo(clone_to):
43+
def clone_repo(clone_to, repo, branch):
4444
"""Clone the repository to the appropriate location."""
4545
# https://code.visualstudio.com/docs/editor/extension-gallery#_where-are-extensions-installed
46-
cmd = ["git", "clone", "-q", "--single-branch", "--branch", "master", REPO_URL, os.fspath(clone_to)]
46+
cmd = ["git", "clone", "-q", "--single-branch", "--branch", branch, repo, os.fspath(clone_to)]
4747
run_command(cmd)
4848

4949

@@ -104,11 +104,11 @@ def build(checkout):
104104
install_PyPI_packages(checkout)
105105

106106

107-
def setup(install_type):
107+
def setup(install_type, repo, branch):
108108
"""Set up a clone of PVSC."""
109109
checkout = checkout_directory(install_type)
110-
print(f"Cloning {REPO_URL} ...")
111-
clone_repo(checkout)
110+
print(f"Cloning {repo} ...")
111+
clone_repo(checkout, repo, branch)
112112
build(checkout)
113113

114114

@@ -132,15 +132,20 @@ def parse_args(args=sys.argv[1:]):
132132
subparsers = parser.add_subparsers(dest="cmd")
133133
setup_parser = subparsers.add_parser("setup")
134134
setup_parser.add_argument("install_type", choices=[install_type.name for install_type in VSCode])
135+
setup_parser.add_argument('--repo', dest='repo', default=REPO_URL)
136+
setup_parser.add_argument('--branch', dest='branch', default='master')
135137
update_parser = subparsers.add_parser("update")
136138
return parser.parse_args(args)
137139

138140

139141
if __name__ == "__main__":
140142
args = parse_args()
141-
if args.cmd == "setup":
142-
setup(VSCode[args.install_type])
143-
elif args.cmd == "update":
144-
update()
145-
else:
146-
raise RuntimeError(f"unrecognized sub-command: {args.cmd!r}")
143+
try:
144+
if args.cmd == "setup":
145+
setup(VSCode[args.install_type], args.repo, args.branch)
146+
elif args.cmd == "update":
147+
update()
148+
else:
149+
raise RuntimeError(f"Unrecognized sub-command: {args.cmd!r}")
150+
except subprocess.CalledProcessError as exc:
151+
print(f"Failed to run command {exc.cmd} : {exc.stderr}")

0 commit comments

Comments
 (0)