Skip to content

Commit

Permalink
Merge pull request f4pga#949 from litghost/no_progress_on_non_interac…
Browse files Browse the repository at this point in the history
…tive

Lower poll interval when redirecting to non-interactive terminal (e.g. CI).
  • Loading branch information
litghost committed Aug 20, 2019
2 parents d72470a + c623b5e commit a3c6778
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 35 deletions.
22 changes: 22 additions & 0 deletions utils/lib/progressbar_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import progressbar as bar
import sys


def disable_widgets_if_not_interactive(kwargs):
if not (sys.stdout.isatty() and sys.stderr.isatty()):
# Disable all widgets if non-interactive
print('No progressbar disabled because non-interactive terminal.')
kwargs['widgets'] = []


def progressbar(*args, **kwargs):
disable_widgets_if_not_interactive(kwargs)
b = bar.progressbar(*args, **kwargs)

return b


class ProgressBar(bar.ProgressBar):
def __init__(self, *args, **kwargs):
disable_widgets_if_not_interactive(kwargs)
super().__init__(*args, **kwargs)
6 changes: 3 additions & 3 deletions utils/lib/rr_graph/graph2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from enum import Enum
from .tracks import Track
from lib.rr_graph import channel2
import progressbar
from lib import progressbar_utils


class SwitchType(Enum):
Expand Down Expand Up @@ -539,7 +539,7 @@ def create_channels(self, pad_segment, pool=None):
process_track, (y_tracks[x], )
)

for y in progressbar.progressbar(range(max(x_tracks) + 1)):
for y in progressbar_utils.progressbar(range(max(x_tracks) + 1)):
if y in x_tracks:
if pool is None:
x_channel_models[y] = process_track(x_tracks[y])
Expand All @@ -553,7 +553,7 @@ def create_channels(self, pad_segment, pool=None):
else:
x_list.append(0)

for x in progressbar.progressbar(range(max(y_tracks) + 1)):
for x in progressbar_utils.progressbar(range(max(y_tracks) + 1)):
if x in y_tracks:
if pool is None:
y_channel_models[x] = process_track(y_tracks[x])
Expand Down
17 changes: 10 additions & 7 deletions xc7/utils/prjxray_assign_tile_pin_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
node_to_site_pins, get_pin_name_of_wire
)
from prjxray_constant_site_pins import yield_ties_to_wire
import progressbar
from lib import progressbar_utils
import datetime

from prjxray_db_cache import DatabaseCache
Expand All @@ -42,7 +42,7 @@ def handle_direction_connections(conn, direct_connections, edge_assignments):
# It is expected that all edges_with_mux will lies in a line (e.g. X only or
# Y only).
c = conn.cursor()
for src_wire_pkey, dest_wire_pkey, pip_in_tile_pkey, switch_pkey in progressbar.progressbar(
for src_wire_pkey, dest_wire_pkey, pip_in_tile_pkey, switch_pkey in progressbar_utils.progressbar(
c.execute("""
SELECT src_wire_pkey, dest_wire_pkey, pip_in_tile_pkey, switch_pkey FROM edge_with_mux;"""
)):
Expand Down Expand Up @@ -159,7 +159,8 @@ def handle_edges_to_channels(
1: vcc_track_pkey,
}

for node_pkey, classification in progressbar.progressbar(c.execute("""
for node_pkey, classification in progressbar_utils.progressbar(c.execute(
"""
SELECT pkey, classification FROM node WHERE classification != ?;
""", (NodeClassification.CHANNEL.value, ))):
reason = NodeClassification(classification)
Expand Down Expand Up @@ -389,7 +390,8 @@ def main():
wires_not_in_channels = {}
c = conn.cursor()
print('{} Processing non-channel nodes.'.format(now()))
for node_pkey, classification in progressbar.progressbar(c.execute("""
for node_pkey, classification in progressbar_utils.progressbar(
c.execute("""
SELECT pkey, classification FROM node WHERE classification != ?;
""", (NodeClassification.CHANNEL.value, ))):
reason = NodeClassification(classification)
Expand Down Expand Up @@ -422,7 +424,8 @@ def main():
# Generate track models and verify that wires are either in a channel
# or not in a channel.
print('{} Creating models from tracks.'.format(now()))
for node_pkey, track_pkey in progressbar.progressbar(c.execute("""
for node_pkey, track_pkey in progressbar_utils.progressbar(c.execute(
"""
SELECT pkey, track_pkey FROM node WHERE classification = ?;
""", (NodeClassification.CHANNEL.value, ))):
assert track_pkey is not None
Expand Down Expand Up @@ -461,7 +464,7 @@ def main():

print('{} Processing edge assignments.'.format(now()))
final_edge_assignments = {}
for key, available_pins in progressbar.progressbar(
for key, available_pins in progressbar_utils.progressbar(
edge_assignments.items()):
(tile_type, wire) = key
if len(available_pins) == 0:
Expand Down Expand Up @@ -522,7 +525,7 @@ def main():
)

pin_directions = {}
for key, pins in progressbar.progressbar(
for key, pins in progressbar_utils.progressbar(
final_edge_assignments.items()):
(tile_type, wire) = key
if tile_type not in pin_directions:
Expand Down
14 changes: 7 additions & 7 deletions xc7/utils/prjxray_create_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from prjxray.roi import Roi
from prjxray import grid_types
import simplejson as json
import progressbar
from lib import progressbar_utils
import datetime
import functools
from collections import namedtuple
Expand Down Expand Up @@ -1114,7 +1114,7 @@ def build_channels(conn, pool, active_tracks):

write_cur.execute("""BEGIN EXCLUSIVE TRANSACTION;""")

for y in progressbar.progressbar(range(max(x_tracks) + 1)):
for y in progressbar_utils.progressbar(range(max(x_tracks) + 1)):
if y in x_tracks:
x_channel_models[y] = x_channel_models[y].get()

Expand All @@ -1129,7 +1129,7 @@ def build_channels(conn, pool, active_tracks):
else:
x_list.append(0)

for x in progressbar.progressbar(range(max(y_tracks) + 1)):
for x in progressbar_utils.progressbar(range(max(y_tracks) + 1)):
if x in y_tracks:
y_channel_models[x] = y_channel_models[x].get()

Expand Down Expand Up @@ -1247,7 +1247,7 @@ def main():
for wire in wire_map.keys():
tile_wires.append((tile_type, wire))

for tile_type, wire in progressbar.progressbar(tile_wires):
for tile_type, wire in progressbar_utils.progressbar(tile_wires):
pins = [
direction_to_enum(pin)
for pin in pin_assignments['pin_directions'][tile_type][wire]
Expand Down Expand Up @@ -1282,7 +1282,7 @@ def main():

print('{} Finding nodes belonging to ROI'.format(now()))
if use_roi:
for loc in progressbar.progressbar(grid.tile_locations()):
for loc in progressbar_utils.progressbar(grid.tile_locations()):
gridinfo = grid.gridinfo_at_loc(loc)
tile_name = grid.tilename_at_loc(loc)

Expand Down Expand Up @@ -1316,7 +1316,7 @@ def main():

edge_set = set()

for loc in progressbar.progressbar(grid.tile_locations()):
for loc in progressbar_utils.progressbar(grid.tile_locations()):
gridinfo = grid.gridinfo_at_loc(loc)
tile_name = grid.tilename_at_loc(loc)

Expand Down Expand Up @@ -1357,7 +1357,7 @@ def main():
print('{} Created {} edges, inserting'.format(now(), len(edges)))

write_cur.execute("""BEGIN EXCLUSIVE TRANSACTION;""")
for edge in progressbar.progressbar(edges):
for edge in progressbar_utils.progressbar(edges):
write_cur.execute(
"""
INSERT INTO graph_edge(
Expand Down
2 changes: 1 addition & 1 deletion xc7/utils/prjxray_db_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
operations are then pefromed on this copy which yields in performance increase.
"""
import sqlite3
from progressbar.bar import ProgressBar
from lib.progressbar_utils import ProgressBar

# =============================================================================

Expand Down
27 changes: 14 additions & 13 deletions xc7/utils/prjxray_form_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import prjxray.db
import prjxray.tile
from prjxray.timing import PvtCorner
import progressbar
from lib import progressbar_utils
import tile_splitter.grid
from lib.rr_graph import points
from lib.rr_graph import tracks
Expand Down Expand Up @@ -415,7 +415,7 @@ def import_nodes(db, grid, conn):

tile_wire_map = {}
wires = {}
for tile in progressbar.progressbar(grid.tiles()):
for tile in progressbar_utils.progressbar(grid.tiles()):
gridinfo = grid.gridinfo_at_tilename(tile)
tile_type = db.get_tile_type(gridinfo.tile_type)

Expand Down Expand Up @@ -450,7 +450,8 @@ def import_nodes(db, grid, conn):

connections = db.connections()

for connection in progressbar.progressbar(connections.get_connections()):
for connection in progressbar_utils.progressbar(
connections.get_connections()):
a_pkey = tile_wire_map[
(connection.wire_a.tile, connection.wire_a.wire)]
b_pkey = tile_wire_map[
Expand Down Expand Up @@ -481,7 +482,7 @@ def import_nodes(db, grid, conn):
nodes[id(node)] = node

wires_assigned = set()
for node in progressbar.progressbar(nodes.values()):
for node in progressbar_utils.progressbar(nodes.values()):
write_cur.execute("""INSERT INTO node(number_pips) VALUES (0);""")
node_pkey = write_cur.lastrowid

Expand Down Expand Up @@ -781,7 +782,7 @@ def classify_nodes(conn, get_switch_timing):
AND site_wire_pkey IS NOT NULL;"""
)
num_nodes = cur.fetchone()[0]
with progressbar.ProgressBar(max_value=num_nodes) as bar:
with progressbar_utils.ProgressBar(max_value=num_nodes) as bar:
bar.update(0)
for idx, (node, site_wire_pkey) in enumerate(cur.execute("""
SELECT
Expand Down Expand Up @@ -888,7 +889,7 @@ def classify_nodes(conn, get_switch_timing):
else:
edges_to_channel.append(node)

for nodes, src_wire_pkey, dest_wire_pkey, pip_pkey in progressbar.progressbar(
for nodes, src_wire_pkey, dest_wire_pkey, pip_pkey in progressbar_utils.progressbar(
edge_with_mux):
assert len(nodes) == 2

Expand All @@ -909,7 +910,7 @@ def classify_nodes(conn, get_switch_timing):
(?, ?, ?, ?);""", (src_wire_pkey, dest_wire_pkey, pip_pkey, switch_pkey)
)

for node in progressbar.progressbar(edges_to_channel):
for node in progressbar_utils.progressbar(edges_to_channel):
write_cur.execute(
"""
UPDATE node SET classification = ?
Expand All @@ -919,7 +920,7 @@ def classify_nodes(conn, get_switch_timing):
)
)

for null_node in progressbar.progressbar(null_nodes):
for null_node in progressbar_utils.progressbar(null_nodes):
write_cur.execute(
"""
UPDATE node SET classification = ?
Expand Down Expand Up @@ -965,7 +966,7 @@ def insert_tracks(conn, tracks_to_insert):

track_graph_nodes = {}
track_pkeys = []
for node, tracks_list, track_connections, tracks_model in progressbar.progressbar(
for node, tracks_list, track_connections, tracks_model in progressbar_utils.progressbar(
tracks_to_insert):
write_cur.execute("""INSERT INTO track DEFAULT VALUES""")
track_pkey = write_cur.lastrowid
Expand Down Expand Up @@ -1032,7 +1033,7 @@ def insert_tracks(conn, tracks_to_insert):
conn.commit()

wire_to_graph = {}
for node, tracks_list, track_connections, tracks_model in progressbar.progressbar(
for node, tracks_list, track_connections, tracks_model in progressbar_utils.progressbar(
tracks_to_insert):
track_graph_node_pkey = track_graph_nodes[node]

Expand Down Expand Up @@ -1070,7 +1071,7 @@ def insert_tracks(conn, tracks_to_insert):

wire_to_graph[wire_pkey] = graph_node_pkey

for wire_pkey, graph_node_pkey in progressbar.progressbar(
for wire_pkey, graph_node_pkey in progressbar_utils.progressbar(
wire_to_graph.items()):
write_cur.execute(
"""
Expand Down Expand Up @@ -1112,7 +1113,7 @@ def form_tracks(conn):
num_nodes = cur.fetchone()[0]

tracks_to_insert = []
with progressbar.ProgressBar(max_value=num_nodes) as bar:
with progressbar_utils.ProgressBar(max_value=num_nodes) as bar:
bar.update(0)
cur2 = conn.cursor()
for idx, (node, ) in enumerate(cur.execute("""
Expand Down Expand Up @@ -1314,7 +1315,7 @@ def create_vpr_grid(conn):
# tile_type_pkey, to array of split tile type pkeys, (e.g. SLICEL/SLICEM).
tile_to_tile_type_pkeys = {}
grid_loc_map = {}
for phy_tile_pkey, tile_type_pkey, grid_x, grid_y in progressbar.progressbar(
for phy_tile_pkey, tile_type_pkey, grid_x, grid_y in progressbar_utils.progressbar(
cur.execute("""
SELECT pkey, tile_type_pkey, grid_x, grid_y FROM phy_tile;
""")):
Expand Down
8 changes: 4 additions & 4 deletions xc7/utils/prjxray_routing_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from prjxray_constant_site_pins import feature_when_routed
from prjxray_tile_import import remove_vpr_tile_prefix
import simplejson as json
import progressbar
from lib import progressbar_utils
import datetime
import re
import functools
Expand Down Expand Up @@ -427,7 +427,7 @@ def import_graph_edges(conn, graph, node_mapping):
switch_name_map = {}

print('{} Importing edges from database.'.format(now()))
with progressbar.ProgressBar(max_value=num_edges) as bar:
with progressbar_utils.ProgressBar(max_value=num_edges) as bar:
for idx, (src_graph_node, dest_graph_node, switch_pkey, phy_tile_pkey,
pip_pkey, backward) in enumerate(cur.execute("""
SELECT
Expand Down Expand Up @@ -507,7 +507,7 @@ def create_channels(conn):


def yield_nodes(nodes):
with progressbar.ProgressBar(max_value=len(nodes)) as bar:
with progressbar_utils.ProgressBar(max_value=len(nodes)) as bar:
for idx, node in enumerate(nodes):
yield node

Expand Down Expand Up @@ -568,7 +568,7 @@ def main():

xml_graph = xml_graph2.Graph(
input_rr_graph,
progressbar=progressbar.progressbar,
progressbar=progressbar_utils.progressbar,
output_file_name=args.write_rr_graph,
)

Expand Down

0 comments on commit a3c6778

Please sign in to comment.