Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
remi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
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
RobotLearn
RemI (Remote Inria)
remi
Commits
f7670ae3
Commit
f7670ae3
authored
4 years ago
by
LEPAGE Gaetan
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug when running `percu init` (caused by default values)
parent
4bfcf876
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
percu/cli.py
+70
-52
70 additions, 52 deletions
percu/cli.py
with
70 additions
and
52 deletions
percu/cli.py
+
70
−
52
View file @
f7670ae3
...
@@ -6,7 +6,6 @@ Command line interface for PeRCU
...
@@ -6,7 +6,6 @@ Command line interface for PeRCU
import
sys
import
sys
import
collections
import
collections
import
subprocess
from
os
import
getcwd
from
os
import
getcwd
from
os.path
import
isfile
,
isdir
from
os.path
import
isfile
,
isdir
...
@@ -15,8 +14,10 @@ import percu as _percu
...
@@ -15,8 +14,10 @@ import percu as _percu
from
percu.utils
import
print_warning
,
print_error
from
percu.utils
import
print_warning
,
print_error
from
percu.config
import
Config
from
percu.config
import
Config
# Common options
# Common options, arguments and their eventual callbacks
def
_callback_option_hostname
(
ctx
,
param
,
value
)
->
str
:
# pylint: disable=unused-argument
# pylint: disable=unused-argument
def
_callback_option_hostname
(
ctx
,
param
,
value
)
->
str
:
config
:
Config
=
Config
.
get
()
config
:
Config
=
Config
.
get
()
# If no hostname was provided, use the one from the config file.
# If no hostname was provided, use the one from the config file.
...
@@ -38,8 +39,8 @@ def _callback_option_hostname(ctx, param, value) -> str: # pylint: disable=unus
...
@@ -38,8 +39,8 @@ def _callback_option_hostname(ctx, param, value) -> str: # pylint: disable=unus
return
value
return
value
# pylint: disable=unused-argument
def
_callback_option_script
(
ctx
,
param
,
value
)
->
str
:
# pylint: disable=unused-argument
def
_callback_option_script
(
ctx
,
param
,
value
)
->
str
:
# Make sure the script is a valid file
# Make sure the script is a valid file
if
not
isfile
(
value
):
if
not
isfile
(
value
):
print_error
(
f
'
Script `
{
value
}
` does not exist.
'
)
print_error
(
f
'
Script `
{
value
}
` does not exist.
'
)
...
@@ -47,6 +48,21 @@ def _callback_option_script(ctx, param, value) -> str: # pylint: disable=unused
...
@@ -47,6 +48,21 @@ def _callback_option_script(ctx, param, value) -> str: # pylint: disable=unused
return
value
return
value
# pylint: disable=unused-argument
def
_callback_argument_command
(
ctx
,
param
,
value
)
->
str
:
if
len
(
value
)
==
0
:
print_error
(
text
=
'
No command provided. Exiting
'
)
sys
.
exit
(
1
)
return
value
# pylint: disable=unused-argument
def
_callback_argument_output_path_default
(
ctx
,
param
,
value
)
->
str
:
if
value
==
''
:
return
Config
.
get
().
output_path
return
value
_option_hostname
=
click
.
option
(
'
-h
'
,
'
--hostname
'
,
_option_hostname
=
click
.
option
(
'
-h
'
,
'
--hostname
'
,
default
=
''
,
default
=
''
,
...
@@ -77,6 +93,9 @@ _option_background = click.option('-b', '--background',
...
@@ -77,6 +93,9 @@ _option_background = click.option('-b', '--background',
_option_container
=
click
.
option
(
'
-c
'
,
'
--use-container
'
,
_option_container
=
click
.
option
(
'
-c
'
,
'
--use-container
'
,
is_flag
=
True
,
is_flag
=
True
,
help
=
'
Run code within the singularity container
'
)
help
=
'
Run code within the singularity container
'
)
_argument_command
=
click
.
argument
(
'
command
'
,
nargs
=-
1
,
callback
=
_callback_argument_command
)
def
_option_force
(
help_message
:
str
,
def
_option_force
(
help_message
:
str
,
default
:
bool
=
False
):
default
:
bool
=
False
):
return
click
.
option
(
'
-f
'
,
'
--force
'
,
return
click
.
option
(
'
-f
'
,
'
--force
'
,
...
@@ -118,10 +137,13 @@ def percu(ctx) -> None:
...
@@ -118,10 +137,13 @@ def percu(ctx) -> None:
# remote`)
# remote`)
pass
pass
##################
# Initialization #
##################
@percu.command
()
@percu.command
()
def
init
()
->
None
:
def
init
()
->
None
:
"""
"""
Initialize the project in the current working directory. Generate the config files.
Initialize the project in the current working directory. Generate the config
uration
files.
"""
"""
_percu
.
core
.
init
()
_percu
.
core
.
init
()
...
@@ -130,11 +152,35 @@ def init() -> None:
...
@@ -130,11 +152,35 @@ def init() -> None:
@_option_hostname
@_option_hostname
def
setup
(
hostname
:
str
)
->
None
:
def
setup
(
hostname
:
str
)
->
None
:
"""
"""
S
ync the project, update packages
.
S
et up remote project location and install virtual environment if any
.
"""
"""
_percu
.
core
.
setup
(
hostname
=
hostname
)
_percu
.
core
.
setup
(
hostname
=
hostname
)
@percu.command
()
@_option_hostname
def
update_packages
(
hostname
:
str
)
->
None
:
"""
Update the packages on the remote workstation.
"""
_percu
.
core
.
update_packages
(
hostname
=
hostname
)
@percu.command
()
@_option_hostname
def
prepare
(
hostname
:
str
)
->
None
:
"""
Prepare the remote workstation (setup, virtual environment, pip and dependencies, push project
and update packages).
"""
_percu
.
core
.
setup
(
hostname
=
hostname
)
_percu
.
core
.
push
()
_percu
.
core
.
update_packages
(
hostname
=
hostname
)
###################
# File management #
###################
@percu.command
()
@percu.command
()
@_option_force
(
help_message
=
'
Push the project even though no local changes were noticed.
'
)
@_option_force
(
help_message
=
'
Push the project even though no local changes were noticed.
'
)
def
push
(
force
:
bool
)
->
None
:
def
push
(
force
:
bool
)
->
None
:
...
@@ -143,6 +189,7 @@ def push(force: bool) -> None:
...
@@ -143,6 +189,7 @@ def push(force: bool) -> None:
"""
"""
if
Config
.
get
().
working_from_inria
:
if
Config
.
get
().
working_from_inria
:
print_warning
(
"
You seem to be working directly from your Inria desktop.
"
)
print_warning
(
"
You seem to be working directly from your Inria desktop.
"
)
# TODO not exactly what happens because we read project_remote_path from config file
print_warning
(
f
"
Nothing will get
'
pushed
'
and the current working directory (`
{
getcwd
()
}
`)
"
print_warning
(
f
"
Nothing will get
'
pushed
'
and the current working directory (`
{
getcwd
()
}
`)
"
"
will be used by the cluster and other Inria desktops to access the
"
"
will be used by the cluster and other Inria desktops to access the
"
"
project.
"
)
"
project.
"
)
...
@@ -153,8 +200,9 @@ def push(force: bool) -> None:
...
@@ -153,8 +200,9 @@ def push(force: bool) -> None:
@percu.command
()
@percu.command
()
@click.argument
(
'
remote_path
'
,
@click.argument
(
'
remote_path
'
,
default
=
Config
.
get
().
output_path
,
default
=
''
,
type
=
str
,
type
=
str
,
callback
=
_callback_argument_output_path_default
,
nargs
=
1
)
nargs
=
1
)
@_option_force
(
help_message
=
'
Do not prompt for any confirmation.
'
)
@_option_force
(
help_message
=
'
Do not prompt for any confirmation.
'
)
def
pull
(
remote_path
:
str
,
def
pull
(
remote_path
:
str
,
...
@@ -170,8 +218,9 @@ def pull(remote_path: str,
...
@@ -170,8 +218,9 @@ def pull(remote_path: str,
@percu.command
()
@percu.command
()
@_option_force
(
help_message
=
'
Do not ask for confirmation before deleting the folder content.
'
)
@_option_force
(
help_message
=
'
Do not ask for confirmation before deleting the folder content.
'
)
@click.argument
(
'
directory
'
,
@click.argument
(
'
directory
'
,
default
=
Config
.
get
().
output_path
,
default
=
''
,
type
=
str
,
type
=
str
,
callback
=
_callback_argument_output_path_default
,
nargs
=
1
)
nargs
=
1
)
def
clean
(
directory
:
str
,
def
clean
(
directory
:
str
,
force
:
bool
)
->
None
:
force
:
bool
)
->
None
:
...
@@ -181,39 +230,6 @@ def clean(directory: str,
...
@@ -181,39 +230,6 @@ def clean(directory: str,
_percu
.
core
.
clean
(
directory
=
directory
,
_percu
.
core
.
clean
(
directory
=
directory
,
force
=
force
)
force
=
force
)
################
# Installation #
################
@percu.command
()
@_option_hostname
def
update_packages
(
hostname
:
str
)
->
None
:
"""
Update the packages on the remote workstation.
"""
_percu
.
core
.
update_packages
(
hostname
=
hostname
)
@percu.command
()
@_option_hostname
def
prepare
(
hostname
:
str
)
->
None
:
"""
Prepare the remote workstation (setup pip and dependencies, push project and update packages).
"""
_percu
.
core
.
setup
(
hostname
=
hostname
)
_percu
.
core
.
push
()
_percu
.
core
.
update_packages
(
hostname
=
hostname
)
@percu.command
()
@_option_force
(
help_message
=
'
Build the container even if the sif image already exists.
'
)
def
build_container
(
force
:
bool
=
False
)
->
None
:
"""
Build the singularity container on the remote desktop.
"""
_percu
.
core
.
push
()
_percu
.
cluster
.
build_singularity_container
(
force
=
force
)
##########
##########
# Remote #
# Remote #
##########
##########
...
@@ -273,7 +289,7 @@ def remote_script(script_name: str,
...
@@ -273,7 +289,7 @@ def remote_script(script_name: str,
@_option_container
@_option_container
@_option_no_push
@_option_no_push
@_option_no_build
@_option_no_build
@
click.
argument
(
'
command
'
,
nargs
=-
1
)
@
_
argument
_
command
def
remote_command
(
command
:
list
[
str
],
def
remote_command
(
command
:
list
[
str
],
background
:
bool
,
background
:
bool
,
hostname
:
str
,
hostname
:
str
,
...
@@ -281,10 +297,6 @@ def remote_command(command: list[str],
...
@@ -281,10 +297,6 @@ def remote_command(command: list[str],
no_push
:
bool
,
no_push
:
bool
,
no_build
:
bool
)
->
None
:
no_build
:
bool
)
->
None
:
if
len
(
command
)
==
0
:
print_error
(
text
=
'
No command provided. Exiting
'
)
sys
.
exit
(
1
)
_percu
.
remote
.
remote
(
sub_command
=
'
command
'
,
_percu
.
remote
.
remote
(
sub_command
=
'
command
'
,
command
=
command
,
command
=
command
,
background
=
background
,
background
=
background
,
...
@@ -306,6 +318,16 @@ def remote_interactive(hostname: str,
...
@@ -306,6 +318,16 @@ def remote_interactive(hostname: str,
###########
###########
# Cluster #
# Cluster #
###########
###########
@percu.command
()
@_option_force
(
help_message
=
'
Build the container even if the sif image already exists.
'
)
def
build_container
(
force
:
bool
=
False
)
->
None
:
"""
Build the singularity container on the remote desktop.
"""
_percu
.
core
.
push
()
_percu
.
cluster
.
build_singularity_container
(
force
=
force
)
@percu.group
(
cls
=
OrderedGroup
,
invoke_without_command
=
True
)
@percu.group
(
cls
=
OrderedGroup
,
invoke_without_command
=
True
)
@_option_script
@_option_script
@_option_no_push
@_option_no_push
...
@@ -341,15 +363,11 @@ def cluster_script(script_name: str,
...
@@ -341,15 +363,11 @@ def cluster_script(script_name: str,
@cluster.command
(
'
command
'
)
@cluster.command
(
'
command
'
)
@_option_no_push
@_option_no_push
@_option_no_build
@_option_no_build
@
click.
argument
(
'
command
'
,
nargs
=-
1
)
@
_
argument
_
command
def
cluster_command
(
command
:
list
[
str
],
def
cluster_command
(
command
:
list
[
str
],
no_push
:
bool
,
no_push
:
bool
,
no_build
:
bool
)
->
None
:
no_build
:
bool
)
->
None
:
if
len
(
command
)
==
0
:
print_error
(
'
No command provided. Exiting
'
)
sys
.
exit
(
1
)
_percu
.
cluster
.
cluster
(
sub_command
=
'
command
'
,
_percu
.
cluster
.
cluster
(
sub_command
=
'
command
'
,
command
=
command
,
command
=
command
,
no_push
=
no_push
,
no_push
=
no_push
,
...
...
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