Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
conda
fsl-ci-rules
Commits
395fae48
Commit
395fae48
authored
Jun 04, 2021
by
Paul McCarthy
🚵
Browse files
RF: Wrap yaml load/dump routines
parent
2c36c5ff
Changes
4
Hide whitespace changes
Inline
Side-by-side
fsl_ci/__init__.py
View file @
395fae48
...
...
@@ -8,6 +8,7 @@
import
os.path
as
op
import
os
import
io
import
sys
import
errno
import
shlex
...
...
@@ -17,6 +18,8 @@ import tempfile
import
contextlib
as
ctxlib
import
subprocess
as
sp
import
ruamel.yaml
as
yaml
__version__
=
'0.6.14'
"""Current version of the fsl-ci-rules."""
...
...
@@ -124,6 +127,20 @@ def lockdir(dirname):
os
.
unlink
(
lockfile
)
def
loadyaml
(
s
):
"""Loads a YAML string, returning a dict-like. """
return
yaml
.
YAML
().
load
(
s
)
def
dumpyaml
(
o
):
"""Dumps the given YAML to a string. """
s
=
io
.
StringIO
()
y
=
yaml
.
YAML
()
y
.
default_flow_style
=
False
y
.
dump
(
o
,
s
)
return
s
.
getvalue
()
class
CaptureStdout
:
"""Context manager which captures stdout and stderr. """
...
...
fsl_ci/conda.py
View file @
395fae48
...
...
@@ -16,11 +16,11 @@ from unittest import mock
from
typing
import
Dict
,
List
,
Union
,
Tuple
,
Optional
import
networkx
as
nx
import
jinja2
as
j2
import
yaml
import
networkx
as
nx
import
jinja2
as
j2
from
fsl_ci.gitlab
import
(
http_request
,
download_file
)
from
fsl_ci
import
loadyaml
from
fsl_ci.gitlab
import
http_request
,
download_file
def
gen_recipe_path
(
project_path
):
...
...
@@ -111,7 +111,7 @@ def load_meta_yaml(filename):
template
=
j2
.
Template
(
filename
)
meta
=
template
.
render
(
**
env
)
meta
=
yaml
.
load
(
meta
,
Loader
=
yaml
.
Loader
)
meta
=
loadyaml
(
meta
)
return
meta
...
...
fsl_ci/recipe.py
View file @
395fae48
...
...
@@ -7,9 +7,9 @@
import
os.path
as
op
import
yaml
import
jinja2
as
j2
from
fsl_ci
import
dumpyaml
from
fsl_ci.gitlab
import
gen_repository_url
...
...
@@ -67,9 +67,9 @@ def create_python_recipe_template(recipe_dir,
if
meta
is
not
None
:
if
'test'
in
meta
:
template_meta
[
'test'
]
=
yaml
.
dump
({
'test'
:
meta
[
'test'
]})
template_meta
[
'test'
]
=
dump
yaml
({
'test'
:
meta
[
'test'
]})
if
'about'
in
meta
:
template_meta
[
'about'
]
=
yaml
.
dump
({
'about'
:
meta
[
'about'
]})
template_meta
[
'about'
]
=
dump
yaml
({
'about'
:
meta
[
'about'
]})
# we render the template(s) in the loop below
templates
=
[(
metayaml_template
,
metayaml_dest
)]
...
...
fsl_ci/utils/configure_repositories.py
View file @
395fae48
...
...
@@ -13,8 +13,9 @@ import textwrap as tw
import
argparse
import
urllib.error
as
urlerror
import
yaml
from
fsl_ci
import
(
loadyaml
,
dumpyaml
)
from
fsl_ci.gitlab
import
(
get_project_metadata
,
set_project_metadata
,
list_project_branches
,
...
...
@@ -72,6 +73,7 @@ def patch_gitlab_ci_yml(project_path, server, token, ci_path):
"""
ciyml
,
contents
=
get_gitlab_ci_yml
(
project_path
,
server
,
token
)
contents
=
loadyaml
(
contents
)
rulespath
,
rulesrepo
=
ci_path
.
split
(
'@'
)
changes_made
=
False
...
...
@@ -95,9 +97,6 @@ def patch_gitlab_ci_yml(project_path, server, token, ci_path):
'already appears to be active - skipping.'
)
return
with
io
.
StringIO
(
contents
)
as
f
:
contents
=
yaml
.
load
(
f
,
Loader
=
yaml
.
Loader
)
cistages
=
[
'fsl-ci-pre'
,
'fsl-ci-build'
,
'fsl-ci-test'
,
'fsl-ci-deploy'
]
stages
=
[
s
for
s
in
contents
[
'stages'
]
if
s
not
in
cistages
]
+
cistages
...
...
@@ -116,9 +115,8 @@ def patch_gitlab_ci_yml(project_path, server, token, ci_path):
changes_made
=
True
contents
[
'include'
].
append
(
include
)
if
changes_made
:
contents
=
yaml
.
dump
(
contents
,
Dumper
=
yaml
.
Dumper
)
contents
=
dumpyaml
(
contents
)
create_branch
(
project_path
,
branch
,
'master'
,
server
,
token
)
update_file
(
project_path
,
ciyml
,
contents
,
msg
,
server
,
token
,
branch
)
open_merge_request
(
project_path
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment