11"""The vcpkg provider implementation"""
22
3+ import subprocess
34from logging import getLogger
45from os import name as system_name
56from pathlib import Path , PosixPath , WindowsPath
1617from cppython .plugins .cmake .schema import CMakeSyncData
1718from cppython .plugins .vcpkg .resolution import generate_manifest , resolve_vcpkg_data
1819from cppython .plugins .vcpkg .schema import VcpkgData
19- from cppython .utility .exception import NotSupportedError , ProcessError
20- from cppython .utility .subprocess import invoke as subprocess_call
20+ from cppython .utility .exception import NotSupportedError
2121from cppython .utility .utility import TypeName
2222
2323
@@ -76,19 +76,25 @@ def _update_provider(cls, path: Path) -> None:
7676
7777 try :
7878 if system_name == 'nt' :
79- subprocess_call (
80- str (WindowsPath ('bootstrap-vcpkg.bat' )), ['-disableMetrics' ], logger = logger , cwd = path , shell = True
79+ subprocess .run (
80+ [str (WindowsPath ('bootstrap-vcpkg.bat' )), '-disableMetrics' ],
81+ cwd = path ,
82+ shell = True ,
83+ check = True ,
84+ capture_output = True ,
8185 )
8286 elif system_name == 'posix' :
83- subprocess_call (
84- './' + str (PosixPath ('bootstrap-vcpkg.sh' )),
85- ['-disableMetrics' ],
86- logger = logger ,
87+ subprocess .run (
88+ ['./' + str (PosixPath ('bootstrap-vcpkg.sh' )), '-disableMetrics' ],
8789 cwd = path ,
8890 shell = True ,
91+ check = True ,
92+ capture_output = True ,
8993 )
90- except ProcessError :
91- logger .error ('Unable to bootstrap the vcpkg repository' , exc_info = True )
94+ except subprocess .CalledProcessError as e :
95+ logger .error (
96+ 'Unable to bootstrap the vcpkg repository: %s' , e .stderr .decode () if e .stderr else str (e ), exc_info = True
97+ )
9298 raise
9399
94100 def sync_data (self , consumer : SyncConsumer ) -> SyncData :
@@ -119,25 +125,17 @@ def tooling_downloaded(cls, path: Path) -> bool:
119125 Args:
120126 path: The directory to check for downloaded tooling
121127
122- Raises:
123- ProcessError: Failed vcpkg calls
124-
125128 Returns:
126129 Whether the tooling has been downloaded or not
127130 """
128- logger = getLogger ('cppython.vcpkg' )
129-
130131 try :
131- # Hide output, given an error output is a logic conditional
132- subprocess_call (
133- 'git' ,
134- ['rev-parse' , '--is-inside-work-tree' ],
135- logger = logger ,
136- suppress = True ,
132+ subprocess .run (
133+ ['git' , 'rev-parse' , '--is-inside-work-tree' ],
137134 cwd = path ,
135+ check = True ,
136+ capture_output = True ,
138137 )
139-
140- except ProcessError :
138+ except subprocess .CalledProcessError :
141139 return False
142140
143141 return True
@@ -148,9 +146,6 @@ async def download_tooling(cls, directory: Path) -> None:
148146
149147 Args:
150148 directory: The directory to download any extra tooling to
151-
152- Raises:
153- ProcessError: Failed vcpkg calls
154149 """
155150 logger = getLogger ('cppython.vcpkg' )
156151
@@ -159,35 +154,41 @@ async def download_tooling(cls, directory: Path) -> None:
159154 logger .debug ("Updating the vcpkg repository at '%s'" , directory .absolute ())
160155
161156 # The entire history is need for vcpkg 'baseline' information
162- subprocess_call ('git' , ['fetch' , 'origin' ], logger = logger , cwd = directory )
163- subprocess_call ('git' , ['pull' ], logger = logger , cwd = directory )
164- except ProcessError :
165- logger .exception ('Unable to update the vcpkg repository' )
157+ subprocess .run (
158+ ['git' , 'fetch' , 'origin' ],
159+ cwd = directory ,
160+ check = True ,
161+ capture_output = True ,
162+ )
163+ subprocess .run (
164+ ['git' , 'pull' ],
165+ cwd = directory ,
166+ check = True ,
167+ capture_output = True ,
168+ )
169+ except subprocess .CalledProcessError as e :
170+ logger .exception ('Unable to update the vcpkg repository: %s' , e .stderr .decode () if e .stderr else str (e ))
166171 raise
167172 else :
168173 try :
169174 logger .debug ("Cloning the vcpkg repository to '%s'" , directory .absolute ())
170175
171176 # The entire history is need for vcpkg 'baseline' information
172- subprocess_call (
173- 'git' ,
174- ['clone' , 'https://github.com/microsoft/vcpkg' , '.' ],
175- logger = logger ,
177+ subprocess .run (
178+ ['git' , 'clone' , 'https://github.com/microsoft/vcpkg' , '.' ],
176179 cwd = directory ,
180+ check = True ,
181+ capture_output = True ,
177182 )
178183
179- except ProcessError :
180- logger .exception ('Unable to clone the vcpkg repository' )
184+ except subprocess . CalledProcessError as e :
185+ logger .exception ('Unable to clone the vcpkg repository: %s' , e . stderr . decode () if e . stderr else str ( e ) )
181186 raise
182187
183188 cls ._update_provider (directory )
184189
185190 def install (self ) -> None :
186- """Called when dependencies need to be installed from a lock file.
187-
188- Raises:
189- ProcessError: Failed vcpkg calls
190- """
191+ """Called when dependencies need to be installed from a lock file."""
191192 manifest_directory = self .core_data .project_data .project_root
192193 manifest = generate_manifest (self .core_data , self .data )
193194
@@ -199,25 +200,18 @@ def install(self) -> None:
199200 executable = self .core_data .cppython_data .install_path / 'vcpkg'
200201 logger = getLogger ('cppython.vcpkg' )
201202 try :
202- subprocess_call (
203- executable ,
204- [
205- 'install' ,
206- f'--x-install-root={ self .data .install_directory } ' ,
207- ],
208- logger = logger ,
203+ subprocess .run (
204+ [str (executable ), 'install' , f'--x-install-root={ self .data .install_directory } ' ],
209205 cwd = self .core_data .cppython_data .build_path ,
206+ check = True ,
207+ capture_output = True ,
210208 )
211- except ProcessError :
212- logger .exception ('Unable to install project dependencies' )
209+ except subprocess . CalledProcessError as e :
210+ logger .exception ('Unable to install project dependencies: %s' , e . stderr . decode () if e . stderr else str ( e ) )
213211 raise
214212
215213 def update (self ) -> None :
216- """Called when dependencies need to be updated and written to the lock file.
217-
218- Raises:
219- ProcessError: Failed vcpkg calls
220- """
214+ """Called when dependencies need to be updated and written to the lock file."""
221215 manifest_directory = self .core_data .project_data .project_root
222216
223217 manifest = generate_manifest (self .core_data , self .data )
@@ -230,15 +224,12 @@ def update(self) -> None:
230224 executable = self .core_data .cppython_data .install_path / 'vcpkg'
231225 logger = getLogger ('cppython.vcpkg' )
232226 try :
233- subprocess_call (
234- executable ,
235- [
236- 'install' ,
237- f'--x-install-root={ self .data .install_directory } ' ,
238- ],
239- logger = logger ,
227+ subprocess .run (
228+ [str (executable ), 'install' , f'--x-install-root={ self .data .install_directory } ' ],
240229 cwd = self .core_data .cppython_data .build_path ,
230+ check = True ,
231+ capture_output = True ,
241232 )
242- except ProcessError :
243- logger .exception ('Unable to install project dependencies' )
233+ except subprocess . CalledProcessError as e :
234+ logger .exception ('Unable to install project dependencies: %s' , e . stderr . decode () if e . stderr else str ( e ) )
244235 raise
0 commit comments