Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
d8c8af4f
Commit
d8c8af4f
authored
6 years ago
by
Mikhail Karnevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Add parser group: required arguments. Show warning if parameter is an empty list.
parent
0f5c731e
No related branches found
No related tags found
1 merge request
!29
Required parameter
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xfel_calibrate/calibrate.py
+27
-14
27 additions, 14 deletions
xfel_calibrate/calibrate.py
with
27 additions
and
14 deletions
xfel_calibrate/calibrate.py
+
27
−
14
View file @
d8c8af4f
...
...
@@ -48,6 +48,8 @@ def make_initial_parser():
parser
.
add_argument
(
'
--report-to
'
,
type
=
str
,
help
=
'
Filename (and optionally path) for output report
'
)
parser
.
add_argument_group
(
'
required arguments
'
)
return
parser
parser
=
make_initial_parser
()
...
...
@@ -243,32 +245,43 @@ elif len(sys.argv) >= 3:
helpstr
=
(
"
Default: %(default)s
"
if
not
p
.
comment
else
"
{}. Default: %(default)s
"
.
format
(
p
.
comment
.
replace
(
"
#
"
,
"
"
).
strip
()))
required
=
(
p
.
comment
is
not
None
and
"
required
"
in
p
.
comment
)
and
not
overwrite_reqs
if
p
.
type
==
list
or
p
.
name
==
cvar
:
if
p
.
type
is
list
and
len
(
p
.
value
):
ltype
=
type
(
p
.
value
[
0
])
elif
p
.
type
is
not
list
:
ltype
=
p
.
type
required
=
(
p
.
comment
is
not
None
and
"
required
"
in
p
.
comment
and
not
overwrite_reqs
and
p
.
name
!=
cvar
)
pars_group
=
parser
.
_action_groups
[
1
]
if
required
:
pars_group
=
parser
.
_action_groups
[
2
]
default
=
p
.
value
if
(
not
required
)
else
None
if
p
.
type
==
list
:
# Warning if list is empty
if
len
(
p
.
value
)
==
0
:
warnings
.
warn
(
"
List {} is empty. Parameter type can not be defined.
"
.
format
(
p
.
name
),
RuntimeWarning
)
ltype
=
type
(
p
.
value
[
0
])
range_allowed
=
"
RANGE ALLOWED
"
in
p
.
comment
.
upper
()
if
p
.
comment
else
False
pars
er
.
add_argument
(
"
--{}
"
.
format
(
consolize_name
(
p
.
name
)),
pars
_group
.
add_argument
(
"
--{}
"
.
format
(
consolize_name
(
p
.
name
)),
nargs
=
'
+
'
,
type
=
ltype
if
not
range_allowed
else
str
,
default
=
p
.
value
if
(
not
required
)
and
p
.
name
!=
cvar
else
None
,
default
=
default
,
help
=
helpstr
,
required
=
required
and
p
.
name
!=
cvar
,
required
=
required
,
action
=
make_intelli_list
(
ltype
)
if
range_allowed
else
None
)
elif
p
.
type
==
bool
:
pars
er
.
add_argument
(
"
--{}
"
.
format
(
consolize_name
(
p
.
name
)),
pars
_group
.
add_argument
(
"
--{}
"
.
format
(
consolize_name
(
p
.
name
)),
action
=
"
store_true
"
,
default
=
p
.
value
if
not
required
else
None
,
default
=
default
,
help
=
helpstr
,
required
=
required
)
else
:
pars
er
.
add_argument
(
"
--{}
"
.
format
(
consolize_name
(
p
.
name
)),
pars
_group
.
add_argument
(
"
--{}
"
.
format
(
consolize_name
(
p
.
name
)),
type
=
p
.
type
,
default
=
p
.
value
if
not
required
else
None
,
default
=
default
,
help
=
helpstr
,
required
=
required
)
...
...
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