Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix script execution in non-PATH directories #156

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading