From eae9e750183e267809c5f3f709ae4d2db8b61a6d Mon Sep 17 00:00:00 2001 From: derek-hirotsu <132305781+derek-hirotsu@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:35:21 -0800 Subject: [PATCH] misc cleanup (#84) * remove inline pylint * cspell * pylint import * pylint flac * pylint ycruncher --- F1_22/f1.py | 14 +++++--------- F1_23/f1_23.py | 7 ++----- atomic_heart/atomicheart.py | 4 +--- cspell.json | 8 +++++++- cyberpunk2077/cyberpunk2077.py | 4 +--- dota2/dota2.py | 2 +- dota2/dota2_utils.py | 1 - flac/flac.py | 8 +++----- forza5/forza5.py | 5 +---- reddeadredemption2/reddeadredemption2.py | 3 --- returnal/returnal.py | 8 ++------ returnal/returnal_utils.py | 11 ----------- rocket_league/rocket_league.py | 4 ++-- rocket_league/{utils.py => rocket_league_utils.py} | 0 the_last_of_us_part_i/the_last_of_us_part_i.py | 4 +--- total_war_warhammer_iii/twwh3.py | 4 +--- ycruncher/ycruncher.py | 6 ++---- 17 files changed, 29 insertions(+), 64 deletions(-) rename rocket_league/{utils.py => rocket_league_utils.py} (100%) diff --git a/F1_22/f1.py b/F1_22/f1.py index 0a5f679..7f2d0fe 100644 --- a/F1_22/f1.py +++ b/F1_22/f1.py @@ -9,7 +9,6 @@ from f1_22_utils import get_resolution sys.path.insert(1, os.path.join(sys.path[0], "..")) -#pylint: disable=wrong-import-position from harness_utils.keras_service import KerasService from harness_utils.steam import exec_steam_run_command, get_steamapps_common_path from harness_utils.output import ( @@ -22,25 +21,24 @@ from harness_utils.output import ( ) from harness_utils.misc import remove_files from harness_utils.process import terminate_processes -#pylint: enable=wrong-import-position SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") STEAM_GAME_ID = 1692250 VIDEO_PATH = os.path.join(get_steamapps_common_path(), "videos") -skippable = [ +intro_videos = [ os.path.join(VIDEO_PATH, "attract.bk2"), os.path.join(VIDEO_PATH, "cm_f1_sting.bk2"), ] def navigate_overlay(): - """Simulate inputs to navigate ingame overlay.""" - # if steam ingame overlay is disabled it will be a an okay to press + """Simulate inputs to navigate in-game overlay.""" + # if steam in-game overlay is disabled it will be a an okay to press if kerasService.look_for_word("okay", attempts=5, interval=1): user.press("enter") - # if steam ingame overlay is enabled we have to press escape and enter + # if steam in-game overlay is enabled we have to press escape and enter elif kerasService.look_for_word("please", attempts=5, interval=1): user.press("esc") time.sleep(0.5) @@ -102,7 +100,7 @@ def navigate_menu(): def run_benchmark(): """Runs the actual benchmark.""" setup_start_time = time.time() - remove_files(skippable) + remove_files(intro_videos) exec_steam_run_command(STEAM_GAME_ID) time.sleep(20) @@ -174,8 +172,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) - -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/F1_23/f1_23.py b/F1_23/f1_23.py index e986634..27a57fe 100644 --- a/F1_23/f1_23.py +++ b/F1_23/f1_23.py @@ -9,7 +9,6 @@ from f1_23_utils import get_resolution sys.path.insert(1, os.path.join(sys.path[0], "..")) -# pylint: disable=wrong-import-position from harness_utils.steam import exec_steam_run_command, get_app_install_location from harness_utils.keras_service import KerasService from harness_utils.misc import remove_files @@ -22,7 +21,6 @@ from harness_utils.output import ( DEFAULT_LOGGING_FORMAT, DEFAULT_DATE_FORMAT, ) -# pylint: enable=wrong-import-position SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") @@ -30,7 +28,7 @@ PROCESS_NAME = "F1_23" STEAM_GAME_ID = 2108330 VIDEO_PATH = os.path.join(get_app_install_location(STEAM_GAME_ID), "videos") -skippable = [ +intro_videos = [ os.path.join(VIDEO_PATH, "attract.bk2"), os.path.join(VIDEO_PATH, "cm_f1_sting.bk2") ] @@ -159,7 +157,7 @@ def navigate_menu(): def run_benchmark(): """Runs the actual benchmark.""" - remove_files(skippable) + remove_files(intro_videos) exec_steam_run_command(STEAM_GAME_ID) setup_start_time = time.time() time.sleep(2) @@ -232,7 +230,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/atomic_heart/atomicheart.py b/atomic_heart/atomicheart.py index f22c60d..30d6c8f 100644 --- a/atomic_heart/atomicheart.py +++ b/atomic_heart/atomicheart.py @@ -8,7 +8,7 @@ import pydirectinput as user from utils import read_resolution sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position + from harness_utils.steam import exec_steam_run_command, get_app_install_location from harness_utils.misc import remove_files from harness_utils.process import terminate_processes @@ -21,7 +21,6 @@ from harness_utils.output import ( DEFAULT_DATE_FORMAT, ) from harness_utils.keras_service import KerasService -#pylint: enable=wrong-import-position SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") @@ -141,7 +140,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/cspell.json b/cspell.json index 2ebbd69..681a78f 100644 --- a/cspell.json +++ b/cspell.json @@ -10,6 +10,8 @@ "directx", "Dota", "flac", + "Forza", + "fromy", "HIWORD", "Jcraft", "Keras", @@ -20,11 +22,15 @@ "OPTIX", "psutil", "pycache", + "Returnal", "RLCS", + "RTSS", + "tlou", "turbopolsa", "twwh", "Unigine", - "vsix" + "vsix", + "ycruncher" ], "ignoreRegExpList": [ "import .*" diff --git a/cyberpunk2077/cyberpunk2077.py b/cyberpunk2077/cyberpunk2077.py index 803e285..521605b 100644 --- a/cyberpunk2077/cyberpunk2077.py +++ b/cyberpunk2077/cyberpunk2077.py @@ -9,7 +9,7 @@ from cyberpunk_utils import copy_no_intro_mod, get_args, read_current_resolution sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position + from harness_utils.keras_service import KerasService from harness_utils.output import ( setup_log_directory, @@ -19,7 +19,6 @@ from harness_utils.output import ( DEFAULT_DATE_FORMAT) from harness_utils.process import terminate_processes from harness_utils.steam import exec_steam_game -#pylint: enable=wrong-import-position STEAM_GAME_ID = 1091500 SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) @@ -134,7 +133,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/dota2/dota2.py b/dota2/dota2.py index 0c4f58d..963a4b2 100644 --- a/dota2/dota2.py +++ b/dota2/dota2.py @@ -7,7 +7,7 @@ import sys from dota2_utils import console_command, get_resolution, copy_replay, copy_config, get_args sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position + from harness_utils.output import ( setup_log_directory, write_report_json, diff --git a/dota2/dota2_utils.py b/dota2/dota2_utils.py index 3f8badf..3e9ef78 100644 --- a/dota2/dota2_utils.py +++ b/dota2/dota2_utils.py @@ -13,7 +13,6 @@ import sys from pathlib import Path sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position USERNAME = os.getlogin() SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) diff --git a/flac/flac.py b/flac/flac.py index d498468..5c0ad4d 100644 --- a/flac/flac.py +++ b/flac/flac.py @@ -8,7 +8,6 @@ from subprocess import Popen sys.path.insert(1, os.path.join(sys.path[0], "..")) -# pylint: disable=wrong-import-position from flac_utils import download_flac, flac_folder_exists from harness_utils.output import DEFAULT_LOGGING_FORMAT, setup_log_directory @@ -35,9 +34,8 @@ command = f'{ABS_EXECUTABLE_PATH}' command = command.rstrip() start_time = time.time() -process = Popen(executable=command, args=[], - cwd=os.path.dirname(os.path.realpath(__file__))) -EXIT_CODE = process.wait() +with Popen(executable=command, args=[], cwd=script_dir) as process: + EXIT_CODE = process.wait() if EXIT_CODE > 0: logging.error("Test failed!") @@ -48,7 +46,7 @@ score = round((end_time - start_time), 3) logging.info("Benchmark took %s seconds", score) if EXIT_CODE > 0: logging.error("Test failed!") - exit(EXIT_CODE) + sys.exit(EXIT_CODE) report = { "score": score, diff --git a/forza5/forza5.py b/forza5/forza5.py index 4b2cc7f..d4d2465 100644 --- a/forza5/forza5.py +++ b/forza5/forza5.py @@ -10,7 +10,6 @@ from forza5_utils import read_resolution sys.path.insert(1, os.path.join(sys.path[0], '..')) -# pylint: disable=wrong-import-position from harness_utils.output import ( format_resolution, seconds_to_milliseconds, @@ -23,7 +22,6 @@ from harness_utils.process import terminate_processes from harness_utils.rtss import start_rtss_process, copy_rtss_profile from harness_utils.steam import exec_steam_run_command from harness_utils.keras_service import KerasService -# pylint: enable=wrong-import-position STEAM_GAME_ID = 1551360 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) @@ -62,7 +60,7 @@ def run_benchmark(): logging.info("Game didn't start.") sys.exit(1) - logging.info("Accessibilty found pressing X to continue.") + logging.info("Accessibility found pressing X to continue.") user.press("x") time.sleep(2) @@ -148,7 +146,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/reddeadredemption2/reddeadredemption2.py b/reddeadredemption2/reddeadredemption2.py index bfbf11a..43ea87e 100644 --- a/reddeadredemption2/reddeadredemption2.py +++ b/reddeadredemption2/reddeadredemption2.py @@ -9,7 +9,6 @@ from red_dead_redemption_2_utils import get_resolution sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position from harness_utils.output import ( format_resolution, seconds_to_milliseconds, @@ -20,7 +19,6 @@ from harness_utils.output import ( ) from harness_utils.process import terminate_processes from harness_utils.steam import exec_steam_run_command -#pylint: enable=wrong-import-position STEAM_GAME_ID = 1174180 PROCESS_NAME = "RDR2" @@ -93,7 +91,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/returnal/returnal.py b/returnal/returnal.py index f63c5b2..4d0c4e0 100644 --- a/returnal/returnal.py +++ b/returnal/returnal.py @@ -9,7 +9,6 @@ from returnal_utils import get_resolution, get_args sys.path.insert(1, os.path.join(sys.path[0], '..')) -# pylint: disable=wrong-import-position from harness_utils.keras_service import KerasService from harness_utils.output import ( format_resolution, @@ -25,7 +24,6 @@ from harness_utils.steam import ( exec_steam_run_command, get_steamapps_common_path, ) -# pylint: enable=wrong-import-position STEAM_GAME_ID = 1649240 SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) @@ -39,7 +37,7 @@ VIDEO_PATH = os.path.join(get_steamapps_common_path(), "Returnal", "Returnal", " user.FAILSAFE = False -skippable_videos = [ +intro_videos = [ os.path.join(VIDEO_PATH, "Logos_PC.mp4"), os.path.join(VIDEO_PATH, "Logos_PC_UW21.mp4"), os.path.join(VIDEO_PATH, "Logos_PC_UW32.mp4"), @@ -87,7 +85,7 @@ def navigate_options_menu() -> None: def run_benchmark() -> tuple[float]: """Run the benchmark""" logging.info("Removing intro videos") - remove_files(skippable_videos) + remove_files(intro_videos) logging.info("Starting game") exec_steam_run_command(STEAM_GAME_ID) @@ -159,8 +157,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) - -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/returnal/returnal_utils.py b/returnal/returnal_utils.py index 0ecc20d..4141921 100644 --- a/returnal/returnal_utils.py +++ b/returnal/returnal_utils.py @@ -1,6 +1,5 @@ """Utility functions supporting Returnal test script.""" from argparse import ArgumentParser -import os import re @@ -25,16 +24,6 @@ def get_resolution(config_path: str) -> tuple[int]: return (height, width) -def remove_intro_videos(file_paths: list[str]) -> None: - """Removes given video file paths""" - for video in file_paths: - try: - os.remove(video) - except FileNotFoundError: - # If file not found, it has likely already been deleted before. - pass - - def get_args() -> any: """Get command line arguments""" parser = ArgumentParser() diff --git a/rocket_league/rocket_league.py b/rocket_league/rocket_league.py index 7c0ca26..25c7b75 100644 --- a/rocket_league/rocket_league.py +++ b/rocket_league/rocket_league.py @@ -6,10 +6,10 @@ from subprocess import Popen import pyautogui as gui import pydirectinput as user import sys -from utils import get_resolution, copy_replay, find_rocketleague_executable, get_args +from rocket_league_utils import get_resolution, copy_replay, find_rocketleague_executable, get_args sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position + from harness_utils.output import ( setup_log_directory, write_report_json, diff --git a/rocket_league/utils.py b/rocket_league/rocket_league_utils.py similarity index 100% rename from rocket_league/utils.py rename to rocket_league/rocket_league_utils.py diff --git a/the_last_of_us_part_i/the_last_of_us_part_i.py b/the_last_of_us_part_i/the_last_of_us_part_i.py index 5926211..1ec60e5 100644 --- a/the_last_of_us_part_i/the_last_of_us_part_i.py +++ b/the_last_of_us_part_i/the_last_of_us_part_i.py @@ -8,7 +8,7 @@ import pydirectinput as user from the_last_of_us_part_i_utils import get_args, get_resolution sys.path.insert(1, os.path.join(sys.path[0], '..')) -#pylint: disable=wrong-import-position + from harness_utils.keras_service import KerasService from harness_utils.output import ( format_resolution, @@ -23,7 +23,6 @@ from harness_utils.steam import ( get_registry_active_user, exec_steam_run_command, ) -#pylint: enable=wrong-import-position STEAM_GAME_ID = 1888930 SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) @@ -136,7 +135,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/total_war_warhammer_iii/twwh3.py b/total_war_warhammer_iii/twwh3.py index b6fc7e1..9f071c1 100644 --- a/total_war_warhammer_iii/twwh3.py +++ b/total_war_warhammer_iii/twwh3.py @@ -9,7 +9,7 @@ import pydirectinput as user from twwh3_utils import read_current_resolution sys.path.insert(1, os.path.join(sys.path[0], '..')) -# pylint: disable=wrong-import-position + from harness_utils.process import terminate_processes from harness_utils.output import ( format_resolution, @@ -21,7 +21,6 @@ from harness_utils.output import ( ) from harness_utils.steam import get_app_install_location from harness_utils.keras_service import KerasService -# pylint: enable=wrong-import-position SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") @@ -182,7 +181,6 @@ try: } write_report_json(LOG_DIRECTORY, "report.json", report) -#pylint: disable=broad-exception-caught except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) diff --git a/ycruncher/ycruncher.py b/ycruncher/ycruncher.py index b42da1c..8183424 100644 --- a/ycruncher/ycruncher.py +++ b/ycruncher/ycruncher.py @@ -9,10 +9,8 @@ from subprocess import Popen sys.path.insert(1, os.path.join(sys.path[0], "..")) -# pylint: disable=wrong-import-position from ycruncher_utils import YCRUNCHER_FOLDER_NAME, download_ycruncher, ycruncher_folder_exists - ABS_EXECUTABLE_PATH = os.path.join(os.path.dirname( os.path.realpath(__file__)), YCRUNCHER_FOLDER_NAME, "y-cruncher.exe") @@ -42,8 +40,8 @@ arg_string = ['skip-warnings', 'bench', '5b', '-o', os.path.join(os.path.dirname(os.path.realpath(__file__)), 'run')] logging.info(arg_string) -process = Popen(executable=command, args=arg_string) -EXIT_CODE = process.wait() +with Popen(executable=command, args=arg_string) as process: + EXIT_CODE = process.wait() if EXIT_CODE > 0: logging.error("Test failed!")