| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| """Install script for setuptools.""" |
|
|
| import fnmatch |
| import logging |
| import os |
| import platform |
| import subprocess |
| import sys |
|
|
| import mujoco |
| import setuptools |
| from setuptools import find_packages |
| from setuptools import setup |
| from setuptools.command import install |
|
|
| PLATFORM = platform.system() |
|
|
| |
| AUTOWRAP_PATH = 'dm_control/autowrap/autowrap.py' |
| MJBINDINGS_DIR = 'dm_control/mujoco/wrapper/mjbindings' |
|
|
| |
| |
| |
| HEADER_FILENAMES = [ |
| 'mjdata.h', |
| 'mjmodel.h', |
| 'mjrender.h', |
| 'mjtype.h', |
| 'mjui.h', |
| 'mjvisualize.h', |
| 'mjxmacro.h', |
| 'mujoco.h', |
| ] |
|
|
|
|
| def _initialize_mjbindings_options(cmd_instance): |
| """Set default values for options relating to `build_mjbindings`.""" |
| |
| cmd_instance.inplace = 0 |
| cmd_instance.headers_dir = mujoco.HEADERS_DIR |
|
|
|
|
| def _finalize_mjbindings_options(cmd_instance): |
| """Post-process options relating to `build_mjbindings`.""" |
| headers_dir = os.path.expanduser(cmd_instance.headers_dir) |
| header_paths = [] |
| for filename in HEADER_FILENAMES: |
| full_path = os.path.join(headers_dir, filename) |
| if not os.path.exists(full_path): |
| raise IOError('Header file {!r} does not exist.'.format(full_path)) |
| header_paths.append(full_path) |
| cmd_instance.header_paths = ' '.join(header_paths) |
|
|
|
|
| class BuildMJBindingsCommand(setuptools.Command): |
| """Runs `autowrap.py` to generate the low-level ctypes bindings for MuJoCo.""" |
|
|
| description = __doc__ |
| user_options = [ |
| |
| ('headers-dir=', None, 'Path to directory containing MuJoCo headers.'), |
| ( |
| 'inplace=', |
| None, |
| 'Place generated files in source directory rather than `build-lib`.', |
| ), |
| ] |
| boolean_options = ['inplace'] |
|
|
| def initialize_options(self): |
| _initialize_mjbindings_options(self) |
|
|
| def finalize_options(self): |
| _finalize_mjbindings_options(self) |
|
|
| def run(self): |
| cwd = os.path.realpath(os.curdir) |
| if self.inplace: |
| dist_root = cwd |
| else: |
| build_cmd = self.get_finalized_command('build') |
| dist_root = os.path.realpath(build_cmd.build_lib) |
| output_dir = os.path.join(dist_root, MJBINDINGS_DIR) |
| command = [ |
| sys.executable or 'python', |
| AUTOWRAP_PATH, |
| '--header_paths={}'.format(self.header_paths), |
| '--output_dir={}'.format(output_dir), |
| ] |
| self.announce('Running command: {}'.format(command), level=logging.DEBUG) |
| try: |
| |
| |
| old_environ = os.environ.copy() |
| new_pythonpath = [cwd] |
| if 'PYTHONPATH' in old_environ: |
| new_pythonpath.append(old_environ['PYTHONPATH']) |
| os.environ['PYTHONPATH'] = ':'.join(new_pythonpath) |
| subprocess.check_call(command) |
| finally: |
| os.environ = old_environ |
|
|
|
|
| class InstallCommand(install.install): |
| """Runs 'build_mjbindings' before installation.""" |
|
|
| user_options = ( |
| install.install.user_options + BuildMJBindingsCommand.user_options |
| ) |
| boolean_options = ( |
| install.install.boolean_options + BuildMJBindingsCommand.boolean_options |
| ) |
|
|
| def initialize_options(self): |
| install.install.initialize_options(self) |
| _initialize_mjbindings_options(self) |
|
|
| def finalize_options(self): |
| install.install.finalize_options(self) |
| _finalize_mjbindings_options(self) |
|
|
| def run(self): |
| self.reinitialize_command('build_mjbindings') |
| self.run_command('build_mjbindings') |
| install.install.run(self) |
|
|
|
|
| def find_data_files(package_dir, patterns, excludes=()): |
| """Recursively finds files whose names match the given shell patterns.""" |
| paths = set() |
|
|
| def is_excluded(s): |
| for exclude in excludes: |
| if fnmatch.fnmatch(s, exclude): |
| return True |
| return False |
|
|
| for directory, _, filenames in os.walk(package_dir): |
| if is_excluded(directory): |
| continue |
| for pattern in patterns: |
| for filename in fnmatch.filter(filenames, pattern): |
| |
| relative_dirpath = os.path.relpath(directory, package_dir) |
| full_path = os.path.join(relative_dirpath, filename) |
| if not is_excluded(full_path): |
| paths.add(full_path) |
| return list(paths) |
|
|
|
|
| setup( |
| name='dm_control', |
| version='1.0.42', |
| description='Continuous control environments and MuJoCo Python bindings.', |
| long_description=""" |
| # `dm_control`: DeepMind Infrastructure for Physics-Based Simulation. |
| |
| DeepMind's software stack for physics-based simulation and Reinforcement |
| Learning environments, using MuJoCo physics. |
| |
| An **introductory tutorial** for this package is available as a Colaboratory |
| notebook: [Open In Google Colab](https://colab.research.google.com/github/google-deepmind/dm_control/blob/main/tutorial.ipynb). |
| """, |
| long_description_content_type='text/markdown', |
| author='DeepMind', |
| author_email='mujoco@deepmind.com', |
| url='https://github.com/google-deepmind/dm_control', |
| license='Apache-2.0', |
| keywords='machine learning control physics MuJoCo AI', |
| python_requires='>=3.9', |
| install_requires=[ |
| 'absl-py>=0.7.0', |
| 'dm-env', |
| 'dm-tree != 0.1.2', |
| 'glfw', |
| 'labmaze', |
| 'lxml', |
| 'mujoco >= 3.9.0', |
| 'numpy >= 1.9.0', |
| 'protobuf >= 3.19.4', |
| 'pyopengl >= 3.1.4', |
| 'pyparsing >= 3.0.0', |
| 'requests', |
| 'setuptools!=50.0.0', |
| 'scipy', |
| 'tqdm', |
| ], |
| extras_require={ |
| 'HDF5': ['h5py'], |
| }, |
| tests_require=[ |
| 'mock', |
| 'pytest', |
| 'pillow>=10.2.0', |
| ], |
| packages=find_packages(), |
| package_data={ |
| 'dm_control': find_data_files( |
| package_dir='dm_control', |
| patterns=[ |
| '*.amc', |
| '*.msh', |
| '*.png', |
| '*.skn', |
| '*.stl', |
| '*.xml', |
| '*.textproto', |
| '*.h5', |
| '*.zip', |
| ], |
| excludes=[ |
| '*/dog_assets/extras/*', |
| '*/kinova/meshes/*', |
| ], |
| ), |
| }, |
| cmdclass={ |
| 'build_mjbindings': BuildMJBindingsCommand, |
| 'install': InstallCommand, |
| }, |
| entry_points={}, |
| ) |
|
|