mirror of
https://github.com/clearml/clearml
synced 2025-01-31 17:17:00 +00:00
Fix Hydra support, relative path argv[0]. (issue #219)
This commit is contained in:
parent
49b578b979
commit
6e7cb6b6f1
@ -569,22 +569,24 @@ class ScriptInfo(object):
|
|||||||
return Path(entry_point).as_posix()
|
return Path(entry_point).as_posix()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_working_dir(cls, repo_root, return_abs=False):
|
def _cwd(cls):
|
||||||
repo_root = Path(repo_root).absolute()
|
# return the current working directory (solve for hydra changing it)
|
||||||
cwd = None
|
|
||||||
|
|
||||||
# check if running with hydra
|
# check if running with hydra
|
||||||
if sys.modules.get('hydra'):
|
if sys.modules.get('hydra'):
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
# noinspection PyPackageRequirements
|
# noinspection PyPackageRequirements
|
||||||
import hydra
|
import hydra
|
||||||
cwd = Path(hydra.utils.get_original_cwd()).absolute()
|
return Path(hydra.utils.get_original_cwd()).absolute()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
return Path.cwd().absolute()
|
||||||
|
|
||||||
if not cwd:
|
@classmethod
|
||||||
cwd = Path.cwd().absolute()
|
def _get_working_dir(cls, repo_root, return_abs=False):
|
||||||
|
# get the repository working directory (might be different from actual cwd)
|
||||||
|
repo_root = Path(repo_root).absolute()
|
||||||
|
cwd = cls._cwd()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# do not change: test if we are under the repo root folder, it will throw an exception if we are not
|
# do not change: test if we are under the repo root folder, it will throw an exception if we are not
|
||||||
@ -594,6 +596,15 @@ class ScriptInfo(object):
|
|||||||
# Working directory not under repository root, default to repo root
|
# Working directory not under repository root, default to repo root
|
||||||
return repo_root.as_posix() if return_abs else '.'
|
return repo_root.as_posix() if return_abs else '.'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _absolute_path(cls, file_path, cwd):
|
||||||
|
# return the absolute path, relative to a specific working directory (cwd)
|
||||||
|
file_path = Path(file_path)
|
||||||
|
if file_path.is_absolute():
|
||||||
|
return file_path.as_posix()
|
||||||
|
# Convert to absolute and squash 'path/../folder'
|
||||||
|
return os.path.abspath((Path(cwd).absolute() / file_path).as_posix())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_script_code(cls, script_path):
|
def _get_script_code(cls, script_path):
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
@ -612,7 +623,8 @@ class ScriptInfo(object):
|
|||||||
if jupyter_filepath:
|
if jupyter_filepath:
|
||||||
scripts_path = [Path(os.path.normpath(jupyter_filepath)).absolute()]
|
scripts_path = [Path(os.path.normpath(jupyter_filepath)).absolute()]
|
||||||
else:
|
else:
|
||||||
scripts_path = [Path(os.path.normpath(f)).absolute() for f in filepaths if f]
|
cwd = cls._cwd()
|
||||||
|
scripts_path = [Path(cls._absolute_path(os.path.normpath(f), cwd)) for f in filepaths if f]
|
||||||
if all(not f.is_file() for f in scripts_path):
|
if all(not f.is_file() for f in scripts_path):
|
||||||
raise ScriptInfoError(
|
raise ScriptInfoError(
|
||||||
"Script file {} could not be found".format(scripts_path)
|
"Script file {} could not be found".format(scripts_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user