Skip to content

Commit 6991f00

Browse files
authored
Moving the install and upgrade logic into a python script. (#7)
1 parent c6f51ff commit 6991f00

4 files changed

Lines changed: 43 additions & 46 deletions

File tree

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Include everything the framework requires
22
# You will automatically get updates for all versions starting with "1.".
33
rlbot==1.*
4+
5+
# This will cause pip to auto-upgrade and stop scaring people with warning messages
6+
pip

run-gui.bat

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,4 @@ cd /D "%~dp0"
66
@rem Make sure the environment variables are up-to-date. This is useful if the user installed python a moment ago.
77
call ./RefreshEnv.cmd
88

9-
setlocal EnableDelayedExpansion
10-
11-
@rem Run the is_safe_to_upgrade function and save the output to a temp file.
12-
python -c "from rlbot.utils import public_utils; print(public_utils.is_safe_to_upgrade());" > %temp%\is_safe_to_upgrade.txt
13-
14-
IF %ERRORLEVEL% NEQ 0 (
15-
@rem The python command failed, so rlbot is probably not installed at all. Safe to 'upgrade'.
16-
set is_safe_to_upgrade=True
17-
) ELSE (
18-
@rem read the file containing the python output.
19-
set /p is_safe_to_upgrade= < %temp%\is_safe_to_upgrade.txt
20-
)
21-
del %temp%\is_safe_to_upgrade.txt
22-
23-
IF "!is_safe_to_upgrade!"=="True" (
24-
python -m pip install -r requirements.txt --upgrade
25-
) ELSE (
26-
echo Will not attempt to upgrade rlbot because files are in use.
27-
)
28-
29-
python -c "from rlbot.gui.qt_root import RLBotQTGui; RLBotQTGui.main();"
30-
31-
pause
9+
python run.py gui

run.bat

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,4 @@ cd /D "%~dp0"
66
@rem Make sure the environment variables are up-to-date. This is useful if the user installed python a moment ago.
77
call ./RefreshEnv.cmd
88

9-
setlocal EnableDelayedExpansion
10-
11-
@rem Run the is_safe_to_upgrade function and save the output to a temp file.
12-
python -c "from rlbot.utils import public_utils; print(public_utils.is_safe_to_upgrade());" > %temp%\is_safe_to_upgrade.txt
13-
14-
IF %ERRORLEVEL% NEQ 0 (
15-
@rem The python command failed, so rlbot is probably not installed at all. Safe to 'upgrade'.
16-
set is_safe_to_upgrade=True
17-
) ELSE (
18-
@rem read the file containing the python output.
19-
set /p is_safe_to_upgrade= < %temp%\is_safe_to_upgrade.txt
20-
)
21-
del %temp%\is_safe_to_upgrade.txt
22-
23-
IF "!is_safe_to_upgrade!"=="True" (
24-
python -m pip install -r requirements.txt --upgrade
25-
) ELSE (
26-
echo Will not attempt to upgrade rlbot because files are in use.
27-
)
28-
29-
python -c "from rlbot import runner; runner.main();"
30-
31-
pause
9+
python run.py

run.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# https://stackoverflow.com/a/51704613
2+
try:
3+
from pip import main as pipmain
4+
except ImportError:
5+
from pip._internal import main as pipmain
6+
7+
8+
# https://stackoverflow.com/a/24773951
9+
def install_and_import(package):
10+
import importlib
11+
12+
try:
13+
importlib.import_module(package)
14+
except ImportError:
15+
pipmain(['install', package])
16+
finally:
17+
globals()[package] = importlib.import_module(package)
18+
19+
20+
if __name__ == '__main__':
21+
install_and_import('rlbot')
22+
from rlbot.utils import public_utils
23+
24+
if public_utils.is_safe_to_upgrade():
25+
pipmain(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager'])
26+
27+
try:
28+
import sys
29+
if len(sys.argv) > 1 and sys.argv[1] == 'gui':
30+
from rlbot.gui.qt_root import RLBotQTGui
31+
RLBotQTGui.main()
32+
else:
33+
from rlbot import runner
34+
runner.main()
35+
except Exception as e:
36+
print("Encountered exception: ", e)
37+
print("Press enter to close.")
38+
input()

0 commit comments

Comments
 (0)