Skip to content

Commit 14aefea

Browse files
committed
Detecting gaps in requirements.txt and offering to install.
1 parent 2885c28 commit 14aefea

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

rlbot_gui/gui.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
from pathlib import Path
34

45
import eel
56
from PyQt5.QtCore import QSettings
@@ -8,14 +9,16 @@
89
from rlbot.parsing.agent_config_parser import create_looks_configurations, BOT_CONFIG_LOADOUT_HEADER, \
910
BOT_CONFIG_LOADOUT_ORANGE_HEADER, BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER, BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER, \
1011
load_bot_appearance
11-
from rlbot.parsing.bot_config_bundle import get_bot_config_bundle, get_script_config_bundle, RunnableConfigBundle
12+
from rlbot.parsing.bot_config_bundle import get_bot_config_bundle, get_script_config_bundle, RunnableConfigBundle, \
13+
BotConfigBundle
1214
from rlbot.parsing.directory_scanner import scan_directory_for_bot_configs, scan_directory_for_script_configs
1315
from rlbot.parsing.match_settings_config_parser import map_types, game_mode_types, \
1416
boost_amount_mutator_types, match_length_types, max_score_types, overtime_mutator_types, \
1517
series_length_mutator_types, game_speed_mutator_types, ball_max_speed_mutator_types, ball_type_mutator_types, \
1618
ball_weight_mutator_types, ball_size_mutator_types, ball_bounciness_mutator_types, rumble_mutator_types, \
1719
boost_strength_mutator_types, gravity_mutator_types, demolish_mutator_types, respawn_time_mutator_types, \
1820
existing_match_behavior_types
21+
from rlbot.utils.requirements_management import install_requirements_file
1922

2023
from rlbot_gui.bot_management.bot_creation import bootstrap_python_bot, bootstrap_scratch_bot, \
2124
bootstrap_python_hivemind, convert_to_filename
@@ -68,7 +71,7 @@ def pick_bot_folder():
6871
return []
6972

7073

71-
def serialize_bundle(bundle):
74+
def serialize_bundle(bundle: BotConfigBundle):
7275
return {
7376
'name': bundle.name,
7477
'type': 'rlbot',
@@ -77,7 +80,8 @@ def serialize_bundle(bundle):
7780
'path': bundle.config_path,
7881
'looks_path': bundle.looks_path,
7982
'info': read_info(bundle),
80-
'logo': try_copy_logo(bundle)
83+
'logo': try_copy_logo(bundle),
84+
'missing_python_packages': [r.name for r in bundle.get_missing_python_packages()],
8185
}
8286

8387

@@ -88,7 +92,8 @@ def serialize_script_bundle(bundle):
8892
'image': 'imgs/rlbot.png',
8993
'path': bundle.config_path,
9094
'info': read_info(bundle),
91-
'logo': try_copy_logo(bundle)
95+
'logo': try_copy_logo(bundle),
96+
'missing_python_packages': [r.name for r in bundle.get_missing_python_packages()],
9297
}
9398

9499

@@ -374,6 +379,20 @@ def install_package(package_string):
374379
return {'exitCode': exit_code, 'package': package_string}
375380

376381

382+
@eel.expose
383+
def install_requirements(config_path):
384+
try:
385+
bundle = get_bot_config_bundle(config_path)
386+
except Exception:
387+
bundle = get_script_config_bundle(config_path)
388+
389+
if bundle.requirements_file:
390+
exit_code = install_requirements_file(bundle.requirements_file)
391+
return {'exitCode': exit_code, 'package': bundle.requirements_file}
392+
else:
393+
return {'exitCode': 1, 'package': None}
394+
395+
377396
def get_last_botpack_commit_id():
378397
url = f'https://api.github.com/repos/{BOTPACK_REPO_OWNER}/{BOTPACK_REPO_NAME}/branches/{BOTPACK_REPO_BRANCH}'
379398
try:

rlbot_gui/gui/main.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@
116116
</draggable>
117117
<md-card class="bot-card md-elevation-3" v-for="script in scriptPool">
118118
<md-switch v-model="script.enabled">{{script.name}}</md-switch>
119+
<md-button class="md-icon-button md-dense warning-icon" v-if="script.warn"
120+
@click.stop="activeBot = script; showLanguageWarning = true;">
121+
<md-icon>warning</md-icon>
122+
</md-button>
119123
<md-button class="md-icon-button md-dense bot-hover-reveal" v-if="script.info"
120124
@click.stop="activeBot = script; showBotInfo = true;">
121125
<md-icon>blur_on</md-icon>
@@ -338,6 +342,14 @@
338342
<a href="https://www.google.com/chrome/" target="_blank">download it here</a>.
339343
</p>
340344
</div>
345+
<div v-if="activeBot.warn === 'pythonpkg'">
346+
<p>
347+
This bot needs some python packages you haven't installed yet:
348+
<code><span v-for="missing in activeBot.missing_python_packages">{{missing}} </span></code>
349+
</p>
350+
<md-button @click="installRequirements(activeBot.path)"
351+
class="md-primary md-raised">Install Now</md-button>
352+
</div>
341353
</md-dialog-content>
342354

343355
<md-dialog-actions>
@@ -675,13 +687,13 @@
675687
freshScripts.forEach((script) => {script.enabled = !!this.matchSettings.scripts.find( (element) => element.path === script.path )});
676688
677689
this.scriptPool = this.scriptPool.concat(freshScripts).sort((a, b) => a.name.localeCompare(b.name));
678-
690+
this.applyLanguageWarnings();
679691
this.showProgressSpinner = false;
680692
},
681693
682694
applyLanguageWarnings: function () {
683695
if (this.languageSupport) {
684-
this.botPool.forEach((bot) => {
696+
this.botPool.concat(this.scriptPool).forEach((bot) => {
685697
if (bot.info && bot.info.language) {
686698
const language = bot.info.language.toLowerCase();
687699
if (!this.languageSupport.java && language.match(/java|kotlin|scala/)) {
@@ -691,6 +703,10 @@
691703
bot.warn = 'chrome';
692704
}
693705
}
706+
console.log(bot);
707+
if (bot.missing_python_packages && bot.missing_python_packages.length > 0) {
708+
bot.warn = 'pythonpkg';
709+
}
694710
});
695711
}
696712
},
@@ -741,6 +757,10 @@
741757
this.showProgressSpinner = true;
742758
eel.install_package(this.packageString)(this.onInstallationComplete);
743759
},
760+
installRequirements: function (configPath) {
761+
this.showProgressSpinner = true;
762+
eel.install_requirements(configPath)(this.onInstallationComplete);
763+
}
744764
},
745765
created: function () {
746766
eel.get_folder_settings()(this.folderSettingsReceived);

0 commit comments

Comments
 (0)