Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exp-runner
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Christopher Spinrath
exp-runner
Commits
bd7acd91
Commit
bd7acd91
authored
1 month ago
by
Christopher Spinrath
Browse files
Options
Downloads
Patches
Plain Diff
Add experimental exp2sh converter
The converter is not feature complete!
parent
161f6547
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
exp2sh.py
+98
-0
98 additions, 0 deletions
exp2sh.py
run-exp.py
+20
-0
20 additions, 0 deletions
run-exp.py
with
118 additions
and
0 deletions
exp2sh.py
0 → 100755
+
98
−
0
View file @
bd7acd91
#!/usr/bin/env python3
import
importlib
import
pathlib
import
click
import
structlog
exprunner
=
importlib
.
import_module
(
'
run-exp
'
)
# logger = structlog.get_logger()
def
drop_log_msgs
(
*
_1
,
**
_2
):
raise
structlog
.
DropEvent
structlog
.
configure
(
processors
=
[
drop_log_msgs
])
def
print_stmt
(
stmt
,
indent
):
print
(
f
"
{
"
"
*
indent
}{
stmt
}
"
,
flush
=
True
)
def
translate_var_init
(
variable
,
variable_map
,
indent
):
sh_var_name
=
variable_map
[
variable
.
name
].
strip
(
"
$
"
)
# remove leading $
if
isinstance
(
variable
,
exprunner
.
SimpleVariable
):
values
=
variable
.
evaluate
(
variable_map
)
if
len
(
values
)
==
1
:
print_stmt
(
f
"
{
sh_var_name
}
=
\"
{
values
[
0
]
}
\"
"
,
indent
)
return
False
else
:
print
()
print_stmt
(
f
"
for
{
sh_var_name
}
in
{
"
"
.
join
(
f
"
\"
{
v
}
\
""
for
v
in
values
)
}
"
,
indent
)
print_stmt
(
"
do
"
,
indent
)
return
True
if
isinstance
(
variable
,
exprunner
.
RangeVariable
):
print
()
print_stmt
(
f
"
for
{
sh_var_name
}
in $(seq
{
variable
.
lower
}
{
variable
.
step
}
{
variable
.
upper
}
)
"
,
indent
)
print_stmt
(
"
do
"
,
indent
)
return
True
if
isinstance
(
variable
,
exprunner
.
FileVariable
):
directory_str
=
variable
.
directory_str
.
format
(
**
variable_map
)
print
()
print_stmt
(
f
"
for
{
sh_var_name
}
in
{
directory_str
}
/*
"
,
indent
)
print_stmt
(
"
do
"
,
indent
)
if
variable
.
basename_only
:
print_stmt
(
f
"
{
sh_var_name
}
=$(basename $
{
sh_var_name
}
)
"
,
indent
+
1
)
return
True
return
False
@click.command
()
@click.argument
(
"
config_file
"
,
type
=
click
.
Path
(
exists
=
True
,
file_okay
=
True
,
dir_okay
=
False
,
readable
=
True
,
path_type
=
pathlib
.
Path
))
@click.option
(
"
--global-timeout
"
,
type
=
click
.
IntRange
(
1
),
default
=
7200
)
@click.option
(
"
--dry-run
"
,
is_flag
=
True
)
def
main
(
config_file
,
global_timeout
,
dry_run
):
c
=
exprunner
.
Config
.
from_file
(
config_file
)
print
(
"
#!/usr/bin/env bash
"
)
print
()
print
(
"
# WARNING: This script ignoes
'
if-(not)-variable
'
conditions!
"
)
print
()
# we precompute all variable values to be able to abort early in case of a problem,
# for instance, if a file does not exist
variable_map
=
{
v
.
name
:
f
"
$
{
v
.
name
.
upper
().
replace
(
'
-
'
,
'
_
'
)
}
"
for
v
in
c
.
variables
}
indent
=
0
num_for_loops
=
0
for
variable
in
c
.
variables
:
if
translate_var_init
(
variable
,
variable_map
,
indent
):
num_for_loops
+=
1
indent
+=
1
print
()
print_stmt
(
f
"
for EXP_RUNNER_REPETITION in $(seq 0
{
c
.
repetitions
}
)
"
,
indent
)
print_stmt
(
"
do
"
,
indent
)
for
task
in
c
.
tasks
:
print_stmt
(
f
"
#
{
task
.
name
}
"
,
indent
+
1
)
print
(
"
"
*
(
indent
+
1
),
flush
=
True
,
end
=
''
)
if
dry_run
:
print
(
"
echo
"
,
flush
=
True
,
end
=
''
)
task
.
run
({
k
:
f
"
\\
{
v
}
"
for
k
,
v
in
variable_map
.
items
()},
global_timeout
,
True
)
for
_
in
range
(
num_for_loops
+
1
):
print_stmt
(
"
done
"
,
indent
)
indent
-=
1
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
run-exp.py
+
20
−
0
View file @
bd7acd91
...
@@ -54,6 +54,18 @@ class RangeVariable(SimpleVariable):
...
@@ -54,6 +54,18 @@ class RangeVariable(SimpleVariable):
def
__init__
(
self
,
name
,
lower
,
upper
,
step
):
def
__init__
(
self
,
name
,
lower
,
upper
,
step
):
super
().
__init__
(
name
,
list
(
range
(
lower
,
upper
+
1
,
step
)))
super
().
__init__
(
name
,
list
(
range
(
lower
,
upper
+
1
,
step
)))
@property
def
lower
(
self
):
return
self
.
_lower
@property
def
upper
(
self
):
return
self
.
_upper
@property
def
step
(
self
):
return
self
.
_step
class
FileVariable
(
Variable
):
class
FileVariable
(
Variable
):
def
__init__
(
self
,
name
,
directory_str
,
basename_only
):
def
__init__
(
self
,
name
,
directory_str
,
basename_only
):
...
@@ -61,6 +73,14 @@ class FileVariable(Variable):
...
@@ -61,6 +73,14 @@ class FileVariable(Variable):
self
.
_directory_str
=
directory_str
self
.
_directory_str
=
directory_str
self
.
_basename_only
=
basename_only
self
.
_basename_only
=
basename_only
@property
def
directory_str
(
self
):
return
self
.
_directory_str
@property
def
basename_only
(
self
):
return
self
.
_basename_only
def
evaluate
(
self
,
variable_mapping
):
def
evaluate
(
self
,
variable_mapping
):
directory
=
pathlib
.
Path
(
self
.
_directory_str
.
format
(
**
variable_mapping
))
directory
=
pathlib
.
Path
(
self
.
_directory_str
.
format
(
**
variable_mapping
))
directory
=
directory
.
expanduser
()
directory
=
directory
.
expanduser
()
...
...
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