Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

62 行
1.8 KiB

#!/usr/bin/env python
import os
import sys
from typing import Dict
import argparse
VERSION_LINE_START = "__version__ = "
DIRECTORIES = [
"ml-agents/mlagents/trainers",
"ml-agents-envs/mlagents/envs",
"gym-unity/gym_unity",
]
def extract_version_string(filename):
with open(filename) as f:
for l in f.readlines():
if l.startswith(VERSION_LINE_START):
return l.replace(VERSION_LINE_START, "").strip()
return None
def check_versions() -> bool:
version_by_dir: Dict[str, str] = {}
for directory in DIRECTORIES:
path = os.path.join(directory, "__init__.py")
version = extract_version_string(path)
print(f"Found version {version} for {directory}")
version_by_dir[directory] = version
# Make sure we have exactly one version, and it's not none
versions = set(version_by_dir.values())
if len(versions) != 1 or None in versions:
print("Each setup.py must have the same VERSION string.")
return False
return True
def set_version(new_version: str) -> None:
new_contents = f'{VERSION_LINE_START}"{new_version}"\n'
for directory in DIRECTORIES:
path = os.path.join(directory, "__init__.py")
print(f"Setting {path} to version {new_version}")
with open(path, "w") as f:
f.write(new_contents)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--new-version", default=None)
# unused, but allows precommit to pass filenames
parser.add_argument("files", nargs="*")
args = parser.parse_args()
if args.new_version:
print(f"Updating to verison {args.new_version}")
set_version(args.new_version)
else:
ok = check_versions()
return_code = 0 if ok else 1
sys.exit(return_code)