Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ewokscore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
workflow
ewoks
ewokscore
Compare revisions
4f8c67beacaf3604a849cc046e81d9751a32c415 to 375fee02835bdac411191033debaaa464a9e3fc0
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
workflow/ewoks/ewokscore
Select target project
No results found
375fee02835bdac411191033debaaa464a9e3fc0
Select Git revision
Swap
Target
workflow/ewoks/ewokscore
Select target project
tvincent/ewokscore
workflow/ewoks/ewokscore
2 results
4f8c67beacaf3604a849cc046e81d9751a32c415
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Add support of Path filepaths in `convert_graph`
· 5ceb285d
Loic Huder
authored
6 months ago
5ceb285d
Merge branch 'convert-path' into 'main'
· 375fee02
Loic Huder
authored
6 months ago
Add support of Path filepaths in `convert_graph` See merge request
!234
375fee02
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ewokscore/graph/serialize.py
+11
-5
11 additions, 5 deletions
src/ewokscore/graph/serialize.py
src/ewokscore/graph/taskgraph.py
+3
-2
3 additions, 2 deletions
src/ewokscore/graph/taskgraph.py
src/ewokscore/tests/test_examples.py
+10
-10
10 additions, 10 deletions
src/ewokscore/tests/test_examples.py
with
24 additions
and
17 deletions
src/ewokscore/graph/serialize.py
View file @
375fee02
...
@@ -25,16 +25,16 @@ GraphRepresentation = enum.Enum(
...
@@ -25,16 +25,16 @@ GraphRepresentation = enum.Enum(
def
dump
(
def
dump
(
graph
:
networkx
.
DiGraph
,
graph
:
networkx
.
DiGraph
,
destination
=
None
,
destination
:
Optional
[
Union
[
str
,
Path
]]
=
None
,
representation
:
Optional
[
Union
[
GraphRepresentation
,
str
]]
=
None
,
representation
:
Optional
[
Union
[
GraphRepresentation
,
str
]]
=
None
,
**
kw
,
**
kw
,
)
->
Union
[
str
,
dict
]:
)
->
Union
[
str
,
Path
,
dict
]:
"""
From runtime to persistent representation
"""
"""
From runtime to persistent representation
"""
if
isinstance
(
representation
,
str
):
if
isinstance
(
representation
,
str
):
representation
=
GraphRepresentation
.
__members__
[
representation
]
representation
=
GraphRepresentation
.
__members__
[
representation
]
if
representation
is
None
:
if
representation
is
None
:
if
isinstance
(
destination
,
str
):
if
isinstance
(
destination
,
(
str
,
Path
)
):
filename
=
destination
.
lower
()
filename
=
str
(
destination
)
.
lower
()
if
filename
.
endswith
(
"
.json
"
):
if
filename
.
endswith
(
"
.json
"
):
representation
=
GraphRepresentation
.
json
representation
=
GraphRepresentation
.
json
elif
filename
.
endswith
((
"
.yml
"
,
"
.yaml
"
)):
elif
filename
.
endswith
((
"
.yml
"
,
"
.yaml
"
)):
...
@@ -46,6 +46,8 @@ def dump(
...
@@ -46,6 +46,8 @@ def dump(
return
_networkx_to_dict
(
graph
)
return
_networkx_to_dict
(
graph
)
if
representation
==
GraphRepresentation
.
json
:
if
representation
==
GraphRepresentation
.
json
:
if
destination
is
None
:
raise
TypeError
(
"
Destination should be specified when dumping to json
"
)
dictrepr
=
dump
(
graph
)
dictrepr
=
dump
(
graph
)
makedirs_from_filename
(
destination
)
makedirs_from_filename
(
destination
)
kw
.
setdefault
(
"
indent
"
,
2
)
kw
.
setdefault
(
"
indent
"
,
2
)
...
@@ -58,6 +60,8 @@ def dump(
...
@@ -58,6 +60,8 @@ def dump(
return
json
.
dumps
(
dictrepr
,
**
kw
)
return
json
.
dumps
(
dictrepr
,
**
kw
)
if
representation
==
GraphRepresentation
.
yaml
:
if
representation
==
GraphRepresentation
.
yaml
:
if
destination
is
None
:
raise
TypeError
(
"
Destination should be specified when dumping to yaml
"
)
dictrepr
=
dump
(
graph
)
dictrepr
=
dump
(
graph
)
makedirs_from_filename
(
destination
)
makedirs_from_filename
(
destination
)
with
open
(
destination
,
mode
=
"
w
"
)
as
f
:
with
open
(
destination
,
mode
=
"
w
"
)
as
f
:
...
@@ -65,7 +69,9 @@ def dump(
...
@@ -65,7 +69,9 @@ def dump(
return
destination
return
destination
if
representation
==
GraphRepresentation
.
json_module
:
if
representation
==
GraphRepresentation
.
json_module
:
package
,
_
,
file
=
destination
.
rpartition
(
"
.
"
)
if
destination
is
None
:
raise
TypeError
(
"
Destination should be specified when dumping to json
"
)
package
,
_
,
file
=
str
(
destination
).
rpartition
(
"
.
"
)
assert
package
,
f
"
No package provided when saving graph to
'
{
destination
}
'"
assert
package
,
f
"
No package provided when saving graph to
'
{
destination
}
'"
destination
=
os
.
path
.
join
(
_package_path
(
package
),
f
"
{
file
}
.json
"
)
destination
=
os
.
path
.
join
(
_package_path
(
package
),
f
"
{
file
}
.json
"
)
return
dump
(
graph
,
destination
=
destination
,
representation
=
"
json
"
,
**
kw
)
return
dump
(
graph
,
destination
=
destination
,
representation
=
"
json
"
,
**
kw
)
...
...
This diff is collapsed.
Click to expand it.
src/ewokscore/graph/taskgraph.py
View file @
375fee02
from
pathlib
import
Path
from
typing
import
Hashable
,
Optional
,
Union
from
typing
import
Hashable
,
Optional
,
Union
import
networkx
import
networkx
from
ewoksutils.import_utils
import
qualname
from
ewoksutils.import_utils
import
qualname
...
@@ -107,10 +108,10 @@ class TaskGraph:
...
@@ -107,10 +108,10 @@ class TaskGraph:
def
dump
(
def
dump
(
self
,
self
,
destination
=
None
,
destination
:
Optional
[
Union
[
str
,
Path
]]
=
None
,
representation
:
Optional
[
Union
[
serialize
.
GraphRepresentation
,
str
]]
=
None
,
representation
:
Optional
[
Union
[
serialize
.
GraphRepresentation
,
str
]]
=
None
,
**
kw
,
**
kw
,
)
->
Optional
[
Union
[
str
,
dict
]]:
)
->
Optional
[
Union
[
str
,
Path
,
dict
]]:
return
serialize
.
dump
(
return
serialize
.
dump
(
self
.
graph
,
destination
=
destination
,
representation
=
representation
,
**
kw
self
.
graph
,
destination
=
destination
,
representation
=
representation
,
**
kw
)
)
...
...
This diff is collapsed.
Click to expand it.
src/ewokscore/tests/test_examples.py
View file @
375fee02
from
typing
import
Iterable
,
Optional
,
Tuple
from
pathlib
import
Path
import
pytest
import
pytest
from
ewokscore
import
execute_graph
from
ewokscore
import
execute_graph
...
@@ -68,13 +68,14 @@ def test_start_nodes():
...
@@ -68,13 +68,14 @@ def test_start_nodes():
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"
representation
"
,
(
None
,
"
json
"
,
"
json_dict
"
,
"
json_string
"
,
"
yaml
"
)
"
representation
"
,
(
None
,
"
json
"
,
"
json_dict
"
,
"
json_string
"
,
"
yaml
"
)
)
)
def
test_serialize_graph
(
graph_name
,
representation
,
tmpdir
):
@pytest.mark.parametrize
(
"
path_format
"
,
(
str
,
Path
))
def
test_serialize_graph
(
graph_name
,
representation
,
path_format
,
tmpdir
):
graph
,
_
=
get_graph
(
graph_name
)
graph
,
_
=
get_graph
(
graph_name
)
ewoksgraph
=
load_graph
(
graph
)
ewoksgraph
=
load_graph
(
graph
)
if
representation
==
"
yaml
"
:
if
representation
==
"
yaml
"
:
destination
=
str
(
tmpdir
/
"
file.yml
"
)
destination
=
path_format
(
tmpdir
/
"
file.yml
"
)
elif
representation
==
"
json
"
:
elif
representation
==
"
json
"
:
destination
=
str
(
tmpdir
/
"
file.json
"
)
destination
=
path_format
(
tmpdir
/
"
file.json
"
)
else
:
else
:
destination
=
None
destination
=
None
inmemorydump
=
ewoksgraph
.
dump
(
destination
,
representation
=
representation
)
inmemorydump
=
ewoksgraph
.
dump
(
destination
,
representation
=
representation
)
...
@@ -89,17 +90,18 @@ def test_serialize_graph(graph_name, representation, tmpdir):
...
@@ -89,17 +90,18 @@ def test_serialize_graph(graph_name, representation, tmpdir):
@pytest.mark.parametrize
(
"
graph_name
"
,
graph_names
())
@pytest.mark.parametrize
(
"
graph_name
"
,
graph_names
())
def
test_convert_graph
(
graph_name
,
tmpdir
):
@pytest.mark.parametrize
(
"
path_format
"
,
(
str
,
Path
))
def
test_convert_graph
(
graph_name
,
path_format
,
tmpdir
):
graph
,
_
=
get_graph
(
graph_name
)
graph
,
_
=
get_graph
(
graph_name
)
ewoksgraph
=
load_graph
(
graph
)
ewoksgraph
=
load_graph
(
graph
)
assert_convert_graph
(
convert_graph
,
ewoksgraph
,
tmpdir
)
assert_convert_graph
(
convert_graph
,
ewoksgraph
,
path_format
,
tmpdir
)
def
assert_convert_graph
(
def
assert_convert_graph
(
convert_graph
,
convert_graph
,
ewoksgraph
,
ewoksgraph
,
path_format
,
tmpdir
,
tmpdir
,
representations
:
Optional
[
Iterable
[
Tuple
[
dict
,
dict
,
Optional
[
str
]]]]
=
None
,
):
):
"""
All graph `representations` need to be known by `convert_graph`. It will always
"""
All graph `representations` need to be known by `convert_graph`. It will always
test the basic representations (e.g. json and yaml) in addition to the provided
test the basic representations (e.g. json and yaml) in addition to the provided
...
@@ -115,15 +117,13 @@ def assert_convert_graph(
...
@@ -115,15 +117,13 @@ def assert_convert_graph(
(
dict
(),
{
"
representation
"
:
"
json_dict
"
},
None
),
(
dict
(),
{
"
representation
"
:
"
json_dict
"
},
None
),
(
dict
(),
{
"
representation
"
:
"
json_string
"
},
None
),
(
dict
(),
{
"
representation
"
:
"
json_string
"
},
None
),
]
]
if
representations
:
conversion_chain
.
extend
(
representations
)
conversion_chain
.
append
(
non_serialized_representation
)
conversion_chain
.
append
(
non_serialized_representation
)
source
=
ewoksgraph
source
=
ewoksgraph
for
convert_from
,
convert_to
in
zip
(
conversion_chain
[:
-
1
],
conversion_chain
[
1
:]):
for
convert_from
,
convert_to
in
zip
(
conversion_chain
[:
-
1
],
conversion_chain
[
1
:]):
load_options
,
_
,
_
=
convert_from
load_options
,
_
,
_
=
convert_from
_
,
save_options
,
fileext
=
convert_to
_
,
save_options
,
fileext
=
convert_to
if
fileext
:
if
fileext
:
destination
=
str
(
tmpdir
/
f
"
file.
{
fileext
}
"
)
destination
=
path_format
(
tmpdir
/
f
"
file.
{
fileext
}
"
)
else
:
else
:
destination
=
None
destination
=
None
result
=
convert_graph
(
result
=
convert_graph
(
...
...
This diff is collapsed.
Click to expand it.