Skip to content

Commit

Permalink
allow invoking mach from arbitary current working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mukilan committed Dec 15, 2024
1 parent 94aabd2 commit 0a939cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions mach
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
# given in `.python-version` and python/mach_bootstrap.py will provision a new
# environment that will be used for the subsequent runs.
''':' && {
MACH_DIR=$(dirname "$0");
run_in_nix_if_needed() {
if ([ -f /etc/NIXOS ] || [ -n "${MACH_USE_NIX}" ]) && [ -z "${IN_NIX_SHELL}" ]; then
EXTRA_NIX_ARGS=${SERVO_ANDROID_BUILD:+'--arg buildAndroid true'}
echo "NOTE: Entering nix-shell $(pwd)/shell.nix"
exec nix-shell $EXTRA_NIX_ARGS --run "$*"
echo "NOTE: Entering nix-shell ${MACH_DIR}/shell.nix"
exec nix-shell ${MACH_DIR}/shell.nix $EXTRA_NIX_ARGS --run "$*"
else
exec $*
fi
}

run_in_nix_if_needed uv run python ./mach $*
run_in_nix_if_needed uv run python ${MACH_DIR}/mach $*
}
'''
Expand Down
3 changes: 2 additions & 1 deletion mach.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@echo off

uv run python .\mach %*
set workdir=%~dp0
uv run python %workdir%mach %*
9 changes: 5 additions & 4 deletions python/mach_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
}


def _process_exec(args):
def _process_exec(args, cwd):
try:
subprocess.check_output(args, stderr=subprocess.STDOUT)
subprocess.check_output(args, stderr=subprocess.STDOUT, cwd=cwd)
except subprocess.CalledProcessError as exception:
print(exception.output.decode(sys.stdout.encoding))
print(f"Process failed with return code: {exception.returncode}")
Expand Down Expand Up @@ -115,7 +115,8 @@ def install_virtual_env_requirements(project_path: str, virtualenv_path: str):
_process_exec(["uv", "pip", "install",
"-r", requirements_paths[0],
"-r", requirements_paths[1],
"-r", requirements_paths[2]])
"-r", requirements_paths[2]],
cwd=project_path)
with open(marker_path, "w") as marker_file:
marker_file.write(requirements_hash)

Expand All @@ -126,7 +127,7 @@ def _activate_virtualenv(topdir):
if os.environ.get("VIRTUAL_ENV") != virtualenv_path:
if not os.path.exists(virtualenv_path):
print(" * Setting up virtual environment...")
_process_exec(["uv", "venv"])
_process_exec(["uv", "venv"], cwd=topdir)

script_dir = "Scripts" if _is_windows() else "bin"
runpy.run_path(os.path.join(virtualenv_path, script_dir, 'activate_this.py'))
Expand Down

0 comments on commit 0a939cc

Please sign in to comment.