Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
46692d5c
Commit
46692d5c
authored
6 years ago
by
Michiel Cottaar
Browse files
Options
Downloads
Patches
Plain Diff
BUG: by default update variables for parent
parent
e50b282a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/utils/filetree/filetree.py
+13
-5
13 additions, 5 deletions
fsl/utils/filetree/filetree.py
tests/test_filetree/test_read.py
+11
-0
11 additions, 0 deletions
tests/test_filetree/test_read.py
with
24 additions
and
5 deletions
fsl/utils/filetree/filetree.py
+
13
−
5
View file @
46692d5c
...
@@ -185,7 +185,7 @@ class FileTree(object):
...
@@ -185,7 +185,7 @@ class FileTree(object):
"""
"""
return
tuple
(
self
.
extract_variables
(
short_name
,
fn
)
for
fn
in
self
.
get_all
(
short_name
,
glob_vars
=
glob_vars
))
return
tuple
(
self
.
extract_variables
(
short_name
,
fn
)
for
fn
in
self
.
get_all
(
short_name
,
glob_vars
=
glob_vars
))
def
get_all_trees
(
self
,
short_name
:
str
,
glob_vars
=
())
->
Tuple
[
"
FileTree
"
]:
def
get_all_trees
(
self
,
short_name
:
str
,
glob_vars
=
()
,
set_parent
=
True
)
->
Tuple
[
"
FileTree
"
]:
"""
"""
Gets all the trees that generate the existing files matching the pattern
Gets all the trees that generate the existing files matching the pattern
...
@@ -195,23 +195,31 @@ class FileTree(object):
...
@@ -195,23 +195,31 @@ class FileTree(object):
:param glob_vars: sequence of undefined variables that can take any possible values when looking for matches on the disk.
:param glob_vars: sequence of undefined variables that can take any possible values when looking for matches on the disk.
Any defined variables in `glob_vars` will be ignored.
Any defined variables in `glob_vars` will be ignored.
If glob_vars is set to
'
all
'
, all undefined variables will be used to look up matches.
If glob_vars is set to
'
all
'
, all undefined variables will be used to look up matches.
:param set_parent: Update the variables of the top-level rather than current tree if True.
Ony relevant if `self` is a sub-tree.
:return: sequence of FileTrees used to generate each file on disk matching the pattern of `short_name`
:return: sequence of FileTrees used to generate each file on disk matching the pattern of `short_name`
"""
"""
return
tuple
(
self
.
update
(
**
vars
)
for
vars
in
self
.
get_all_vars
(
short_name
,
glob_vars
=
glob_vars
))
return
tuple
(
self
.
update
(
set_parent
=
set_parent
,
**
vars
)
for
vars
in
self
.
get_all_vars
(
short_name
,
glob_vars
=
glob_vars
))
def
update
(
self
,
**
variables
)
->
"
FileTree
"
:
def
update
(
self
,
set_parent
=
True
,
**
variables
)
->
"
FileTree
"
:
"""
"""
Creates a new FileTree with updated variables
Creates a new FileTree with updated variables
:param set_parent: Update the variables of the top-level rather than current tree if True.
Ony relevant if `self` is a sub-tree.
:param variables: new values for the variables
:param variables: new values for the variables
Setting a variable to None will cause the variable to be unset
Setting a variable to None will cause the variable to be unset
:return: New FileTree with same templates for directory names and filenames, but updated variables
:return: New FileTree with same templates for directory names and filenames, but updated variables
"""
"""
new_tree
=
deepcopy
(
self
)
new_tree
=
deepcopy
(
self
)
new_tree
.
variables
.
update
(
variables
)
set_tree
=
new_tree
while
set_parent
and
set_tree
.
parent
is
not
None
:
set_tree
=
set_tree
.
parent
set_tree
.
variables
.
update
(
variables
)
for
key
,
value
in
variables
.
items
():
for
key
,
value
in
variables
.
items
():
if
value
is
None
:
if
value
is
None
:
del
new
_tree
.
variables
[
key
]
del
set
_tree
.
variables
[
key
]
return
new_tree
return
new_tree
def
extract_variables
(
self
,
short_name
:
str
,
filename
:
str
)
->
Dict
[
str
,
str
]:
def
extract_variables
(
self
,
short_name
:
str
,
filename
:
str
)
->
Dict
[
str
,
str
]:
...
...
This diff is collapsed.
Click to expand it.
tests/test_filetree/test_read.py
+
11
−
0
View file @
46692d5c
...
@@ -58,6 +58,17 @@ def test_parent_tree():
...
@@ -58,6 +58,17 @@ def test_parent_tree():
with
pytest
.
raises
(
KeyError
):
with
pytest
.
raises
(
KeyError
):
tree
.
get
(
'
sub_var/basename
'
)
tree
.
get
(
'
sub_var/basename
'
)
# test updating in parent tree
sub0_tree
=
tree
.
sub_trees
[
'
sub0
'
]
same_path
(
sub0_tree
.
update
(
subvar
=
'
test
'
).
get
(
'
../subvar/basename
'
),
'
subvar_test
'
)
with
pytest
.
raises
(
KeyError
):
sub0_tree
.
update
(
subvar
=
'
test
'
,
set_parent
=
False
).
get
(
'
../subvar/basename
'
)
sub0_tree
=
tree
.
update
(
subvar
=
'
grot
'
).
sub_trees
[
'
sub0
'
]
same_path
(
sub0_tree
.
update
(
subvar
=
'
test
'
).
get
(
'
../subvar/basename
'
),
'
subvar_test
'
)
same_path
(
sub0_tree
.
update
(
subvar
=
'
test
'
,
set_parent
=
False
).
get
(
'
../subvar/basename
'
),
'
subvar_grot
'
)
same_path
(
sub0_tree
.
get
(
'
../subvar/basename
'
),
'
subvar_grot
'
)
def
test_custom_tree
():
def
test_custom_tree
():
directory
=
op
.
split
(
__file__
)[
0
]
directory
=
op
.
split
(
__file__
)[
0
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment