Skip to content

Commit

Permalink
fix script execution in non-PATH directories (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoe authored Aug 13, 2024
1 parent f017969 commit df7b9be
Show file tree
Hide file tree
Showing 4 changed files with 453 additions and 282 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.8.3

### Prs in Release

- [Fix script execution in virtualenvs](https://github.com/jdoiro3/mkdocs-multirepo-plugin/pull/156)

## 0.8.2

### Prs in Release
Expand Down
47 changes: 28 additions & 19 deletions mkdocs_multirepo_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from sys import platform, version_info
from typing import Any, Dict, NamedTuple

try:
from importlib import resources
if not hasattr(resources, 'files'):
import importlib_resources as resources
except ImportError:
import importlib_resources as resources

LINUX_LIKE_PLATFORMS = ["linux", "linux2", "darwin"]

# This is a global variable imported by other modules
Expand Down Expand Up @@ -110,25 +117,27 @@ async def execute_bash_script(
script: str, arguments: list = [], cwd: Path = Path.cwd()
) -> str:
"""executes a bash script in an asynchronously"""
try:
process = await asyncio.create_subprocess_exec(
"bash",
script,
*arguments,
cwd=cwd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
except FileNotFoundError:
raise GitException(
"bash executable not found. Please ensure bash is available in PATH."
)

stdout, stderr = await process.communicate()
stdout_str, stderr_str = stdout.decode(), stderr.decode()
if process.returncode == 1:
raise BashException(f"\n{stderr_str}\n")
return stdout_str
ref = resources.files("mkdocs_multirepo_plugin") / "scripts" / script
with resources.as_file(ref) as script_path:
try:
process = await asyncio.create_subprocess_exec(
"bash",
script_path,
*arguments,
cwd=cwd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
except FileNotFoundError:
raise GitException(
"bash executable not found. Please ensure bash is available in PATH."
)

stdout, stderr = await process.communicate()
stdout_str, stderr_str = stdout.decode(), stderr.decode()
if process.returncode != 0:
raise BashException(f"\n{stderr_str}\n")
return stdout_str


def asyncio_run(futures) -> None:
Expand Down
Loading

0 comments on commit df7b9be

Please sign in to comment.