-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
179 lines (152 loc) · 6.26 KB
/
setup.py
File metadata and controls
179 lines (152 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python3
"""Clean setup.py for MineDojo using gymnasium instead of gym."""
import os
import sys
import subprocess
import pathlib
from setuptools import setup, find_packages
from setuptools.command.install import install
from setuptools.command.develop import develop
PKG_NAME = "minedojo"
VERSION = "0.1.1"
def _read_file(fname):
with pathlib.Path(fname).open() as fp:
return fp.read()
def _read_install_requires():
"""Read requirements from requirements.txt."""
requirements = []
with pathlib.Path("requirements.txt").open() as fp:
for line in fp:
line = line.strip()
if line and not line.startswith('#'):
requirements.append(line)
return requirements
def check_java():
"""Check if Java 8 is installed and accessible."""
try:
result = subprocess.run(['java', '-version'], capture_output=True, text=True)
if 'version "1.8' in result.stderr or 'openjdk version "1.8' in result.stderr:
return True
print("WARNING: Java 8 not found. MineDojo requires Java 8.")
print("Please install Java 8:")
print(" Ubuntu/Debian: sudo apt-get install openjdk-8-jdk")
print(" Arch Linux: sudo pacman -S jdk8-openjdk")
print(" macOS: brew install openjdk@8")
return False
except FileNotFoundError:
print("WARNING: Java not found. MineDojo requires Java 8.")
return False
def patch_numpy_compatibility():
"""Patch MineDojo's spaces.py for NumPy 2.0 compatibility if needed."""
spaces_py = pathlib.Path(__file__).parent / "minedojo" / "sim" / "spaces.py"
if spaces_py.exists():
with open(spaces_py, 'r') as f:
content = f.read()
# Replace np.unicode_ with np.str_ if needed
if 'np.unicode_' in content:
print("Patching spaces.py for NumPy 2.0 compatibility...")
content = content.replace('np.unicode_', 'np.str_')
with open(spaces_py, 'w') as f:
f.write(content)
print("spaces.py patched successfully.")
def setup_mixingradle():
"""Clone the MixinGradle repository and patch build.gradle if needed."""
# Create libs directory
libs_dir = pathlib.Path(__file__).parent / "libs"
libs_dir.mkdir(exist_ok=True)
# Clone MixinGradle if not exists
mixingradle_dir = libs_dir / "MixinGradle-dcfaf61"
if not mixingradle_dir.exists():
print("Setting up MixinGradle...")
subprocess.run([
"git", "clone",
"https://github.com/verityw/MixinGradle-dcfaf61.git",
str(mixingradle_dir)
], check=True)
# Patch build.gradle
build_gradle = pathlib.Path(__file__).parent / "minedojo" / "sim" / "Malmo" / "Minecraft" / "build.gradle"
if build_gradle.exists():
with open(build_gradle, 'r') as f:
content = f.read()
# Check if already patched
if 'file:///' not in content:
print("Patching build.gradle...")
# Find the buildscript repositories block and add local maven repo
lines = content.split('\n')
new_lines = []
in_buildscript = False
in_repositories = False
indent = ''
for i, line in enumerate(lines):
new_lines.append(line)
if 'buildscript {' in line:
in_buildscript = True
elif in_buildscript and 'repositories {' in line:
in_repositories = True
# Get indentation
indent = line[:line.index('repositories')]
elif in_repositories and 'maven {' in line and i < 20:
# Add our local maven repo after the first maven repo
new_lines.append(f'{indent} maven {{')
new_lines.append(f'{indent} url \'file:///{libs_dir.absolute()}\'')
new_lines.append(f'{indent} }}')
in_repositories = False
in_buildscript = False
content = '\n'.join(new_lines)
# Change the classpath
content = content.replace(
"classpath('com.github.SpongePowered:MixinGradle:dcfaf61')",
"classpath('MixinGradle-dcfaf61:MixinGradle:dcfaf61')"
)
with open(build_gradle, 'w') as f:
f.write(content)
print("build.gradle patched successfully.")
class CustomInstallCommand(install):
"""Custom installation command that applies necessary patches."""
def run(self):
# Check Java
check_java()
# Run standard install
install.run(self)
# Apply post-install patches
patch_numpy_compatibility()
setup_mixingradle()
class CustomDevelopCommand(develop):
"""Custom develop command that applies necessary patches."""
def run(self):
# Check Java
check_java()
# Run standard develop
develop.run(self)
# Apply post-install patches
patch_numpy_compatibility()
setup_mixingradle()
setup(
name=PKG_NAME,
version=VERSION,
author="MineDojo Team",
url="http://github.com/MineDojo/MineDojo",
description="Building AI Agents with Internet-Scale Knowledge in Minecraft",
long_description=_read_file("README.md"),
long_description_content_type="text/markdown",
keywords=["Deep Learning", "Machine Learning", "Minecraft", "RL", "Gymnasium"],
license="MIT License",
packages=find_packages(include=[f"{PKG_NAME}", f"{PKG_NAME}.*"]),
include_package_data=True,
zip_safe=False,
install_requires=_read_install_requires(),
python_requires=">=3.9,<3.13",
cmdclass={
'install': CustomInstallCommand,
'develop': CustomDevelopCommand,
},
classifiers=[
"Development Status :: 4 - Beta",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Environment :: Console",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)