Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
565da1fb
Unverified
Commit
565da1fb
authored
Sep 03, 2024
by
Jakob Görgen
Browse files
more methods to resolve paths
parent
bb42498c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
11 deletions
+29
-11
experiments/simbricks/orchestration/instantiation/base.py
experiments/simbricks/orchestration/instantiation/base.py
+29
-11
No files found.
experiments/simbricks/orchestration/instantiation/base.py
View file @
565da1fb
...
@@ -47,6 +47,7 @@ class InstantiationEnvironment:
...
@@ -47,6 +47,7 @@ class InstantiationEnvironment:
cpdir
:
str
=
pathlib
.
Path
(),
cpdir
:
str
=
pathlib
.
Path
(),
shm_base
:
str
=
pathlib
.
Path
(),
shm_base
:
str
=
pathlib
.
Path
(),
output_base
:
str
=
pathlib
.
Path
(),
output_base
:
str
=
pathlib
.
Path
(),
tmp_simulation_files
:
str
=
pathlib
.
Path
(),
):
):
# TODO: add more parameters that wont change during instantiation
# TODO: add more parameters that wont change during instantiation
self
.
_repodir
:
str
=
pathlib
.
Path
(
repo_path
).
absolute
()
self
.
_repodir
:
str
=
pathlib
.
Path
(
repo_path
).
absolute
()
...
@@ -54,6 +55,9 @@ class InstantiationEnvironment:
...
@@ -54,6 +55,9 @@ class InstantiationEnvironment:
self
.
_cpdir
:
str
=
pathlib
.
Path
(
cpdir
).
absolute
()
self
.
_cpdir
:
str
=
pathlib
.
Path
(
cpdir
).
absolute
()
self
.
_shm_base
:
str
=
pathlib
.
Path
(
workdir
).
joinpath
(
shm_base
).
absolute
()
self
.
_shm_base
:
str
=
pathlib
.
Path
(
workdir
).
joinpath
(
shm_base
).
absolute
()
self
.
_output_base
:
str
=
pathlib
.
Path
(
workdir
).
joinpath
(
output_base
).
absolute
()
self
.
_output_base
:
str
=
pathlib
.
Path
(
workdir
).
joinpath
(
output_base
).
absolute
()
self
.
_tmp_simulation_files
:
str
=
(
pathlib
.
Path
(
workdir
).
joinpath
(
tmp_simulation_files
).
absolute
()
)
class
Instantiation
:
class
Instantiation
:
...
@@ -156,31 +160,45 @@ class Instantiation:
...
@@ -156,31 +160,45 @@ class Instantiation:
# TODO: add more methods constructing paths as required by methods in simulators or image handling classes
# TODO: add more methods constructing paths as required by methods in simulators or image handling classes
def
_join_paths
(
self
,
base
:
str
=
""
,
relative_path
:
str
=
""
)
->
str
:
def
_join_paths
(
self
,
base
:
str
=
""
,
relative_path
:
str
=
""
,
enforce_existence
=
True
)
->
str
:
path
=
pathlib
.
Path
(
base
)
path
=
pathlib
.
Path
(
base
)
path
.
joinpath
(
relative_path
)
path
.
joinpath
(
relative_path
)
if
not
path
.
exists
():
if
not
path
.
exists
()
and
enforce_existence
:
raise
Exception
(
f
"couldn't join
{
base
}
and
{
relative_path
}
"
)
raise
Exception
(
f
"couldn't join
{
base
}
and
{
relative_path
}
"
)
return
path
.
absolute
()
return
path
.
absolute
()
def
join_repo_base
(
self
,
relative_path
:
str
)
->
str
:
def
join_repo_base
(
self
,
relative_path
:
str
)
->
str
:
return
self
.
_join_paths
(
base
=
self
.
_env
.
_repodir
,
relative_path
=
relative_path
)
return
self
.
_join_paths
(
base
=
self
.
_env
.
_repodir
,
relative_path
=
relative_path
,
enforce_existence
=
True
)
def
join_output_base
(
self
,
relative_path
:
str
)
->
str
:
def
join_output_base
(
self
,
relative_path
:
str
)
->
str
:
return
self
.
_join_paths
(
return
self
.
_join_paths
(
base
=
self
.
_env
.
_output_base
,
relative_path
=
relative_path
base
=
self
.
_env
.
_output_base
,
relative_path
=
relative_path
,
enforce_existence
=
True
,
)
)
def
hd_path
(
self
,
hd_name_or_path
:
str
)
->
str
:
def
hd_path
(
self
,
hd_name_or_path
:
str
)
->
str
:
if
Instantiation
.
is_absolute_exists
(
hd_name_or_path
):
if
Instantiation
.
is_absolute_exists
(
hd_name_or_path
):
return
hd_name_or_path
return
hd_name_or_path
path
=
self
.
_join_paths
(
path
=
pathlib
.
Path
(
base
=
self
.
_env
.
_repodir
,
f
"
{
self
.
_env
.
_repodir
}
/images/output-
{
hd_name_or_path
}
/
{
hd_name_or_path
}
"
relative_path
=
f
"/images/output-
{
hd_name_or_path
}
/
{
hd_name_or_path
}
"
,
enforce_existence
=
True
,
)
)
return
path
return
path
.
absolute
()
def
join_tmp_base
(
self
,
relative_path
:
str
)
->
str
:
return
self
.
_join_paths
(
base
=
self
.
_env
.
_tmp_simulation_files
,
relative_path
=
filename
,
enforce_existence
=
False
,
)
def
dynamic_img_path
(
self
,
format
:
str
)
->
str
:
def
dynamic_img_path
(
self
,
filename
:
str
)
->
str
:
# TODO
return
self
.
_join_paths
(
return
""
base
=
self
.
_env
.
_tmp_simulation_files
,
relative_path
=
filename
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment