Skip to content

Instantly share code, notes, and snippets.

@gglin001
Last active May 17, 2021 12:19
Show Gist options
  • Save gglin001/115ab012750aeb86fbda9975fa49f47c to your computer and use it in GitHub Desktop.
Save gglin001/115ab012750aeb86fbda9975fa49f47c to your computer and use it in GitHub Desktop.
pytorch_edit_cmake.py
...
# old
def convert_cmake_value_to_python_value(cmake_value, cmake_type):
r"""Convert a CMake value in a string form to a Python value.
Args:
cmake_value (string): The CMake value in a string form (e.g., "ON", "OFF", "1").
cmake_type (string): The CMake type of :attr:`cmake_value`.
Returns:
A Python value corresponding to :attr:`cmake_value` with type :attr:`cmake_type`.
"""
cmake_type = cmake_type.upper()
up_val = cmake_value.upper()
if cmake_type == 'BOOL':
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/VariablesListsStrings#boolean-values-in-cmake
return not (up_val in ('FALSE', 'OFF', 'N', 'NO', '0', '', 'NOTFOUND') or up_val.endswith('-NOTFOUND'))
elif cmake_type == 'FILEPATH':
if up_val.endswith('-NOTFOUND'):
return None
else:
return cmake_value
else: # Directly return the cmake_value.
return cmake_value
...
==========================================================================================
# new
...
def convert_cmake_value_to_python_value(cmake_value, cmake_type):
r"""Convert a CMake value in a string form to a Python value.
Args:
cmake_value (string): The CMake value in a string form (e.g., "ON", "OFF", "1").
cmake_type (string): The CMake type of :attr:`cmake_value`.
Returns:
A Python value corresponding to :attr:`cmake_value` with type :attr:`cmake_type`.
"""
cmake_type = cmake_type.upper()
up_val = cmake_value.upper()
if cmake_type == 'BOOL':
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/VariablesListsStrings#boolean-values-in-cmake
return not (up_val in ('FALSE', 'OFF', 'N', 'NO', '0', '', 'NOTFOUND') or up_val.endswith('-NOTFOUND'))
elif cmake_type == 'FILEPATH':
if up_val.endswith('-NOTFOUND'):
return None
else:
return cmake_value
elif cmake_type == 'STRING':
if cmake_value == 'OFF':
return False
elif cmake_value == 'ON':
return True
else:
return cmake_value
else: # Directly return the cmake_value.
return cmake_value
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment