Add pyink and isort config. Reformat.
PiperOrigin-RevId: 704533915 Change-Id: I37e9fd51261bd166b725c7460fc65d02fed2b391
This commit is contained in:
committed by
Copybara-Service
parent
6f6244b739
commit
f3b3024291
+63
-40
@@ -101,15 +101,15 @@ def tokenize_quoted_substr(input_string, quote_char, placeholders=None):
|
||||
placeholders = placeholders if placeholders is not None else dict()
|
||||
prev_end = -1
|
||||
for start, end in start_and_end(quote_positions):
|
||||
output_string += input_string[prev_end+1:start]
|
||||
output_string += input_string[prev_end + 1 : start]
|
||||
while True:
|
||||
placeholder = ''.join(random.choices(string.ascii_lowercase, k=5))
|
||||
if placeholder not in input_string and placeholder not in output_string:
|
||||
break
|
||||
output_string += placeholder
|
||||
placeholders[placeholder] = input_string[start+1:end]
|
||||
placeholders[placeholder] = input_string[start + 1 : end]
|
||||
prev_end = end
|
||||
output_string += input_string[prev_end+1:]
|
||||
output_string += input_string[prev_end + 1 :]
|
||||
|
||||
return output_string, placeholders
|
||||
|
||||
@@ -145,15 +145,17 @@ class BuildCMakeExtension(build_ext.build_ext):
|
||||
"""Uses CMake to build extensions."""
|
||||
|
||||
def run(self):
|
||||
self._is_apple = (platform.system() == 'Darwin')
|
||||
(self._mujoco_library_path,
|
||||
self._mujoco_include_path,
|
||||
self._mujoco_plugins_path,
|
||||
self._mujoco_framework_path) = self._find_mujoco()
|
||||
self._is_apple = platform.system() == 'Darwin'
|
||||
(
|
||||
self._mujoco_library_path,
|
||||
self._mujoco_include_path,
|
||||
self._mujoco_plugins_path,
|
||||
self._mujoco_framework_path,
|
||||
) = self._find_mujoco()
|
||||
self._configure_cmake()
|
||||
for ext in self.extensions:
|
||||
assert ext.name.startswith(EXT_PREFIX)
|
||||
assert '.' not in ext.name[len(EXT_PREFIX):]
|
||||
assert '.' not in ext.name[len(EXT_PREFIX) :]
|
||||
self.build_extension(ext)
|
||||
self._copy_external_libraries()
|
||||
self._copy_mujoco_headers()
|
||||
@@ -163,20 +165,22 @@ class BuildCMakeExtension(build_ext.build_ext):
|
||||
|
||||
def _find_mujoco(self):
|
||||
if MUJOCO_PATH not in os.environ:
|
||||
raise RuntimeError(
|
||||
f'{MUJOCO_PATH} environment variable is not set')
|
||||
raise RuntimeError(f'{MUJOCO_PATH} environment variable is not set')
|
||||
if MUJOCO_PLUGIN_PATH not in os.environ:
|
||||
raise RuntimeError(
|
||||
f'{MUJOCO_PLUGIN_PATH} environment variable is not set')
|
||||
f'{MUJOCO_PLUGIN_PATH} environment variable is not set'
|
||||
)
|
||||
library_path = None
|
||||
include_path = None
|
||||
plugin_path = os.environ[MUJOCO_PLUGIN_PATH]
|
||||
for directory, subdirs, filenames in os.walk(os.environ[MUJOCO_PATH]):
|
||||
if self._is_apple and 'mujoco.framework' in subdirs:
|
||||
return (os.path.join(directory, 'mujoco.framework/Versions/A'),
|
||||
os.path.join(directory, 'mujoco.framework/Headers'),
|
||||
plugin_path,
|
||||
directory)
|
||||
return (
|
||||
os.path.join(directory, 'mujoco.framework/Versions/A'),
|
||||
os.path.join(directory, 'mujoco.framework/Headers'),
|
||||
plugin_path,
|
||||
directory,
|
||||
)
|
||||
if fnmatch.filter(filenames, get_mujoco_lib_pattern()):
|
||||
library_path = directory
|
||||
if os.path.exists(os.path.join(directory, 'mujoco/mujoco.h')):
|
||||
@@ -190,63 +194,78 @@ class BuildCMakeExtension(build_ext.build_ext):
|
||||
for directory, _, filenames in os.walk(os.environ[MUJOCO_PATH]):
|
||||
for pattern in get_external_lib_patterns():
|
||||
for filename in fnmatch.filter(filenames, pattern):
|
||||
shutil.copyfile(os.path.join(directory, filename),
|
||||
os.path.join(dst, filename))
|
||||
shutil.copyfile(
|
||||
os.path.join(directory, filename), os.path.join(dst, filename)
|
||||
)
|
||||
|
||||
def _copy_plugin_libraries(self):
|
||||
dst = os.path.join(
|
||||
os.path.dirname(self.get_ext_fullpath(self.extensions[0].name)),
|
||||
'plugin')
|
||||
'plugin',
|
||||
)
|
||||
os.makedirs(dst)
|
||||
for directory, _, filenames in os.walk(self._mujoco_plugins_path):
|
||||
for pattern in get_plugin_lib_patterns():
|
||||
for filename in fnmatch.filter(filenames, pattern):
|
||||
shutil.copyfile(os.path.join(directory, filename),
|
||||
os.path.join(dst, filename))
|
||||
shutil.copyfile(
|
||||
os.path.join(directory, filename), os.path.join(dst, filename)
|
||||
)
|
||||
|
||||
def _copy_mujoco_headers(self):
|
||||
dst = os.path.join(
|
||||
os.path.dirname(self.get_ext_fullpath(self.extensions[0].name)),
|
||||
'include/mujoco')
|
||||
'include/mujoco',
|
||||
)
|
||||
os.makedirs(dst)
|
||||
for directory, _, filenames in os.walk(self._mujoco_include_path):
|
||||
for filename in fnmatch.filter(filenames, '*.h'):
|
||||
shutil.copyfile(os.path.join(directory, filename),
|
||||
os.path.join(dst, filename))
|
||||
shutil.copyfile(
|
||||
os.path.join(directory, filename), os.path.join(dst, filename)
|
||||
)
|
||||
|
||||
def _copy_mjpython(self):
|
||||
src_dir = os.path.join(os.path.dirname(__file__), 'mujoco/mjpython')
|
||||
dst_contents_dir = os.path.join(
|
||||
os.path.dirname(self.get_ext_fullpath(self.extensions[0].name)),
|
||||
'MuJoCo_(mjpython).app/Contents')
|
||||
'MuJoCo_(mjpython).app/Contents',
|
||||
)
|
||||
os.makedirs(dst_contents_dir)
|
||||
shutil.copyfile(os.path.join(src_dir, 'Info.plist'),
|
||||
os.path.join(dst_contents_dir, 'Info.plist'))
|
||||
shutil.copyfile(
|
||||
os.path.join(src_dir, 'Info.plist'),
|
||||
os.path.join(dst_contents_dir, 'Info.plist'),
|
||||
)
|
||||
|
||||
dst_bin_dir = os.path.join(dst_contents_dir, 'MacOS')
|
||||
os.makedirs(dst_bin_dir)
|
||||
shutil.copyfile(os.path.join(self.build_temp, 'mjpython'),
|
||||
os.path.join(dst_bin_dir, 'mjpython'))
|
||||
shutil.copyfile(
|
||||
os.path.join(self.build_temp, 'mjpython'),
|
||||
os.path.join(dst_bin_dir, 'mjpython'),
|
||||
)
|
||||
os.chmod(os.path.join(dst_bin_dir, 'mjpython'), 0o755)
|
||||
|
||||
dst_resources_dir = os.path.join(dst_contents_dir, 'Resources')
|
||||
os.makedirs(dst_resources_dir)
|
||||
shutil.copyfile(os.path.join(src_dir, 'mjpython.icns'),
|
||||
os.path.join(dst_resources_dir, 'mjpython.icns'))
|
||||
shutil.copyfile(
|
||||
os.path.join(src_dir, 'mjpython.icns'),
|
||||
os.path.join(dst_resources_dir, 'mjpython.icns'),
|
||||
)
|
||||
|
||||
def _configure_cmake(self):
|
||||
"""Check for CMake."""
|
||||
cmake = os.environ.get(MUJOCO_CMAKE, 'cmake')
|
||||
build_cfg = 'Debug' if self.debug else 'Release'
|
||||
cmake_module_path = os.path.join(
|
||||
os.path.dirname(__file__), 'mujoco', 'cmake')
|
||||
os.path.dirname(__file__), 'mujoco', 'cmake'
|
||||
)
|
||||
cmake_args = [
|
||||
f'-DPython3_ROOT_DIR:PATH={sys.prefix}',
|
||||
f'-DPython3_EXECUTABLE:STRING={sys.executable}',
|
||||
f'-DCMAKE_MODULE_PATH:PATH={cmake_module_path}',
|
||||
f'-DCMAKE_BUILD_TYPE:STRING={build_cfg}',
|
||||
f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH={self.build_temp}',
|
||||
f'-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL={"OFF" if self.debug else "ON"}',
|
||||
(
|
||||
f'-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL={"OFF" if self.debug else "ON"}'
|
||||
),
|
||||
'-DCMAKE_Fortran_COMPILER:STRING=',
|
||||
'-DBUILD_TESTING:BOOL=OFF',
|
||||
]
|
||||
@@ -284,14 +303,17 @@ class BuildCMakeExtension(build_ext.build_ext):
|
||||
for arg in cmake_args:
|
||||
print(f' {arg}')
|
||||
subprocess.check_call(
|
||||
[cmake] + cmake_args +
|
||||
[os.path.join(os.path.dirname(__file__), 'mujoco')],
|
||||
cwd=self.build_temp)
|
||||
[cmake]
|
||||
+ cmake_args
|
||||
+ [os.path.join(os.path.dirname(__file__), 'mujoco')],
|
||||
cwd=self.build_temp,
|
||||
)
|
||||
|
||||
print('Building all extensions with CMake')
|
||||
subprocess.check_call(
|
||||
[cmake, '--build', '.', f'-j{os.cpu_count()}', '--config', build_cfg],
|
||||
cwd=self.build_temp)
|
||||
cwd=self.build_temp,
|
||||
)
|
||||
|
||||
def build_extension(self, ext):
|
||||
dest_path = self.get_ext_fullpath(ext.name)
|
||||
@@ -331,6 +353,7 @@ class InstallScripts(install_scripts.install_scripts):
|
||||
else:
|
||||
self.outfiles.append(oldfile)
|
||||
|
||||
|
||||
setuptools.setup(
|
||||
long_description=get_long_description(),
|
||||
long_description_content_type='text/markdown',
|
||||
@@ -350,7 +373,7 @@ setuptools.setup(
|
||||
CMakeExtension('mujoco._specs'),
|
||||
CMakeExtension('mujoco._structs'),
|
||||
],
|
||||
scripts=[
|
||||
'mujoco/mjpython/mjpython.py'
|
||||
] if platform.system() == 'Darwin' else [],
|
||||
scripts=['mujoco/mjpython/mjpython.py']
|
||||
if platform.system() == 'Darwin'
|
||||
else [],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user