Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tree_maker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
ABP Computing
ABP Computing Sandbox
tree_maker
Commits
a7ccd1fa
Commit
a7ccd1fa
authored
3 years ago
by
Guido Sterbini
Browse files
Options
Downloads
Patches
Plain Diff
Adding the py_to_yaml
parent
793561c7
No related branches found
Branches containing commit
No related tags found
2 merge requests
!2
Dev v0.0.1
,
!1
Dev v0.0.1
Pipeline
#2790146
passed
3 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/source/api.rst
+5
-0
5 additions, 0 deletions
docs/source/api.rst
tree_maker/__init__.py
+1
-0
1 addition, 0 deletions
tree_maker/__init__.py
tree_maker/general.py
+11
-0
11 additions, 0 deletions
tree_maker/general.py
with
17 additions
and
0 deletions
docs/source/api.rst
+
5
−
0
View file @
a7ccd1fa
...
...
@@ -7,6 +7,11 @@ NodeJob.py
.. autoclass:: tree_maker.NodeJob.NodeJob
:members:
general.py
------
.. automodule:: tree_maker.general
:members:
tag.py
------
.. automodule:: tree_maker.tag
...
...
This diff is collapsed.
Click to expand it.
tree_maker/__init__.py
+
1
−
0
View file @
a7ccd1fa
...
...
@@ -11,6 +11,7 @@ from .general import tree_from_yaml
from
.general
import
tree_from_json
from
.general
import
from_yaml
from
.general
import
from_json
from
.general
import
py_to_yaml
from
.tag
import
*
from
.tag_json
import
*
...
...
This diff is collapsed.
Click to expand it.
tree_maker/general.py
+
11
−
0
View file @
a7ccd1fa
...
...
@@ -10,14 +10,17 @@ import orjson
ryaml
=
ruamel
.
yaml
.
YAML
()
def
tree_from_yaml
(
filename
=
'
tree.yaml
'
):
'''
Import the tree structure from the yaml formatted *filename*
'''
with
open
(
filename
,
"
r
"
)
as
file
:
return
DictImporter
(
nodecls
=
NodeJob
).
import_
(
yaml
.
load
(
file
,
Loader
=
yaml
.
FullLoader
))
def
tree_from_json
(
filename
=
'
tree.json
'
):
'''
Import the tree structure from the json formatted *filename*
'''
with
open
(
filename
,
"
r
"
)
as
file
:
return
DictImporter
(
nodecls
=
NodeJob
).
import_
(
orjson
.
loads
(
file
.
read
()))
def
from_yaml
(
filename
):
'''
Load the *filename* yaml file
'''
try
:
with
open
(
filename
,
'
r
'
)
as
file
:
return
ryaml
.
load
(
file
)
...
...
@@ -26,9 +29,17 @@ def from_yaml(filename):
return
{}
def
from_json
(
filename
,
verbose
=
False
):
'''
Load the *filename* json file
'''
try
:
with
open
(
filename
,
'
r
'
)
as
file
:
return
orjson
.
loads
(
file
.
read
())
except
Exception
as
e
:
if
verbose
:
print
(
e
)
return
{}
def
py_to_yaml
(
filename
):
'''
Convert the *filename*.py (containg dictionaries) to an
equivalent *filename*.yaml
'''
import
filename
as
my_dict
with
open
(
filename
+
'
.yaml
'
,
'
w
'
)
as
fid
:
yaml
.
dump
(
my_dict
,
fid
)
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