Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Commits
45082083
There was a problem fetching the pipeline summary.
Commit
45082083
authored
7 years ago
by
Pavel KORSHUNOV
Browse files
Options
Downloads
Patches
Plain Diff
command line based loading of configs
parent
a12deec7
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/tensorflow/utils/__init__.py
+2
-1
2 additions, 1 deletion
bob/learn/tensorflow/utils/__init__.py
bob/learn/tensorflow/utils/commandline.py
+56
-0
56 additions, 0 deletions
bob/learn/tensorflow/utils/commandline.py
with
58 additions
and
1 deletion
bob/learn/tensorflow/utils/__init__.py
+
2
−
1
View file @
45082083
from
.util
import
*
from
.singleton
import
Singleton
from
.session
import
Session
\ No newline at end of file
from
.session
import
Session
from
.
import
commandline
\ No newline at end of file
This diff is collapsed.
Click to expand it.
bob/learn/tensorflow/utils/commandline.py
0 → 100644
+
56
−
0
View file @
45082083
def
get_from_config_or_commandline
(
config
,
keyword
,
args
,
defaults
,
default_is_valid
=
True
):
"""
Takes the value from command line, config file, and default value with
this precedence.
Only several command line options can be used with this function:
- boolean flags
- repeating flags (like --verbose)
- options where the user will never provide the default value through
command line. For example when [default: None]
Parameters
----------
config : object
The loaded config files.
keyword : str
The keyword to load from the config file or through command line.
args : dict
The arguments parsed with docopt.
defaults : dict
The arguments parsed with docopt when ``argv=[]``.
default_is_valid : bool, optional
If False, will raise an exception if the final parsed value is the
default value.
Returns
-------
object
The bool or integer value of the corresponding keyword.
Example
-------
>>>
from
bob.bio.base.utils
import
read_config_file
>>>
defaults
=
docopt
(
docs
,
argv
=
[
""
])
>>>
args
=
docopt
(
docs
,
argv
=
argv
)
>>>
config_files
=
args
[
'
<config_files>
'
]
>>>
config
=
read_config_file
(
config_files
)
>>>
verbosity
=
get_from_config_or_commandline
(
config
,
'
verbose
'
,
args
,
...
defaults
)
"""
arg_keyword
=
'
--
'
+
keyword
.
replace
(
'
_
'
,
'
-
'
)
# load from config first
value
=
getattr
(
config
,
keyword
,
defaults
[
arg_keyword
])
# override it if provided by command line arguments
if
args
[
arg_keyword
]
!=
defaults
[
arg_keyword
]:
value
=
args
[
arg_keyword
]
if
not
default_is_valid
and
value
==
defaults
[
arg_keyword
]:
raise
ValueError
(
"
The value provided for {} is not valid.
"
.
format
(
keyword
))
return
value
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