Skip to content

Commit 437146f

Browse files
committed
Get ready for release 2.3.0
Fix lint errors
1 parent f1fc830 commit 437146f

File tree

13 files changed

+163
-43
lines changed

13 files changed

+163
-43
lines changed

.editorconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# THis is an EditorConfig file
2+
# https://EditorConfig.org
3+
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
insert_final_newline = true
9+
charset = utf-8
10+
indent_style = tab
11+
indent_size = 4
12+
insert_final_newline = true
13+
14+
[*.yml]
15+
indent_style = space
16+
indent_size = 2
17+
end_of_line = lf
18+
insert_final_newline = true
19+
20+
[*.py]
21+
indent_style = space
22+
indent_size = 4
23+
end_of_line = lf
24+
insert_final_newline = true
25+
26+
# Tab indentation (no size specified)
27+
[Makefile]
28+
indent_style = tab

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.0.0
4+
hooks:
5+
- id: debug-statements
6+
- id: end-of-file-fixer
7+
- repo: https://github.com/psf/black
8+
rev: 20.8b1
9+
hooks:
10+
- id: black
11+
language_version: python3
12+
exclude: 'mathicsscript/version.py'

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2.3.0
2+
-----
3+
4+
Small API changes to track Mathics 3.0.0.
5+
6+
Blacken everything
7+
8+
9+
110
2.2.0
211
-----
312

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Example Session
88
::
99

1010
$ mathicsscript
11-
Mathics 1.1.1
11+
Mathics 3.0.1
1212
on CPython 3.6.12 (default, Oct 24 2020, 10:34:18)
13-
using SymPy 1.8.dev, mpmath 1.1.0, cython 0.29.21
13+
using SymPy 1.8, mpmath 1.2.1, cython 0.29.22
1414

15-
Copyright (C) 2011-2020 The Mathics Team.
15+
Copyright (C) 2011-2021 The Mathics Team.
1616
This program comes with ABSOLUTELY NO WARRANTY.
1717
This is free software, and you are welcome to redistribute it
1818
under certain conditions.

pymathics/graph/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
"""Pymathics Graph - Working with Graphs (Vertices and Edgies)
1+
"""Pymathics Graph - Working with Graphs (Vertices and Edges)
22
33
This module provides functions and variables for workting with
44
graphs.
5-
"""
65
6+
Example:
7+
In[1]:= LoadModule["pymathics.graph"]
8+
Out[1]= pymathics.graph
9+
In[2]:= BinomialTree[3]
10+
In[3]:= BinomialTree[6]
11+
In[4]:= CompleteKaryTree[3, VertexLabels->True]
12+
"""
713

814
from pymathics.graph.version import __version__
9-
from pymathics.graph.__main__ import *
10-
from pymathics.graph.tree import *
11-
from pymathics.graph.generators import *
12-
from pymathics.graph.algorithms import *
15+
from pymathics.graph.__main__ import * # noqa
16+
from pymathics.graph.tree import * # qoqa
17+
from pymathics.graph.generators import * # noqa
18+
from pymathics.graph.algorithms import * # noqa
1319

1420
pymathics_version_data = {
1521
"author": "The Mathics Team",

pymathics/graph/__main__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
# uses networkx
1111

1212
from mathics.builtin.base import Builtin, AtomBuiltin
13-
from mathics.builtin.graphics import GraphicsBox
13+
from mathics.builtin.box.graphics import GraphicsBox
1414
from mathics.core.expression import (
1515
Atom,
1616
Expression,
1717
Integer,
1818
Real,
19-
String,
2019
Symbol,
2120
)
2221
from mathics.builtin.patterns import Matcher
@@ -730,7 +729,7 @@ def full_new_edge_properties(new_edge_style):
730729
attr_dict = attr_dict or empty_dict
731730
G.add_edge(u, v, **attr_dict)
732731

733-
edge_collection = _EdgeCollection(
732+
_EdgeCollection(
734733
edges,
735734
edge_properties,
736735
n_directed=len(directed_edges),
@@ -1804,7 +1803,7 @@ def apply_s_t(self, graph, s, t, expression, evaluation, options):
18041803
def _convert_networkx_graph(G, options):
18051804
mapping = dict((v, Integer(i)) for i, v in enumerate(G.nodes))
18061805
G = nx.relabel_nodes(G, mapping)
1807-
edges = [Expression("System`UndirectedEdge", u, v) for u, v in G.edges]
1806+
[Expression("System`UndirectedEdge", u, v) for u, v in G.edges]
18081807
return Graph(
18091808
G,
18101809
**options,

pymathics/graph/algorithms.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# SymbolFalse = Symbol("System`False")
2323
# SymbolTrue = Symbol("System`True")
2424

25+
2526
class ConnectedComponents(_NetworkXBuiltin):
2627
"""
2728
>> g = Graph[{1 -> 2, 2 -> 3, 3 <-> 4}]; ConnectedComponents[g]
@@ -38,10 +39,12 @@ def apply(self, graph, expression, evaluation, options):
3839
"ConnectedComponents[graph_, OptionsPattern[%(name)s]]"
3940
graph = self._build_graph(graph, evaluation, options, expression)
4041
if graph:
41-
connect_fn = nx.strongly_connected_components if graph.G.is_directed() else nx.connected_components
42-
components = [
43-
Expression("List", *c) for c in connect_fn(graph.G)
44-
]
42+
connect_fn = (
43+
nx.strongly_connected_components
44+
if graph.G.is_directed()
45+
else nx.connected_components
46+
)
47+
components = [Expression("List", *c) for c in connect_fn(graph.G)]
4548
return Expression("List", *components)
4649

4750

@@ -63,6 +66,7 @@ def apply(self, graph, expression, evaluation, options):
6366
# # int_path = map(Integer, path)
6467
# return Expression("List", *path)
6568

69+
6670
class GraphDistance(_NetworkXBuiltin):
6771
"""
6872
<dl>
@@ -110,9 +114,7 @@ def apply_s(self, graph, s, expression, evaluation, options):
110114
weight = graph.update_weights(evaluation)
111115
d = nx.shortest_path_length(graph.G, source=s, weight=weight)
112116
inf = Expression("DirectedInfinity", 1)
113-
return Expression(
114-
"List", *[d.get(v, inf) for v in graph.vertices]
115-
)
117+
return Expression("List", *[d.get(v, inf) for v in graph.vertices])
116118

117119
def apply_s_t(self, graph, s, t, expression, evaluation, options):
118120
"%(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
@@ -133,6 +135,7 @@ def apply_s_t(self, graph, s, t, expression, evaluation, options):
133135
except nx.exception.NetworkXNoPath:
134136
return Expression("DirectedInfinity", 1)
135137

138+
136139
class FindSpanningTree(_NetworkXBuiltin):
137140
"""
138141
<dl>
@@ -144,14 +147,18 @@ class FindSpanningTree(_NetworkXBuiltin):
144147
"""
145148

146149
options = DEFAULT_GRAPH_OPTIONS
150+
147151
def apply(self, graph, expression, evaluation, options):
148152
"%(name)s[graph_, OptionsPattern[%(name)s]]"
149153
graph = self._build_graph(graph, evaluation, options, expression)
150154
if graph:
151155
weight = graph.update_weights(evaluation)
152156
edge_type = "DirectedEdge" if graph.G.is_directed() else "UndirectedEdge"
153157
# FIXME: put in edge to Graph conversion function?
154-
edges = [Expression("UndirectedEdge", u, v) for u, v in nx.minimum_spanning_edges(graph.G, data=False)]
158+
edges = [
159+
Expression("UndirectedEdge", u, v)
160+
for u, v in nx.minimum_spanning_edges(graph.G, data=False)
161+
]
155162
g = _create_graph(edges, [None] * len(edges), options)
156163
if not hasattr(g.G, "graph_layout"):
157164
if hasattr(graph.G, "graph_layout"):
@@ -160,6 +167,7 @@ def apply(self, graph, expression, evaluation, options):
160167
g.G.graph_layout = "tree"
161168
return g
162169

170+
163171
class PlanarGraphQ(_NetworkXBuiltin):
164172
"""
165173
<dl>
@@ -174,6 +182,7 @@ class PlanarGraphQ(_NetworkXBuiltin):
174182
"""
175183

176184
options = DEFAULT_GRAPH_OPTIONS
185+
177186
def apply(self, graph, expression, evaluation, options):
178187
"%(name)s[graph_, OptionsPattern[%(name)s]]"
179188
graph = self._build_graph(graph, evaluation, options, expression)
@@ -182,6 +191,7 @@ def apply(self, graph, expression, evaluation, options):
182191
is_planar, _ = nx.check_planarity(graph.G)
183192
return Symbol("System`True") if is_planar else Symbol("System`False")
184193

194+
185195
class WeaklyConnectedComponents(_NetworkXBuiltin):
186196
"""
187197
>> g = Graph[{1 -> 2, 2 -> 3, 3 <-> 4}]; WeaklyConnectedComponents[g]

pymathics/graph/generators.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
"""
77

88
from mathics.builtin.numbers.randomnumbers import RandomEnv
9-
from mathics.core.expression import String
109

1110
from pymathics.graph.__main__ import (
1211
Graph,
13-
WL_MARKER_TO_NETWORKX,
1412
_NetworkXBuiltin,
1513
_convert_networkx_graph,
1614
_graph_from_list,
@@ -32,6 +30,7 @@ def graph_helper(
3230
options: dict,
3331
can_digraph: bool,
3432
graph_layout: str,
33+
evaluation,
3534
root: Optional[int] = None,
3635
*args,
3736
**kwargs
@@ -94,7 +93,7 @@ def apply(self, r, h, expression, evaluation, options):
9493
return None
9594

9695
args = (py_r, py_h)
97-
g = graph_helper(nx.balanced_tree, options, True, "tree", 0, *args)
96+
g = graph_helper(nx.balanced_tree, options, True, "tree", evaluation, 0, *args)
9897
if not g:
9998
return None
10099
g.G.r = r
@@ -133,7 +132,7 @@ def apply(self, m1, m2, expression, evaluation, options):
133132
return
134133

135134
args = (py_m1, py_m2)
136-
g = graph_helper(nx.barbell_graph, options, False, "spring", None, *args)
135+
g = graph_helper(nx.barbell_graph, options, False, "spring", evaluation, None, *args)
137136
if not g:
138137
return None
139138

@@ -205,7 +204,7 @@ def apply(self, n, expression, evaluation, options):
205204
return
206205

207206
args = (py_n,)
208-
g = graph_helper(binomial_tree, options, True, "tree", 0, *args)
207+
g = graph_helper(binomial_tree, options, True, "tree", evaluation, 0, *args)
209208
if not g:
210209
return None
211210
g.G.n = n
@@ -220,7 +219,7 @@ def complete_graph_apply(self, n, expression, evaluation, options):
220219
return
221220

222221
args = (py_n,)
223-
g = graph_helper(nx.complete_graph, options, False, "circular", None, *args)
222+
g = graph_helper(nx.complete_graph, options, False, "circular", evaluation, None, *args)
224223
if not g:
225224
return None
226225

@@ -333,7 +332,7 @@ def f_r_t_apply(self, r, n, expression, evaluation, options):
333332
return
334333

335334
args = (py_r, py_n)
336-
g = graph_helper(nx.full_rary_tree, options, True, "tree", 0, *args)
335+
g = graph_helper(nx.full_rary_tree, options, True, "tree", evaluation, 0, *args)
337336
if not g:
338337
return None
339338

@@ -395,7 +394,7 @@ def apply(self, n, expression, evaluation, options):
395394
return
396395

397396
args = (py_n,)
398-
g = graph_helper(nx.graph_atlas, options, False, "spring", None, *args)
397+
g = graph_helper(nx.graph_atlas, options, False, "spring", evaluation, None, *args)
399398
if not g:
400399
return None
401400
g.n = n
@@ -417,7 +416,7 @@ def hkn_harary_apply(self, k, n, expression, evaluation, options):
417416
from pymathics.graph.harary import hkn_harary_graph
418417

419418
args = (py_k, py_n)
420-
g = graph_helper(hkn_harary_graph, options, False, "circular", None, *args)
419+
g = graph_helper(hkn_harary_graph, options, False, "circular", evaluation, None, *args)
421420
if not g:
422421
return None
423422
g.k = py_k
@@ -490,7 +489,7 @@ def apply(self, n, m, expression, evaluation, options):
490489
from pymathics.graph.harary import hnm_harary_graph
491490

492491
args = (py_n, py_m)
493-
g = graph_helper(hmn_harary_graph, options, False, "circular", None, *args)
492+
g = graph_helper(hnm_harary_graph, options, False, "circular", evaluation, None, *args)
494493
if not g:
495494
return None
496495
g.n = py_n
@@ -557,12 +556,13 @@ def apply(self, n, expression, evaluation, options):
557556
return
558557

559558
args = (py_n,)
560-
g = graph_helper(nx.ladder_graph, options, False, "spring", 0, *args)
559+
g = graph_helper(nx.ladder_graph, options, False, "spring", evaluation, 0, *args)
561560
if not g:
562561
return None
563562
g.G.n = n
564563
return g
565564

565+
566566
class PathGraph(_NetworkXBuiltin):
567567
"""
568568
<dl>
@@ -582,7 +582,9 @@ def edges():
582582
yield Expression("UndirectedEdge", u, v)
583583

584584
g = _graph_from_list(edges(), options)
585-
g.G.graph_layout = options["System`GraphLayout"].get_string_value() or "spiral_equidistant"
585+
g.G.graph_layout = (
586+
options["System`GraphLayout"].get_string_value() or "spiral_equidistant"
587+
)
586588
return g
587589

588590

@@ -645,7 +647,7 @@ def apply(self, n, expression, evaluation, options):
645647
return
646648

647649
args = (py_n,)
648-
g = graph_helper(nx.random_tree, options, False, "tree", 0, *args)
650+
g = graph_helper(nx.random_tree, options, False, "tree", evaluation, 0, *args)
649651
if not g:
650652
return None
651653
g.G.n = n
@@ -676,12 +678,13 @@ def apply(self, n, expression, evaluation, options):
676678
return
677679

678680
args = (py_n,)
679-
g = graph_helper(nx.star_graph, options, False, "spring", 0, *args)
681+
g = graph_helper(nx.star_graph, options, False, "spring", evaluation, 0, *args)
680682
if not g:
681683
return None
682684
g.G.n = n
683685
return g
684686

687+
685688
WL_TO_NETWORKX_FN = {
686689
"DodecahedralGraph": (nx.dodecahedral_graph, None),
687690
"DiamondGraph": (nx.diamond_graph, "spring"),
@@ -690,6 +693,7 @@ def apply(self, n, expression, evaluation, options):
690693
"PetersenGraph": (nx.petersen_graph, None),
691694
}
692695

696+
693697
class GraphData(_NetworkXBuiltin):
694698
"""
695699
<dl>
@@ -699,6 +703,7 @@ class GraphData(_NetworkXBuiltin):
699703
700704
>> GraphData["PappusGraph"]
701705
"""
706+
702707
def apply(self, name, expression, evaluation, options):
703708
"%(name)s[name_String, OptionsPattern[%(name)s]]"
704709
py_name = name.get_string_value()
@@ -710,11 +715,12 @@ def apply(self, name, expression, evaluation, options):
710715
# These graphs require parameters
711716
return
712717
import inspect
718+
713719
fn = dict(inspect.getmembers(nx, inspect.isfunction)).get(py_name, None)
714720
# parameters = inspect.signature(nx.diamond_graph).parameters.values()
715721
# if len([p for p in list(parameters) if p.kind in [inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD]]) != 0:
716722
# return
717723
if fn:
718-
g = graph_helper(fn, options, False, layout)
724+
g = graph_helper(fn, options, False, evaluation, layout)
719725
g.G.name = py_name
720726
return g

0 commit comments

Comments
 (0)