py-app-dev 2.3.2__tar.gz → 2.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py-app-dev
3
- Version: 2.3.2
3
+ Version: 2.3.3
4
4
  Summary: My application development modules.
5
5
  Home-page: https://github.com/cuinixam/python-app-dev
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "py-app-dev"
3
- version = "2.3.2"
3
+ version = "2.3.3"
4
4
  description = "My application development modules."
5
5
  authors = ["cuinixam <me@cuinixam.com>"]
6
6
  license = "MIT"
@@ -68,7 +68,7 @@ match = "(?!main$)"
68
68
  prerelease = true
69
69
 
70
70
  [tool.pytest.ini_options]
71
- addopts = "-v -Wdefault --cov=py_app_dev --cov-report=term-missing:skip-covered"
71
+ addopts = "-vv -Wdefault --cov=py_app_dev --cov-report=term-missing:skip-covered -s"
72
72
  pythonpath = ["src"]
73
73
 
74
74
  [tool.coverage.run]
@@ -0,0 +1 @@
1
+ __version__ = "2.3.3"
@@ -1,5 +1,4 @@
1
1
  import json
2
- import os
3
2
  import re
4
3
  from concurrent.futures import ThreadPoolExecutor, as_completed
5
4
  from dataclasses import dataclass, field
@@ -209,13 +208,16 @@ class ScoopWrapper:
209
208
  with TemporaryDirectory() as tmp_dir:
210
209
  tmp_scoop_file = Path(tmp_dir).joinpath("scoopfile.json")
211
210
  ScoopInstallConfigFile(scoop_install_config.buckets, apps_to_install).to_file(tmp_scoop_file)
212
- # (!) Make sure powershell core module does not pollute the module path. Without this change scoop.ps1 fails because 'Get-FileHash' cannot be found.
213
- # See more details here: https://github.com/PowerShell/PowerShell/issues/8635
214
- env = os.environ.copy()
215
- env["PSMODULEPATH"] = f"$PSHOME/Modules;{env.get('PSMODULEPATH', '')}"
216
- SubprocessExecutor(["powershell.exe", self.scoop_script, "import", tmp_scoop_file], env=env).execute()
211
+ self.run_powershell_command(f"{self.scoop_script} import {tmp_scoop_file}")
217
212
  return apps_to_install
218
213
 
214
+ @staticmethod
215
+ def run_powershell_command(command: str, update_ps_module_path: bool = True) -> None:
216
+ # (!) Make sure powershell core module does not pollute the module path. Without this change scoop.ps1 fails because 'Get-FileHash' cannot be found.
217
+ # See more details here: https://github.com/PowerShell/PowerShell/issues/8635
218
+ ps_command = f'$env:PSModulePath=\\"$PSHOME\\Modules;$env:PSMODULEPATH\\"; {command}' if update_ps_module_path else f"{command}"
219
+ SubprocessExecutor(f"powershell.exe -Command {ps_command}").execute()
220
+
219
221
  @staticmethod
220
222
  def map_required_apps_to_installed_apps(
221
223
  app_names: List[str],
@@ -1,7 +1,7 @@
1
1
  import shutil
2
2
  import subprocess # nosec
3
3
  from pathlib import Path
4
- from typing import Dict, List, Optional
4
+ from typing import Dict, List, Optional, Union
5
5
 
6
6
  from .exceptions import UserNotificationException
7
7
  from .logging import logger
@@ -16,31 +16,37 @@ def which(app_name: str) -> Optional[Path]:
16
16
  class SubprocessExecutor:
17
17
  def __init__(
18
18
  self,
19
- command: List[str | Path],
19
+ command: Union[str, List[str | Path]],
20
20
  cwd: Optional[Path] = None,
21
21
  capture_output: bool = True,
22
22
  env: Optional[Dict[str, str]] = None,
23
23
  shell: bool = False,
24
24
  ):
25
25
  self.logger = logger.bind()
26
- self.command = " ".join([str(cmd) for cmd in command])
26
+ self.command = command
27
27
  self.current_working_directory = cwd
28
28
  self.capture_output = capture_output
29
29
  self.env = env
30
30
  self.shell = shell
31
31
 
32
+ @property
33
+ def command_str(self) -> str:
34
+ if isinstance(self.command, str):
35
+ return self.command
36
+ return " ".join(str(arg) if not isinstance(arg, str) else arg for arg in self.command)
37
+
32
38
  def execute(self) -> None:
33
39
  try:
34
- self.logger.info(f"Running command: {self.command}")
40
+ self.logger.info(f"Running command: {self.command_str}")
35
41
  cwd_path = (self.current_working_directory or Path.cwd()).as_posix()
36
42
  with subprocess.Popen(
37
- self.command.split(),
43
+ args=self.command,
38
44
  cwd=cwd_path,
39
45
  stdout=(subprocess.PIPE if self.capture_output else subprocess.DEVNULL),
40
46
  stderr=(subprocess.STDOUT if self.capture_output else subprocess.DEVNULL),
41
47
  text=True,
42
48
  env=self.env,
43
- shell=self.shell, # noqa: S603
49
+ shell=self.shell,
44
50
  ) as process: # nosec
45
51
  if self.capture_output and process.stdout is not None:
46
52
  for line in iter(process.stdout.readline, ""):
@@ -49,8 +55,8 @@ class SubprocessExecutor:
49
55
 
50
56
  # Check return code
51
57
  if process.returncode != 0:
52
- raise subprocess.CalledProcessError(process.returncode, self.command)
58
+ raise subprocess.CalledProcessError(process.returncode, self.command_str)
53
59
  except subprocess.CalledProcessError as e:
54
- raise UserNotificationException(f"Command '{self.command}' failed with return code {e.returncode}") from None
60
+ raise UserNotificationException(f"Command '{self.command_str}' failed with return code {e.returncode}") from None
55
61
  except FileNotFoundError as e:
56
- raise UserNotificationException(f"Command '{self.command}' failed with error {e}") from None
62
+ raise UserNotificationException(f"Command '{self.command_str}' failed with error {e}") from None
@@ -1 +0,0 @@
1
- __version__ = "2.3.2"
File without changes
File without changes