Skip to content

Commit a77329a

Browse files
committed
Replace Custom Subprocess Wrapper
Obfuscates the functionality of the built-in library
1 parent 500ce9b commit a77329a

File tree

5 files changed

+55
-293
lines changed

5 files changed

+55
-293
lines changed

cppython/plugins/vcpkg/plugin.py

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""The vcpkg provider implementation"""
22

3+
import subprocess
34
from logging import getLogger
45
from os import name as system_name
56
from pathlib import Path, PosixPath, WindowsPath
@@ -16,8 +17,7 @@
1617
from cppython.plugins.cmake.schema import CMakeSyncData
1718
from cppython.plugins.vcpkg.resolution import generate_manifest, resolve_vcpkg_data
1819
from 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
2121
from 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

cppython/project.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from cppython.core.resolution import resolve_model
1010
from cppython.core.schema import Interface, ProjectConfiguration, PyProject
1111
from cppython.schema import API
12-
from cppython.utility.exception import ProcessError
1312

1413

1514
class Project(API):
@@ -71,9 +70,6 @@ def install(self) -> None:
7170

7271
try:
7372
self._data.plugins.provider.install()
74-
except ProcessError as error:
75-
self.logger.error('Installation failed: %s', error.error)
76-
raise SystemExit('Error: Provider installation failed. Please check the logs.') from None
7773
except Exception as exception:
7874
self.logger.error('Unexpected error during installation: %s', str(exception))
7975
raise SystemExit('Error: An unexpected error occurred during installation.') from None
@@ -98,9 +94,6 @@ def update(self) -> None:
9894

9995
try:
10096
self._data.plugins.provider.update()
101-
except ProcessError as error:
102-
self.logger.error('Update failed: %s', error.error)
103-
raise SystemExit('Error: Provider update failed. Please check the logs.') from None
10497
except Exception as exception:
10598
self.logger.error('Unexpected error during update: %s', str(exception))
10699
raise SystemExit('Error: An unexpected error occurred during update.') from None

cppython/utility/exception.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
"""Exception definitions"""
22

33

4-
class ProcessError(Exception):
5-
"""Raised when there is a configuration error"""
6-
7-
def __init__(self, error: str) -> None:
8-
"""Initializes the error
9-
10-
Args:
11-
error: The error message
12-
"""
13-
self._error = error
14-
15-
super().__init__(error)
16-
17-
@property
18-
def error(self) -> str:
19-
"""Returns the underlying error
20-
21-
Returns:
22-
str -- The underlying error
23-
"""
24-
return self._error
25-
26-
274
class PluginError(Exception):
285
"""Raised when there is a plugin error"""
296

cppython/utility/subprocess.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)