Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.extension
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
Show more breadcrumbs
bob
bob.extension
Commits
003cf587
There was a problem fetching the pipeline summary.
Commit
003cf587
authored
6 years ago
by
Theophile GENTILHOMME
Browse files
Options
Downloads
Patches
Plain Diff
Add dump config file
parent
13a70cfc
Branches
Branches containing commit
Tags
v2.0.10
Tags containing commit
1 merge request
!86
Dump config file
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/extension/scripts/click_helper.py
+23
-1
23 additions, 1 deletion
bob/extension/scripts/click_helper.py
bob/extension/scripts/main_cli.py
+1
-1
1 addition, 1 deletion
bob/extension/scripts/main_cli.py
bob/extension/test_click_helper.py
+17
-0
17 additions, 0 deletions
bob/extension/test_click_helper.py
with
41 additions
and
2 deletions
bob/extension/scripts/click_helper.py
+
23
−
1
View file @
003cf587
from
..log
import
set_verbosity_level
from
..log
import
set_verbosity_level
from
..config
import
load
,
mod_to_context
from
..config
import
load
,
mod_to_context
import
time
import
click
import
click
import
logging
import
logging
...
@@ -172,6 +173,9 @@ class ConfigCommand(click.Command):
...
@@ -172,6 +173,9 @@ class ConfigCommand(click.Command):
**
kwargs
)
**
kwargs
)
# Add the config argument to the command
# Add the config argument to the command
click
.
argument
(
config_argument_name
,
nargs
=-
1
)(
self
)
click
.
argument
(
config_argument_name
,
nargs
=-
1
)(
self
)
# Option for config file generation
click
.
option
(
'
-dc
'
,
'
--dump-config
'
,
type
=
click
.
Path
(
exists
=
False
),
help
=
"
Name of the config file to be generated
"
)(
self
)
def
invoke
(
self
,
ctx
):
def
invoke
(
self
,
ctx
):
config_files
=
ctx
.
params
[
self
.
config_argument_name
.
lower
()]
config_files
=
ctx
.
params
[
self
.
config_argument_name
.
lower
()]
...
@@ -180,7 +184,7 @@ class ConfigCommand(click.Command):
...
@@ -180,7 +184,7 @@ class ConfigCommand(click.Command):
config_files
,
entry_point_group
=
self
.
entry_point_group
)
config_files
,
entry_point_group
=
self
.
entry_point_group
)
config_context
=
mod_to_context
(
config_context
)
config_context
=
mod_to_context
(
config_context
)
for
param
in
self
.
params
:
for
param
in
self
.
params
:
if
param
.
name
not
in
ctx
.
params
:
if
param
.
name
not
in
ctx
.
params
or
param
.
name
==
'
dump_config
'
:
continue
continue
value
=
ctx
.
params
[
param
.
name
]
value
=
ctx
.
params
[
param
.
name
]
if
not
hasattr
(
param
,
'
user_provided
'
):
if
not
hasattr
(
param
,
'
user_provided
'
):
...
@@ -200,9 +204,27 @@ class ConfigCommand(click.Command):
...
@@ -200,9 +204,27 @@ class ConfigCommand(click.Command):
finally
:
finally
:
# make sure to set this back to False for future invocations
# make sure to set this back to False for future invocations
param
.
required
=
False
param
.
required
=
False
if
'
dump_config
'
in
ctx
.
params
:
self
.
dump_config
(
ctx
)
return
super
(
ConfigCommand
,
self
).
invoke
(
ctx
)
return
super
(
ConfigCommand
,
self
).
invoke
(
ctx
)
def
dump_config
(
self
,
ctx
):
config_file
=
open
(
ctx
.
params
.
get
(
'
dump_config
'
),
'
w
'
)
config_file
.
write
(
'
# Configuration file automatically generated at %s
'
'
for %s.
\n\n\n
'
%
(
time
.
strftime
(
"
%d/%m/%Y
"
),
ctx
.
command_path
))
for
param
in
self
.
params
:
if
param
.
name
not
in
ctx
.
params
or
param
.
name
==
'
dump_config
'
:
continue
if
not
isinstance
(
param
,
click
.
Option
):
continue
config_file
.
write
(
'
# %s.
\n\n
'
%
param
.
help
)
config_file
.
write
(
'
# %s = %s
\n\n
'
%
(
param
.
name
,
str
(
ctx
.
params
[
param
.
name
])))
config_file
.
write
(
'
\n\n\n
'
)
class
ResourceOption
(
click
.
Option
):
class
ResourceOption
(
click
.
Option
):
"""
A click.Option that is aware if the user actually provided this option
"""
A click.Option that is aware if the user actually provided this option
...
...
This diff is collapsed.
Click to expand it.
bob/extension/scripts/main_cli.py
+
1
−
1
View file @
003cf587
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
import
pkg_resources
import
pkg_resources
import
click
import
click
from
click_plugins
import
with_plugins
from
click_plugins
import
with_plugins
from
.click_helper
import
AliasedGroup
from
.click_helper
import
AliasedGroup
,
ConfigCommand
from
..log
import
setup
from
..log
import
setup
logger
=
setup
(
'
bob
'
)
logger
=
setup
(
'
bob
'
)
...
...
This diff is collapsed.
Click to expand it.
bob/extension/test_click_helper.py
+
17
−
0
View file @
003cf587
...
@@ -171,3 +171,20 @@ def test_prefix_aliasing():
...
@@ -171,3 +171,20 @@ def test_prefix_aliasing():
result
=
runner
.
invoke
(
cli
,
[
'
test_a
'
],
catch_exceptions
=
False
)
result
=
runner
.
invoke
(
cli
,
[
'
test_a
'
],
catch_exceptions
=
False
)
assert
result
.
exit_code
==
0
,
(
result
.
exit_code
,
result
.
output
)
assert
result
.
exit_code
==
0
,
(
result
.
exit_code
,
result
.
output
)
assert
'
AAA
'
in
result
.
output
,
(
result
.
exit_code
,
result
.
output
)
assert
'
AAA
'
in
result
.
output
,
(
result
.
exit_code
,
result
.
output
)
def
test_config_dump
():
@click.group
(
cls
=
AliasedGroup
)
def
cli
():
pass
@click.command
(
cls
=
ConfigCommand
)
@click.option
(
'
-t
'
,
'
--test
'
,
required
=
True
,
default
=
"
/my/path/test.txt
"
,
help
=
"
Path leading to test blablabla
"
,
cls
=
ResourceOption
)
@verbosity_option
()
def
test
(
config
,
test
,
**
kwargs
):
pass
runner
=
CliRunner
()
with
runner
.
isolated_filesystem
():
result
=
runner
.
invoke
(
cli
,
[
'
test
'
,
'
-dc
'
,
'
TEST_CONF
'
],
catch_exceptions
=
False
)
assert
result
.
exit_code
!=
0
,
(
result
.
exit_code
,
result
.
output
)
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