Skip to content

Commit 2266494

Browse files
committed
Add executable mx.py to repo root
Many places assume that there is an `mx.py` at the repo root that will run mx. The new mx.py is a stub that simply manipulates the path and then runs the mx module
1 parent c25d93a commit 2266494

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

mx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,4 @@ if [ $? -ne 0 ]; then
7676
exit 1
7777
fi
7878

79-
# Include the parent directory of this script in the python path variable, then
80-
# allow loading of the mx module
81-
export PYTHONPATH="$dir/src:$PYTHONPATH"
82-
83-
# The following allows the use of existing module names
84-
export PYTHONPATH="$dir/oldnames:$PYTHONPATH"
85-
86-
exec $python_exe -u -m mx "$@"
79+
exec $python_exe -u "$dir/mx.py" "$@"

mx.cmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ if defined MX_PYTHON (
1010
set "python_exe=python"
1111
)
1212

13-
set "PYTHONPATH=%~dp0/src;%~dp0/oldnames"
14-
1513
:: local variables can be used after endlocal if on the same line
16-
endlocal & "%python_exe%" -u -m mx %*
14+
endlocal & "%python_exe%" -u "%~dp0mx.py" %*

mx.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
"""
3+
Main entry point for running mx.
4+
"""
5+
6+
import sys
7+
import runpy
8+
from pathlib import Path
9+
10+
11+
def patch_path():
12+
"""
13+
Prepends the location of the main mx package as well as the `oldnames`
14+
directory to `sys.path`.
15+
16+
We prepend because otherwise this file is recognized as the `mx` module and
17+
not `src/mx`.
18+
"""
19+
base_dir = Path(__file__).parent.absolute()
20+
# Include the parent directory of this script in the python path variable,
21+
# then allow loading of the mx module
22+
sys.path.insert(0, str(base_dir / 'src'))
23+
# The following allows the use of existing module names
24+
sys.path.insert(0, str(base_dir / 'oldnames'))
25+
26+
27+
if __name__ == "__main__":
28+
patch_path()
29+
runpy.run_module("mx")

src/mx/_impl/mx.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13781,10 +13781,9 @@ def run_mx(args, suite=None, mxpy=None, nonZeroIsFatal=True, out=None, err=None,
1378113781
:param suite: the primary suite or primary suite directory to use
1378213782
:param str mxpy: path the mx module to run (None to use the current mx module)
1378313783
"""
13784-
if mxpy is not None:
13785-
# TODO GR-42789 Figure out how to deal with this argument
13786-
abort(f"mx.run_mx currently does not support custom mxpy {mxpy}")
13787-
commands = [get_mx_path(), '--java-home=' + get_jdk().home]
13784+
if mxpy is None:
13785+
mxpy = join(_mx_home, 'mx.py')
13786+
commands = [sys.executable, '-u', mxpy, '--java-home=' + get_jdk().home]
1378813787
cwd = None
1378913788
if suite:
1379013789
if isinstance(suite, str):

0 commit comments

Comments
 (0)