|
6 | 6 | from sys import platform, version_info |
7 | 7 | from typing import Any, Dict, NamedTuple |
8 | 8 |
|
| 9 | +try: |
| 10 | + from importlib import resources |
| 11 | + if not hasattr(resources, 'files'): |
| 12 | + import importlib_resources as resources |
| 13 | +except ImportError: |
| 14 | + import importlib_resources as resources |
| 15 | + |
9 | 16 | LINUX_LIKE_PLATFORMS = ["linux", "linux2", "darwin"] |
10 | 17 |
|
11 | 18 | # This is a global variable imported by other modules |
@@ -110,25 +117,27 @@ async def execute_bash_script( |
110 | 117 | script: str, arguments: list = [], cwd: Path = Path.cwd() |
111 | 118 | ) -> str: |
112 | 119 | """executes a bash script in an asynchronously""" |
113 | | - try: |
114 | | - process = await asyncio.create_subprocess_exec( |
115 | | - "bash", |
116 | | - script, |
117 | | - *arguments, |
118 | | - cwd=cwd, |
119 | | - stdout=asyncio.subprocess.PIPE, |
120 | | - stderr=asyncio.subprocess.PIPE, |
121 | | - ) |
122 | | - except FileNotFoundError: |
123 | | - raise GitException( |
124 | | - "bash executable not found. Please ensure bash is available in PATH." |
125 | | - ) |
126 | | - |
127 | | - stdout, stderr = await process.communicate() |
128 | | - stdout_str, stderr_str = stdout.decode(), stderr.decode() |
129 | | - if process.returncode == 1: |
130 | | - raise BashException(f"\n{stderr_str}\n") |
131 | | - return stdout_str |
| 120 | + ref = resources.files("mkdocs_multirepo_plugin") / "scripts" / script |
| 121 | + with resources.as_file(ref) as script_path: |
| 122 | + try: |
| 123 | + process = await asyncio.create_subprocess_exec( |
| 124 | + "bash", |
| 125 | + script_path, |
| 126 | + *arguments, |
| 127 | + cwd=cwd, |
| 128 | + stdout=asyncio.subprocess.PIPE, |
| 129 | + stderr=asyncio.subprocess.PIPE, |
| 130 | + ) |
| 131 | + except FileNotFoundError: |
| 132 | + raise GitException( |
| 133 | + "bash executable not found. Please ensure bash is available in PATH." |
| 134 | + ) |
| 135 | + |
| 136 | + stdout, stderr = await process.communicate() |
| 137 | + stdout_str, stderr_str = stdout.decode(), stderr.decode() |
| 138 | + if process.returncode != 0: |
| 139 | + raise BashException(f"\n{stderr_str}\n") |
| 140 | + return stdout_str |
132 | 141 |
|
133 | 142 |
|
134 | 143 | def asyncio_run(futures) -> None: |
|
0 commit comments