Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Casper Weiss Bang
committed
Apr 16, 2021
1 parent
773ffdf
commit ed0e8da
Showing
19 changed files
with
260 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from codoc.domain.model import Graph | ||
from .high_order_filter import filter_nodes_by_lambda | ||
|
||
from .helpers import get_edges_where_both_ends_are_in_nodes | ||
|
||
|
||
# TODO this fails if you do an OR on two graphs. | ||
# TODO this fails if you do an OR on two graphs where node is in both. | ||
def exclude_external(graph: Graph) -> Graph: | ||
nodes = {node for node in graph.nodes if not node.external} | ||
edges = get_edges_where_both_ends_are_in_nodes(graph.edges, nodes) | ||
|
||
return Graph(nodes=nodes, edges=edges) | ||
return filter_nodes_by_lambda(lambda node: not node.external)(graph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python3 | ||
from typing import Callable | ||
|
||
from codoc.domain.model import Graph, Node | ||
|
||
from .types import FilterType | ||
|
||
|
||
def filter_nodes_by_lambda(filter_function: Callable[[Node], bool]) -> FilterType: | ||
def internal_filter(graph: Graph) -> Graph: | ||
nodes = {node for node in graph.nodes if filter_function(node)} | ||
return Graph(nodes=nodes, edges=graph.edges) | ||
|
||
return internal_filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
import re | ||
|
||
from .high_order_filter import filter_nodes_by_lambda | ||
from .types import FilterType | ||
|
||
|
||
def filter_by_regex(pattern: str, flags=0) -> FilterType: | ||
""" | ||
This allows you to filter nodes based on whether they fulfill | ||
some regex query. This is ideal if you, for instance, want to remove all | ||
test related things. | ||
The regex is done solely on the `name` attribute. | ||
The following example removes all instances of "test". | ||
Example: | ||
graph = filters.filter_by_regex("test", flags=re.IGNORECASE)(graph) | ||
To understand how to use regex, please consult the python documentation: | ||
https://docs.python.org/3/library/re.html | ||
""" | ||
|
||
pattern = re.compile(pattern, flags=flags) | ||
return filter_nodes_by_lambda(lambda node: pattern.search(node.name) is not None) | ||
|
||
|
||
def exclude_by_regex(pattern: str, flags=0) -> FilterType: | ||
""" | ||
This allows you to filter nodes based on whether they fulfill | ||
some regex query. This is ideal if you, for instance, want to remove all | ||
test related things. | ||
The regex is done solely on the `name` attribute. | ||
The following example removes all instances of "test". | ||
Example: | ||
graph = filters.filter_by_regex("test", flags=re.IGNORECASE)(graph) | ||
To understand how to use regex, please consult the python documentation: | ||
https://docs.python.org/3/library/re.html | ||
""" | ||
|
||
pattern = re.compile(pattern, flags=flags) | ||
return filter_nodes_by_lambda(lambda node: pattern.search(node.name) is None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.