mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-26 02:49:57 +08:00
remove root dir logic from hydra (#587)
This commit is contained in:
1 parent
c871ff7e13
commit
5d26f3d5c4
7 files changed
+20
-85
No files matched your search
+1
-56
@@ -16,11 +16,9 @@
|
||||
Input/output utils.
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pickle
|
||||
from pathlib import Path
|
||||
from typing import Any, Tuple
|
||||
from typing import Any
|
||||
|
||||
|
||||
def load_from_json(filename: Path):
|
||||
@@ -67,56 +65,3 @@ def write_to_pkl(filename: Path, content: Any):
|
||||
assert filename.suffix == ".pkl"
|
||||
with open(filename, "wb") as f:
|
||||
pickle.dump(content, f)
|
||||
|
||||
|
||||
def get_git_root(path: str, dirs: Tuple[str] = (".git",), default: str = "") -> str:
|
||||
"""Find the root of the git repository.
|
||||
'https://stackoverflow.com/questions/22081209/find-the-root-of-the-git-repository-where-the-file-lives'
|
||||
|
||||
Args:
|
||||
path: The path to start from.
|
||||
dirs: The directories to look for.
|
||||
default: The default value to return if no git root is found.
|
||||
|
||||
Returns:
|
||||
The root of the git repository. Returns None if not found.
|
||||
"""
|
||||
prev, test = None, os.path.abspath(path)
|
||||
while prev != test:
|
||||
if any(os.path.isdir(os.path.join(test, directory)) for directory in dirs):
|
||||
return test
|
||||
prev, test = test, os.path.abspath(os.path.join(test, os.pardir))
|
||||
logging.info("Couldn't find git root")
|
||||
return default
|
||||
|
||||
|
||||
def get_project_root(path: str) -> Path:
|
||||
"""Return the project root directory from an environment variable.
|
||||
# TODO: handle this better and report user error
|
||||
|
||||
Args:
|
||||
path: The path to start from.
|
||||
|
||||
Returns:
|
||||
The project root directory.
|
||||
"""
|
||||
project_root = os.getenv("PROJECT_ROOT")
|
||||
if project_root is None:
|
||||
logging.info(
|
||||
"Please set PROJECT_ROOT to the root directory of this repo. "
|
||||
"Going to try calling get_git_root(path) instead."
|
||||
)
|
||||
project_root = get_git_root(path)
|
||||
return Path(project_root)
|
||||
|
||||
|
||||
def get_absolute_path(path, proj_root_func=get_project_root) -> Path:
|
||||
"""
|
||||
Returns the full, absolute path.
|
||||
Relative paths are assumed to start at the repo directory.
|
||||
"""
|
||||
str_absolute_path = str(path)
|
||||
if str_absolute_path == "" or str_absolute_path[0] == "/":
|
||||
return path
|
||||
absolute_path = proj_root_func(str_absolute_path) / path
|
||||
return absolute_path
|
||||
Reference in new issue
Block a user