Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BIP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
FSL
BIP
Commits
7f8a7a93
Commit
7f8a7a93
authored
2 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Run config files through jinja, so we can inject variables (e.g. FSLDIR,
BIPDIR, etc)
parent
cf99feef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
ENH: Config file templating
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bip/utils/config.py
+19
-5
19 additions, 5 deletions
bip/utils/config.py
with
19 additions
and
5 deletions
bip/utils/config.py
+
19
−
5
View file @
7f8a7a93
...
@@ -26,6 +26,8 @@ import os
...
@@ -26,6 +26,8 @@ import os
import
os.path
as
op
import
os.path
as
op
import
operator
import
operator
import
jinja2
as
j2
# python >= 3.11
# python >= 3.11
try
:
try
:
...
@@ -321,7 +323,7 @@ class Config:
...
@@ -321,7 +323,7 @@ class Config:
@staticmethod
@staticmethod
def
load_config_file
(
cfgfile
,
selectors
=
None
):
def
load_config_file
(
cfgfile
,
selectors
=
None
,
env
=
None
):
"""
Load a BIP configuration file. The file is assumed to be a TOML
"""
Load a BIP configuration file. The file is assumed to be a TOML
file, named as described in the config_file_identifier documentation.
file, named as described in the config_file_identifier documentation.
...
@@ -337,16 +339,27 @@ class Config:
...
@@ -337,16 +339,27 @@ class Config:
'
T1_struct_bet_f
'
: 0.5
'
T1_struct_bet_f
'
: 0.5
'
T1_struct_fast_classes
'
: 3
'
T1_struct_fast_classes
'
: 3
Re-labelling is not applied to the main
"
config.toml
"
configuration
This re-labelling is not applied to the main
"
config.toml
"
file.
configuration file.
If selectors are provided, alternate values stored in the file may be
used - refer to the resolve_selectors method.
Configuration files may contain variables using Jinja2 syntax - if
an
"
env
"
dictionary is provided, the file contents are passed through
Jinja2 to resolve these variable references.
"""
"""
if
selectors
is
None
:
if
selectors
is
None
:
selectors
=
{}
selectors
=
{}
with
open
(
cfgfile
,
'
rb
'
)
as
f
:
with
open
(
cfgfile
,
'
rt
'
)
as
f
:
settings
=
tomllib
.
load
(
f
)
settings
=
f
.
read
()
if
env
is
not
None
:
settings
=
j2
.
Template
(
settings
).
render
(
**
env
)
settings
=
tomllib
.
loads
(
settings
)
ident
=
Config
.
config_file_identifier
(
cfgfile
)
ident
=
Config
.
config_file_identifier
(
cfgfile
)
selectors
=
{
k
:
selectors
[
k
]
for
k
in
sorted
(
selectors
.
keys
())}
selectors
=
{
k
:
selectors
[
k
]
for
k
in
sorted
(
selectors
.
keys
())}
settings
=
Config
.
resolve_selectors
(
settings
,
selectors
)
settings
=
Config
.
resolve_selectors
(
settings
,
selectors
)
...
@@ -378,6 +391,7 @@ class Config:
...
@@ -378,6 +391,7 @@ class Config:
return
settings
return
settings
# env=None - run all files through equivalent of op.expandvars
def
__init__
(
self
,
cfgdir
=
None
,
selectors
=
None
,
overrides
=
None
):
def
__init__
(
self
,
cfgdir
=
None
,
selectors
=
None
,
overrides
=
None
):
"""
Create a Config object. Read configuration files from cfgdir.
"""
Create a Config object. Read configuration files from cfgdir.
...
...
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