# ----------------------------------------------------------------------------# SymForce - Copyright 2022, Skydio, Inc.# This source code is under the Apache 2.0 license found in the LICENSE file.# ----------------------------------------------------------------------------importjsonimportosimporttypingasTfrompathlibimportPath
class_Manifest:""" Internal class to manage loading data from the build manifest and caching that data. Not intended for use outside of path_util.py. """_manifest:T.Optional[T.Dict[str,str]]=None@classmethoddef_ensure_loaded(cls)->None:ifcls._manifestisNone:manifest_path=Path(__file__).parent.parent/"build"/"manifest.json"try:withopen(manifest_path)asf:cls._manifest=json.load(f)exceptFileNotFoundErrorasex:raiseMissingManifestException(f"Manifest not found at {manifest_path}")fromex@classmethoddefget_entry(cls,key:str)->Path:cls._ensure_loaded()assertcls._manifestisnotNonereturnPath(cls._manifest[key]).resolve()@classmethoddefget_entries(cls,key:str)->T.List[Path]:cls._ensure_loaded()assertcls._manifestisnotNonereturn[Path(s).resolve()forsincls._manifest[key]]
[docs]defsymforce_root()->Path:""" The root directory of the symforce project """returnPath(__file__).parent.parent
[docs]defsymforce_data_root(test_file_path:T.Optional[str])->Path:""" The root directory of the symforce project, for use accessing data that might need to be updated (such as generated files). Most of the time this is the same as :func:`symforce_root`, except for two cases: 1) When running tests on wheels, this is the root of the copy of SymForce containing the test, not the installed copy. The generated files we're checking aren't in the wheel, they're in the source tree. 2) When the ``--update`` flag is passed to a test, this is guaranteed to point to the *resolved* version, i.e. the actual symforce location on disk regardless of whether this path is a symlink. """fromsymforce.test_util.test_case_mixinimportSymforceTestCaseMixiniftest_file_pathisnotNoneand"SYMFORCE_WHEEL_TESTS"inos.environ:returnPath(test_file_path).resolve().parent.parentifSymforceTestCaseMixin.should_update():returnPath(__file__).resolve().parent.parentelse:returnsymforce_root()