|
38 | 38 |
|
39 | 39 |
|
40 | 40 | class UnityEnvironment(BaseEnv): |
| 41 | + API_VERSION = "API-14" # TODO : REMOVE |
| 42 | + DEFAULT_EDITOR_PORT = 5004 # TODO : REMOVE |
| 43 | + PORT_COMMAND_LINE_ARG = "--mlagents-port" # TODO : REMOVE |
| 44 | + |
| 45 | + @staticmethod # TODO : REMOVE |
| 46 | + def validate_environment_path(env_path: str) -> Optional[str]: |
| 47 | + # Strip out executable extensions if passed |
| 48 | + env_path = ( |
| 49 | + env_path.strip() |
| 50 | + .replace(".app", "") |
| 51 | + .replace(".exe", "") |
| 52 | + .replace(".x86_64", "") |
| 53 | + .replace(".x86", "") |
| 54 | + ) |
| 55 | + true_filename = os.path.basename(os.path.normpath(env_path)) |
| 56 | + logger.debug("The true file name is {}".format(true_filename)) |
| 57 | + |
| 58 | + if not (glob.glob(env_path) or glob.glob(env_path + ".*")): |
| 59 | + return None |
| 60 | + |
| 61 | + cwd = os.getcwd() |
| 62 | + launch_string = None |
| 63 | + true_filename = os.path.basename(os.path.normpath(env_path)) |
| 64 | + if platform == "linux" or platform == "linux2": |
| 65 | + candidates = glob.glob(os.path.join(cwd, env_path) + ".x86_64") |
| 66 | + if len(candidates) == 0: |
| 67 | + candidates = glob.glob(os.path.join(cwd, env_path) + ".x86") |
| 68 | + if len(candidates) == 0: |
| 69 | + candidates = glob.glob(env_path + ".x86_64") |
| 70 | + if len(candidates) == 0: |
| 71 | + candidates = glob.glob(env_path + ".x86") |
| 72 | + if len(candidates) > 0: |
| 73 | + launch_string = candidates[0] |
| 74 | + |
| 75 | + elif platform == "darwin": |
| 76 | + candidates = glob.glob( |
| 77 | + os.path.join(cwd, env_path + ".app", "Contents", "MacOS", true_filename) |
| 78 | + ) |
| 79 | + if len(candidates) == 0: |
| 80 | + candidates = glob.glob( |
| 81 | + os.path.join(env_path + ".app", "Contents", "MacOS", true_filename) |
| 82 | + ) |
| 83 | + if len(candidates) == 0: |
| 84 | + candidates = glob.glob( |
| 85 | + os.path.join(cwd, env_path + ".app", "Contents", "MacOS", "*") |
| 86 | + ) |
| 87 | + if len(candidates) == 0: |
| 88 | + candidates = glob.glob( |
| 89 | + os.path.join(env_path + ".app", "Contents", "MacOS", "*") |
| 90 | + ) |
| 91 | + if len(candidates) > 0: |
| 92 | + launch_string = candidates[0] |
| 93 | + elif platform == "win32": |
| 94 | + candidates = glob.glob(os.path.join(cwd, env_path + ".exe")) |
| 95 | + if len(candidates) == 0: |
| 96 | + candidates = glob.glob(env_path + ".exe") |
| 97 | + if len(candidates) > 0: |
| 98 | + launch_string = candidates[0] |
| 99 | + return launch_string |
| 100 | + # TODO: END REMOVE |
| 101 | + |
41 | 102 | def __init__( |
42 | 103 | self, |
43 | | - executable_name: Optional[str] = None, |
| 104 | + worker_id=None, # TODO : REMOVE |
| 105 | + seed=None, # TODO : REMOVE |
| 106 | + docker_training=None, # TODO : REMOVE |
| 107 | + no_graphics=None, # TODO : REMOVE |
| 108 | + base_port=None, # TODO : REMOVE |
| 109 | + file_name: Optional[str] = None, |
44 | 110 | args: Optional[List[str]] = None, |
45 | 111 | side_channels: Optional[List[SideChannel]] = None, |
46 | 112 | ): |
47 | 113 | """ |
48 | 114 | Starts a new unity environment and establishes a connection with the environment. |
49 | 115 |
|
50 | | - :string executable_name: Name of Unity environment binary. If None, will try to connect to the Editor. |
| 116 | + :string file_name: Name of Unity environment binary. If None, will try to connect to the Editor. |
51 | 117 | :list args: Addition Unity command line arguments |
52 | 118 | :list side_channels: Additional side channel for not-rl communication with Unity |
53 | 119 | """ |
54 | 120 | args = args or [] |
55 | 121 | atexit.register(self.close) |
| 122 | + executable_name = file_name |
56 | 123 |
|
57 | 124 | if executable_name is None: |
58 | 125 | assert args == [] |
|
0 commit comments