Skip to content

Commit 65e19d9

Browse files
authored
fix: fix Windows console display issues caused by unspecified encoding (#7)
1 parent fba3c77 commit 65e19d9

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

dash_vite_plugin/utils.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ def _check_vite(self) -> bool:
163163
"""
164164
check_cmd = [self.npx_path, 'vite --help']
165165

166-
result = subprocess.run(check_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env)
166+
result = subprocess.run(
167+
check_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env, encoding='utf-8'
168+
)
167169
return result.returncode == 0
168170

169171
def _check_npm_package(self, package_name: str, package_type: Literal['devDependencies', 'dependencies']) -> bool:
@@ -225,7 +227,12 @@ def _install_vite(self) -> None:
225227
'@vitejs/plugin-vue',
226228
]
227229
result = subprocess.run(
228-
install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env
230+
install_cmd,
231+
capture_output=True,
232+
text=True,
233+
cwd=self.plugin_tmp_dir,
234+
env=self.node_env,
235+
encoding='utf-8',
229236
)
230237
if result.returncode != 0:
231238
raise RuntimeError(result.stderr)
@@ -253,7 +260,12 @@ def _install_less(self) -> None:
253260
'less',
254261
]
255262
result = subprocess.run(
256-
install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env
263+
install_cmd,
264+
capture_output=True,
265+
text=True,
266+
cwd=self.plugin_tmp_dir,
267+
env=self.node_env,
268+
encoding='utf-8',
257269
)
258270
if result.returncode != 0:
259271
raise RuntimeError(result.stderr)
@@ -281,7 +293,12 @@ def _install_sass(self) -> None:
281293
'sass',
282294
]
283295
result = subprocess.run(
284-
install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env
296+
install_cmd,
297+
capture_output=True,
298+
text=True,
299+
cwd=self.plugin_tmp_dir,
300+
env=self.node_env,
301+
encoding='utf-8',
285302
)
286303
if result.returncode != 0:
287304
raise RuntimeError(result.stderr)
@@ -309,7 +326,12 @@ def _install_npm_packages(self) -> None:
309326
f'{package.name}@{package.version}',
310327
]
311328
result = subprocess.run(
312-
install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env
329+
install_cmd,
330+
capture_output=True,
331+
text=True,
332+
cwd=self.plugin_tmp_dir,
333+
env=self.node_env,
334+
encoding='utf-8',
313335
)
314336
if result.returncode != 0:
315337
raise RuntimeError(result.stderr)
@@ -353,7 +375,12 @@ def init(self) -> Self:
353375
if not self._check_npm_init():
354376
init_cmd = [self.npm_path, 'init', '-y']
355377
result = subprocess.run(
356-
init_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env
378+
init_cmd,
379+
capture_output=True,
380+
text=True,
381+
cwd=self.plugin_tmp_dir,
382+
env=self.node_env,
383+
encoding='utf-8',
357384
)
358385
if result.returncode != 0:
359386
raise RuntimeError(result.stderr)
@@ -394,7 +421,7 @@ def build(self) -> Self:
394421
build_cmd: List[str] = [self.npx_path, 'vite', 'build']
395422

396423
result = subprocess.run(
397-
build_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env
424+
build_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env, encoding='utf-8'
398425
)
399426

400427
if result.returncode != 0:

0 commit comments

Comments
 (0)