Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
GNA Parser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
gna
GNA Parser
Commits
ef65ce39
Commit
ef65ce39
authored
3 years ago
by
Tsegelnik Nikita
Browse files
Options
Downloads
Patches
Plain Diff
Working on the new implementation of the graphs -- GDGraph
parent
d196fd0c
No related branches found
Branches containing commit
No related tags found
1 merge request
!19
New version
Pipeline
#16659
passed
3 years ago
Stage: tests
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/gdgraph.py
+89
-0
89 additions, 0 deletions
source/gdgraph.py
with
89 additions
and
0 deletions
source/gdgraph.py
0 → 100755
+
89
−
0
View file @
ef65ce39
#!/usr/bin/env python3
from
__future__
import
annotations
from
typing
import
Any
,
List
,
Optional
,
Sequence
,
Tuple
import
warnings
if
__package__
is
None
or
__package__
==
""
:
# uses current directory visibility
# fixed import error when building documentation
from
gdata
import
GData
else
:
# uses current package visibility
from
.gdata
import
GData
class
GDNode
:
def
__init__
(
self
,
name
:
str
,
data
:
Any
,
next
:
Any
=
None
)
->
None
:
self
.
name
=
name
self
.
data
=
data
self
.
next
=
next
@classmethod
def
from_gdata
(
cls
,
data
:
GData
,
next
:
Optional
[
GData
]
=
None
)
->
GDNode
:
return
cls
(
data
.
uname
(),
data
,
next
)
class
GDGraph
:
"""
Simple directed graph, containing list of all nodes,
references to the top node (only one) and a bottom node (random)
Implemented to the advanced Pattern Matching
"""
def
__init__
(
self
,
nodes
:
Sequence
[
Any
]
=
None
,
debug
:
bool
=
False
,
strict
:
bool
=
False
,
)
->
None
:
self
.
debug
=
debug
self
.
strict
=
strict
self
.
names
=
[]
self
.
nodes
=
[]
if
isinstance
(
nodes
,
(
List
,
Tuple
)):
self
.
add_nodes
(
nodes
)
else
:
raise
ValueError
(
"
The nodes must be `List` or `Tuple`,
"
f
"
but given
'
{
type
(
nodes
)
}
'
!
"
)
def
add_nodes
(
self
,
nodes
:
Sequence
[
Any
])
->
None
:
for
node
in
nodes
:
if
isinstance
(
node
,
GData
):
self
.
add_node
(
node
,
node
.
uname
())
elif
isinstance
(
node
,
GDNode
):
self
.
add_node
(
node
,
node
.
name
)
elif
isinstance
(
node
,
(
List
,
Tuple
)):
self
.
add_nodes
(
node
)
else
:
if
self
.
strict
:
raise
ValueError
(
"
In the strict mode the allowed types are `GData`
"
f
"
and `GDNode`, but given
'
{
type
(
node
)
}
'
!
"
)
elif
self
.
debug
:
warnings
.
warn
(
"
The name of the node cannot be determined,
"
"
so the string representation of the node is used
"
"
as the name.
"
,
RuntimeWarning
,
)
self
.
add_node
(
node
,
node
)
def
add_node
(
self
,
data
:
Any
,
name
:
Optional
[
str
]
=
None
,
next
:
Any
=
None
)
->
GDNode
:
"""
Adding node to the graph
"""
node
=
(
GDNode
.
from_gdata
(
data
,
next
)
if
isinstance
(
data
,
GData
)
else
GDNode
(
name
or
str
(
data
),
data
,
next
)
)
self
.
nodes
.
append
(
node
)
return
node
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