Directory fix for git installs (#355)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
single_channel
Glenn Jocher 2 years ago committed by GitHub
parent f8e32c4c13
commit 4962733b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, GPL-3.0 license # Ultralytics YOLO 🚀, GPL-3.0 license
__version__ = "8.0.5" __version__ = "8.0.6"
from ultralytics.hub import checks from ultralytics.hub import checks
from ultralytics.yolo.engine.model import YOLO from ultralytics.yolo.engine.model import YOLO

@ -134,12 +134,13 @@ def is_git_directory() -> bool:
Returns: Returns:
bool: True if the current working directory is inside a git repository, False otherwise. bool: True if the current working directory is inside a git repository, False otherwise.
""" """
from git import Repo import git
try: try:
# Check if the current working directory is a git repository from git import Repo
Repo(search_parent_directories=True) Repo(search_parent_directories=True)
# subprocess.run(["git", "rev-parse", "--git-dir"], capture_output=True, check=True) # CLI alternative
return True return True
except Exception: except git.exc.InvalidGitRepositoryError: # subprocess.CalledProcessError:
return False return False
@ -348,7 +349,7 @@ def yaml_load(file='data.yaml', append_filename=False):
return {**yaml.safe_load(f), 'yaml_file': str(file)} if append_filename else yaml.safe_load(f) return {**yaml.safe_load(f), 'yaml_file': str(file)} if append_filename else yaml.safe_load(f)
def get_settings(file=USER_CONFIG_DIR / 'settings.yaml', version='0.0.0'): def get_settings(file=USER_CONFIG_DIR / 'settings.yaml', version='0.0.1'):
""" """
Loads a global Ultralytics settings YAML file or creates one with default values if it does not exist. Loads a global Ultralytics settings YAML file or creates one with default values if it does not exist.
@ -362,9 +363,10 @@ def get_settings(file=USER_CONFIG_DIR / 'settings.yaml', version='0.0.0'):
from ultralytics.yolo.utils.checks import check_version from ultralytics.yolo.utils.checks import check_version
from ultralytics.yolo.utils.torch_utils import torch_distributed_zero_first from ultralytics.yolo.utils.torch_utils import torch_distributed_zero_first
root = get_git_root_dir() or Path('') # not is_pip_package() is_git = is_git_directory() # True if ultralytics installed via git
root = get_git_root_dir() if is_git else Path()
defaults = { defaults = {
'datasets_dir': str(root / 'datasets'), # default datasets directory. 'datasets_dir': str((root.parent if is_git else root) / 'datasets'), # default datasets directory.
'weights_dir': str(root / 'weights'), # default weights directory. 'weights_dir': str(root / 'weights'), # default weights directory.
'runs_dir': str(root / 'runs'), # default runs directory. 'runs_dir': str(root / 'runs'), # default runs directory.
'sync': True, # sync analytics to help with YOLO development 'sync': True, # sync analytics to help with YOLO development

Loading…
Cancel
Save