Skip to content

Commit

Permalink
Set max line length to 100 characters (Qiskit#490)
Browse files Browse the repository at this point in the history
Previously we had been setting rustfmt and black to use an 80 character
line length. This was primarily because my personal dev workflow is
setup around 80 character-wide windows. However, as the project has a
growing number of contributors my personal archaic taste in dev workflow
should not be subjected upon everyone. This commit bumps the max line
length in rustfmt and black up to 100 which is a more common default
that will work better in most editors and not needlessly wrap lines
everywhere. Most of this diff is just the auto-formatting adjustments
now that there are an additional 20 characters available for them to
use.

Additionally, with the recent release of black 22.0 the project has
moved out of beta and adopted a stability policy. [1] Moving forward for
a given major version there will be no formatting changes in black, so
this commit bumps the black version and loosens the constraint to use
any of the 22.x.y which means we'll get the latest bug fixes for running
in CI but have a stable set of formatting rules applied.

[1] https://black.readthedocs.io/en/latest/the_black_code_style/index.html#stability-policy
  • Loading branch information
mtreinish authored Feb 3, 2022
1 parent eecaf91 commit a6cc894
Show file tree
Hide file tree
Showing 115 changed files with 1,119 additions and 3,316 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.8
- run: pip install -U flake8 black==21.5b0
- run: pip install -U flake8 black~=22.0
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ requires = ["setuptools", "wheel", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 80
target-version = ['py36', 'py37', 'py38', 'py39']
line-length = 100
target-version = ['py37', 'py38', 'py39', 'py310']
125 changes: 31 additions & 94 deletions retworkx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ class PyDAG(PyDiGraph):


@functools.singledispatch
def distance_matrix(
graph, parallel_threshold=300, as_undirected=False, null_value=0.0
):
def distance_matrix(graph, parallel_threshold=300, as_undirected=False, null_value=0.0):
"""Get the distance matrix for a graph
This differs from functions like :func:`~retworkx.floyd_warshall_numpy` in
Expand Down Expand Up @@ -161,9 +159,7 @@ def distance_matrix(


@distance_matrix.register(PyDiGraph)
def _digraph_distance_matrix(
graph, parallel_threshold=300, as_undirected=False, null_value=0.0
):
def _digraph_distance_matrix(graph, parallel_threshold=300, as_undirected=False, null_value=0.0):
return digraph_distance_matrix(
graph,
parallel_threshold=parallel_threshold,
Expand All @@ -180,9 +176,7 @@ def _graph_distance_matrix(graph, parallel_threshold=300, null_value=0.0):


@functools.singledispatch
def unweighted_average_shortest_path_length(
graph, parallel_threshold=300, disconnected=False
):
def unweighted_average_shortest_path_length(graph, parallel_threshold=300, disconnected=False):
r"""Return the average shortest path length with unweighted edges.
The average shortest path length is calculated as
Expand Down Expand Up @@ -236,9 +230,7 @@ def _digraph_unweighted_average_shortest_path_length(


@unweighted_average_shortest_path_length.register(PyGraph)
def _graph_unweighted_shortest_path_length(
graph, parallel_threshold=300, disconnected=False
):
def _graph_unweighted_shortest_path_length(graph, parallel_threshold=300, disconnected=False):
return graph_unweighted_average_shortest_path_length(
graph, parallel_threshold=parallel_threshold, disconnected=disconnected
)
Expand Down Expand Up @@ -281,9 +273,7 @@ def adjacency_matrix(graph, weight_fn=None, default_weight=1.0, null_value=0.0):


@adjacency_matrix.register(PyDiGraph)
def _digraph_adjacency_matrix(
graph, weight_fn=None, default_weight=1.0, null_value=0.0
):
def _digraph_adjacency_matrix(graph, weight_fn=None, default_weight=1.0, null_value=0.0):
return digraph_adjacency_matrix(
graph,
weight_fn=weight_fn,
Expand All @@ -293,9 +283,7 @@ def _digraph_adjacency_matrix(


@adjacency_matrix.register(PyGraph)
def _graph_adjacency_matrix(
graph, weight_fn=None, default_weight=1.0, null_value=0.0
):
def _graph_adjacency_matrix(graph, weight_fn=None, default_weight=1.0, null_value=0.0):
return graph_adjacency_matrix(
graph,
weight_fn=weight_fn,
Expand Down Expand Up @@ -329,16 +317,12 @@ def all_simple_paths(graph, from_, to, min_depth=None, cutoff=None):

@all_simple_paths.register(PyDiGraph)
def _digraph_all_simple_paths(graph, from_, to, min_depth=None, cutoff=None):
return digraph_all_simple_paths(
graph, from_, to, min_depth=min_depth, cutoff=cutoff
)
return digraph_all_simple_paths(graph, from_, to, min_depth=min_depth, cutoff=cutoff)


@all_simple_paths.register(PyGraph)
def _graph_all_simple_paths(graph, from_, to, min_depth=None, cutoff=None):
return graph_all_simple_paths(
graph, from_, to, min_depth=min_depth, cutoff=cutoff
)
return graph_all_simple_paths(graph, from_, to, min_depth=min_depth, cutoff=cutoff)


@functools.singledispatch
Expand Down Expand Up @@ -489,9 +473,7 @@ def _digraph_floyd_warshall_numpy(


@floyd_warshall_numpy.register(PyGraph)
def _graph_floyd_warshall_numpy(
graph, weight_fn=None, default_weight=1.0, parallel_threshold=300
):
def _graph_floyd_warshall_numpy(graph, weight_fn=None, default_weight=1.0, parallel_threshold=300):
return graph_floyd_warshall_numpy(
graph,
weight_fn=weight_fn,
Expand Down Expand Up @@ -528,21 +510,13 @@ def astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn):


@astar_shortest_path.register(PyDiGraph)
def _digraph_astar_shortest_path(
graph, node, goal_fn, edge_cost_fn, estimate_cost_fn
):
return digraph_astar_shortest_path(
graph, node, goal_fn, edge_cost_fn, estimate_cost_fn
)
def _digraph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn):
return digraph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn)


@astar_shortest_path.register(PyGraph)
def _graph_astar_shortest_path(
graph, node, goal_fn, edge_cost_fn, estimate_cost_fn
):
return graph_astar_shortest_path(
graph, node, goal_fn, edge_cost_fn, estimate_cost_fn
)
def _graph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn):
return graph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn)


@functools.singledispatch
Expand Down Expand Up @@ -599,9 +573,7 @@ def _digraph_dijkstra_shortest_path(


@dijkstra_shortest_paths.register(PyGraph)
def _graph_dijkstra_shortest_path(
graph, source, target=None, weight_fn=None, default_weight=1.0
):
def _graph_dijkstra_shortest_path(graph, source, target=None, weight_fn=None, default_weight=1.0):
return graph_dijkstra_shortest_paths(
graph,
source,
Expand Down Expand Up @@ -723,19 +695,13 @@ def dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=None):


@dijkstra_shortest_path_lengths.register(PyDiGraph)
def _digraph_dijkstra_shortest_path_lengths(
graph, node, edge_cost_fn, goal=None
):
return digraph_dijkstra_shortest_path_lengths(
graph, node, edge_cost_fn, goal=goal
)
def _digraph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=None):
return digraph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=goal)


@dijkstra_shortest_path_lengths.register(PyGraph)
def _graph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=None):
return graph_dijkstra_shortest_path_lengths(
graph, node, edge_cost_fn, goal=goal
)
return graph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=goal)


@functools.singledispatch
Expand Down Expand Up @@ -765,9 +731,7 @@ def k_shortest_path_lengths(graph, start, k, edge_cost, goal=None):

@k_shortest_path_lengths.register(PyDiGraph)
def _digraph_k_shortest_path_lengths(graph, start, k, edge_cost, goal=None):
return digraph_k_shortest_path_lengths(
graph, start, k, edge_cost, goal=goal
)
return digraph_k_shortest_path_lengths(graph, start, k, edge_cost, goal=goal)


@k_shortest_path_lengths.register(PyGraph)
Expand Down Expand Up @@ -894,9 +858,7 @@ def _digraph_is_isomorphic(
id_order=True,
call_limit=None,
):
return digraph_is_isomorphic(
first, second, node_matcher, edge_matcher, id_order, call_limit
)
return digraph_is_isomorphic(first, second, node_matcher, edge_matcher, id_order, call_limit)


@is_isomorphic.register(PyGraph)
Expand All @@ -908,9 +870,7 @@ def _graph_is_isomorphic(
id_order=True,
call_limit=None,
):
return graph_is_isomorphic(
first, second, node_matcher, edge_matcher, id_order, call_limit
)
return graph_is_isomorphic(first, second, node_matcher, edge_matcher, id_order, call_limit)


@functools.singledispatch
Expand Down Expand Up @@ -1330,10 +1290,7 @@ def networkx_converter(graph, keep_attributes: bool = False):
nodes = list(graph.nodes)
node_indices = dict(zip(nodes, new_graph.add_nodes_from(nodes)))
new_graph.add_edges_from(
[
(node_indices[x[0]], node_indices[x[1]], x[2])
for x in graph.edges(data=True)
]
[(node_indices[x[0]], node_indices[x[1]], x[2]) for x in graph.edges(data=True)]
)

if keep_attributes:
Expand Down Expand Up @@ -1461,22 +1418,16 @@ def shell_layout(graph, nlist=None, rotate=None, scale=1, center=None):

@shell_layout.register(PyDiGraph)
def _digraph_shell_layout(graph, nlist=None, rotate=None, scale=1, center=None):
return digraph_shell_layout(
graph, nlist=nlist, rotate=rotate, scale=scale, center=center
)
return digraph_shell_layout(graph, nlist=nlist, rotate=rotate, scale=scale, center=center)


@shell_layout.register(PyGraph)
def _graph_shell_layout(graph, nlist=None, rotate=None, scale=1, center=None):
return graph_shell_layout(
graph, nlist=nlist, rotate=rotate, scale=scale, center=center
)
return graph_shell_layout(graph, nlist=nlist, rotate=rotate, scale=scale, center=center)


@functools.singledispatch
def spiral_layout(
graph, scale=1, center=None, resolution=0.35, equidistant=False
):
def spiral_layout(graph, scale=1, center=None, resolution=0.35, equidistant=False):
"""
Generate a spiral layout of the graph
Expand All @@ -1497,9 +1448,7 @@ def spiral_layout(


@spiral_layout.register(PyDiGraph)
def _digraph_spiral_layout(
graph, scale=1, center=None, resolution=0.35, equidistant=False
):
def _digraph_spiral_layout(graph, scale=1, center=None, resolution=0.35, equidistant=False):
return digraph_spiral_layout(
graph,
scale=scale,
Expand All @@ -1510,9 +1459,7 @@ def _digraph_spiral_layout(


@spiral_layout.register(PyGraph)
def _graph_spiral_layout(
graph, scale=1, center=None, resolution=0.35, equidistant=False
):
def _graph_spiral_layout(graph, scale=1, center=None, resolution=0.35, equidistant=False):
return graph_spiral_layout(
graph,
scale=scale,
Expand Down Expand Up @@ -1548,9 +1495,7 @@ def _graph_num_shortest_paths_unweighted(graph, source):


@functools.singledispatch
def betweenness_centrality(
graph, normalized=True, endpoints=False, parallel_threshold=50
):
def betweenness_centrality(graph, normalized=True, endpoints=False, parallel_threshold=50):
r"""Returns the betweenness centrality of each node in the graph.
Betweenness centrality of a node :math:`v` is the sum of the
Expand Down Expand Up @@ -1593,9 +1538,7 @@ def betweenness_centrality(


@betweenness_centrality.register(PyDiGraph)
def _digraph_betweenness_centrality(
graph, normalized=True, endpoints=False, parallel_threshold=50
):
def _digraph_betweenness_centrality(graph, normalized=True, endpoints=False, parallel_threshold=50):
return digraph_betweenness_centrality(
graph,
normalized=normalized,
Expand All @@ -1605,9 +1548,7 @@ def _digraph_betweenness_centrality(


@betweenness_centrality.register(PyGraph)
def _graph_betweenness_centrality(
graph, normalized=True, endpoints=False, parallel_threshold=50
):
def _graph_betweenness_centrality(graph, normalized=True, endpoints=False, parallel_threshold=50):
return graph_betweenness_centrality(
graph,
normalized=normalized,
Expand Down Expand Up @@ -1768,9 +1709,7 @@ def _digraph_union(
merge_nodes=False,
merge_edges=False,
):
return digraph_union(
first, second, merge_nodes=merge_nodes, merge_edges=merge_edges
)
return digraph_union(first, second, merge_nodes=merge_nodes, merge_edges=merge_edges)


@union.register(PyGraph)
Expand All @@ -1780,9 +1719,7 @@ def _graph_union(
merge_nodes=False,
merge_edges=False,
):
return graph_union(
first, second, merge_nodes=merge_nodes, merge_edges=merge_edges
)
return graph_union(first, second, merge_nodes=merge_nodes, merge_edges=merge_edges)


@functools.singledispatch
Expand Down
Loading

0 comments on commit a6cc894

Please sign in to comment.