Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cb-util
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Alt
cb-util
Commits
4db8b35b
Commit
4db8b35b
authored
1 year ago
by
Christoph Alt
Browse files
Options
Downloads
Patches
Plain Diff
added the yaml utility for the gitlab ci
parent
8a6396ab
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cbutil/yaml_util.py
+45
-0
45 additions, 0 deletions
cbutil/yaml_util.py
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
tests/test_yaml_util.py
+8
-0
8 additions, 0 deletions
tests/test_yaml_util.py
with
54 additions
and
0 deletions
cbutil/yaml_util.py
0 → 100644
+
45
−
0
View file @
4db8b35b
import
yaml
class
Reference
:
yaml_tag
=
'
!reference
'
def
__init__
(
self
,
values
):
self
.
_values
=
values
def
reference_constructor
(
loader
:
yaml
.
SafeLoader
,
node
:
yaml
.
nodes
.
CollectionNode
)
->
Reference
:
return
Reference
(
loader
.
construct_sequence
(
node
))
def
reference_representer
(
dumper
:
yaml
.
SafeDumper
,
ref
:
Reference
)
->
yaml
.
nodes
.
SequenceNode
:
return
dumper
.
represent_sequence
(
Reference
.
yaml_tag
,
ref
.
_values
,
flow_style
=
True
)
def
loader
():
loader
=
yaml
.
SafeLoader
loader
.
add_constructor
(
Reference
.
yaml_tag
,
reference_constructor
)
return
loader
def
dumper
():
dumper
=
yaml
.
SafeDumper
dumper
.
add_representer
(
Reference
,
reference_representer
)
dumper
.
ignore_aliases
=
lambda
*
args
:
True
return
dumper
def
load_script
(
raw_strings
):
if
isinstance
(
raw_strings
,
str
):
raw_strings
=
[
raw_strings
]
for
raw_string
in
raw_strings
:
yield
yaml
.
load
(
raw_string
,
Loader
=
loader
())
def
print_yaml_file
(
config
:
dict
)
->
str
:
return
yaml
.
dump
(
config
,
default_flow_style
=
False
,
line_break
=
False
,
width
=
120
,
Dumper
=
dumper
(),
sort_keys
=
False
)
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
0
View file @
4db8b35b
...
...
@@ -18,6 +18,7 @@ dependencies = [
"numpy"
,
"pandas"
,
"importlib_resources ; python_version<'3.7'"
,
"pyyaml"
,
]
[project.optional-dependencies]
...
...
This diff is collapsed.
Click to expand it.
tests/test_yaml_util.py
0 → 100644
+
8
−
0
View file @
4db8b35b
from
cbutil.yaml_util
import
load_script
,
dumper
import
yaml
def
test_load_script
():
test_string
=
"
before_script:
\n
-!reference [.load_cbutil, script]
\n
"""
actual = yaml.dump(next(load_script(test_string)), Dumper=dumper())
assert actual.replace(
"
"
,
""
).replace(
"
\
n
"
,
""
) == test_string.replace(
"
"
,
""
).replace(
"
\
n
"
,
""
)
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