Skip to content

Commit df7b9be

Browse files
authored
fix script execution in non-PATH directories (#156)
1 parent f017969 commit df7b9be

File tree

4 files changed

+453
-282
lines changed

4 files changed

+453
-282
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.8.3
2+
3+
### Prs in Release
4+
5+
- [Fix script execution in virtualenvs](https://github.com/jdoiro3/mkdocs-multirepo-plugin/pull/156)
6+
17
## 0.8.2
28

39
### Prs in Release

mkdocs_multirepo_plugin/util.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from sys import platform, version_info
77
from typing import Any, Dict, NamedTuple
88

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+
916
LINUX_LIKE_PLATFORMS = ["linux", "linux2", "darwin"]
1017

1118
# This is a global variable imported by other modules
@@ -110,25 +117,27 @@ async def execute_bash_script(
110117
script: str, arguments: list = [], cwd: Path = Path.cwd()
111118
) -> str:
112119
"""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
132141

133142

134143
def asyncio_run(futures) -> None:

0 commit comments

Comments
 (0)