Update check_git_status() to run under ROOT working directory (#5441)
* Updating check_git_status() to switch to the repository root before performing git ops * More pythonic * Linting * Remove redundant Path() call * Generalizing the context manager * Fixing error in context manager * Cleanup * Change to decorator Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
19c8760caa
commit
7476012a4d
1 file changed
+14
@@ -81,6 +81,19 @@ class Timeout(contextlib.ContextDecorator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class WorkingDirectory(contextlib.ContextDecorator):
|
||||||
|
# Usage: @WorkingDirectory(dir) decorator or 'with WorkingDirectory(dir):' context manager
|
||||||
|
def __init__(self, new_dir):
|
||||||
|
self.dir = new_dir # new dir
|
||||||
|
self.cwd = Path.cwd().resolve() # current dir
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
os.chdir(self.dir)
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
os.chdir(self.cwd)
|
||||||
|
|
||||||
|
|
||||||
def try_except(func):
|
def try_except(func):
|
||||||
# try-except function. Usage: @try_except decorator
|
# try-except function. Usage: @try_except decorator
|
||||||
def handler(*args, **kwargs):
|
def handler(*args, **kwargs):
|
||||||
@@ -203,6 +216,7 @@ def check_online():
|
|||||||
|
|
||||||
|
|
||||||
@try_except
|
@try_except
|
||||||
|
@WorkingDirectory(ROOT)
|
||||||
def check_git_status():
|
def check_git_status():
|
||||||
# Recommend 'git pull' if code is out of date
|
# Recommend 'git pull' if code is out of date
|
||||||
msg = ', for updates see https://github.com/ultralytics/yolov5'
|
msg = ', for updates see https://github.com/ultralytics/yolov5'
|
||||||
|
|||||||
Reference in new issue
Block a user