Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
# Copyright 2026 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Generates API for APIReference.rst."""
import os
import sys
from typing import Dict
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
try:
import resource_loader # pyrefly: ignore[missing-import]
import header_reader # pyrefly: ignore[missing-import]
except ImportError:
raise
_HEADER_FILES = [
'include/mujoco/mjassert.h',
'include/mujoco/mjdata.h',
'include/mujoco/mjexport.h',
'include/mujoco/mjmacro.h',
'include/mujoco/mjmodel.h',
'include/mujoco/mjplugin.h',
'include/mujoco/mjrender.h',
'include/mujoco/mjrfilament.h',
'include/mujoco/mjspec.h',
'include/mujoco/mjspecmacro.h',
'include/mujoco/mjtype.h',
'include/mujoco/mjui.h',
'include/mujoco/mjvisualize.h',
'include/mujoco/mjxmacro.h',
'include/mujoco/mujoco.h',
]
_SOURCE_FILES = [
'src/engine/engine_support.c',
'src/engine/engine_vis_init.c',
]
def generate_reference_header(
api: Dict[str, header_reader.ApiDefinition]) -> str:
"""Generates the reference header file used by APIRererence.rst."""
source = """
// Copyright 2022 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// DO NOT EDIT. THIS FILE IS AUTOMATICALLY GENERATED.
// Error: C reference not found
// NOLINTBEGIN\n\n""".lstrip()
for value in api.values():
if value.c_type not in ('FUNCTION', 'ARRAY'):
source = f'{source}{value.code}'
source = f"""{source}
//----------------------------- STRING CONSTANTS -------------------------------
"""
for value in api.values():
if value.c_type == 'ARRAY':
source = f'{source}{value.code}'
source = f"""{source}
//----------------------------- MJAPI FUNCTIONS --------------------------------
"""
for value in api.values():
if value.c_type == 'FUNCTION':
source = f'{source}{value.code}'
source = f'{source}// NOLINTEND\n'
return source
def read_headers() -> Dict[str, header_reader.ApiDefinition]:
"""Reads API header and source files and generates a mapping between C tokens and C definitions."""
api = {}
for header in _HEADER_FILES:
lines = resource_loader.read_text(header).splitlines(keepends=True)
api.update(header_reader.read(lines))
for source in _SOURCE_FILES:
lines = resource_loader.read_text(source).splitlines(keepends=True)
api.update(header_reader.read(lines, parse_functions=False))
return api
def main() -> None:
if len(sys.argv) > 1:
sys.exit('Too many command-line arguments.')
sys.stdout.buffer.write(
generate_reference_header(read_headers()).encode('utf-8')
)
if __name__ == '__main__':
main()
46f925a79This file is pinned to the selected release. Download the original to open it in your design tool.