diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a110c23bdee..fb8f2777fda8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,8 @@ repos: - id: astyle_py args: [--style=java --unpad-paren --pad-header --pad-oper --add-brackets --indent-switches --align-pointer=type] exclude: 'src/foreign/.*' +- repo: https://github.com/hhatto/autopep8 + rev: v2.0.4 + hooks: + - id: autopep8 + args: ['--max-line-length', '120', '--in-place'] diff --git a/tools/assign/duaIterate_reroutingAnalysis.py b/tools/assign/duaIterate_reroutingAnalysis.py index ac052033baa3..ae0ea3782ee6 100755 --- a/tools/assign/duaIterate_reroutingAnalysis.py +++ b/tools/assign/duaIterate_reroutingAnalysis.py @@ -28,8 +28,8 @@ def parse_args(args=None): USAGE = "Usage: " + sys.argv[0] + " [options]" parser = sumolib.options.ArgumentParser( - usage=USAGE, - description="Extract fraction of vehicles that changed their route per iteration") + usage=USAGE, + description="Extract fraction of vehicles that changed their route per iteration") parser.add_argument("-d", "--base-directory", dest="baseDir", category="input", default=".", type=str, help="Base directory of duaIterate run") parser.add_argument("-v", "--verbose", action="store_true", default=False, diff --git a/tools/build_config/templates.py b/tools/build_config/templates.py index 988ef4effbe7..c8ee789ccff1 100755 --- a/tools/build_config/templates.py +++ b/tools/build_config/templates.py @@ -337,7 +337,8 @@ def generateTemplate(app, appBin): print("Obtaining " + app + " template") # obtain template piping stdout using check_output try: - template = formatBinTemplate(subprocess.check_output([appBin, "--save-template", "stdout"], universal_newlines=True)) + template = formatBinTemplate(subprocess.check_output( + [appBin, "--save-template", "stdout"], universal_newlines=True)) except subprocess.CalledProcessError as e: sys.stderr.write("Error when generating template for " + app + ": '%s'" % e) template = "" diff --git a/tools/drt/drtOnline.py b/tools/drt/drtOnline.py index 1d2332b58694..244cbbbd793a 100755 --- a/tools/drt/drtOnline.py +++ b/tools/drt/drtOnline.py @@ -117,9 +117,9 @@ def find_dua_times(options): with open("temp_dua/dua_file.xml", "w+") as dua_file: dua_file.write("\n") for comb_edges in list(combination_edges): - dua_file.write('\t\n' + dua_file.write(' \n' % (comb_edges[0], comb_edges[1], comb_edges[0], comb_edges[1])) - dua_file.write('\t\n' + dua_file.write(' \n' % (comb_edges[1], comb_edges[0], comb_edges[1], comb_edges[0])) dua_file.write("\n") @@ -176,13 +176,11 @@ def ilp_solve(options, veh_num, res_num, costs, veh_constraints, # add constraints for index in range(veh_num): prob += pl.lpSum([veh_constraints[i][index] * Trips_vars[i] - for i in order_trips]) <= 1, \ - "Max_1_trip_per_vehicle_%s" % index + for i in order_trips]) <= 1, "Max_1_trip_per_vehicle_%s" % index for index in range(res_num): prob += pl.lpSum([res_constraints[i][index] * Trips_vars[i] - for i in order_trips]) <= 1, \ - "Max_1_trip_per_reservation_%s" % index + for i in order_trips]) <= 1, "Max_1_trip_per_reservation_%s" % index prob += pl.lpSum([sum(veh_constraints[i]) * Trips_vars[i] for i in order_trips]) >= 1, "Assing_at_least_one_vehicle" @@ -440,8 +438,7 @@ def main(): for idx, trip_id in enumerate(trips): # routes[route] = [travel_time, veh_bin, res_bin, value] # TODO specific cost for vehicle can be consider here - bonus_cost = (sum(routes[trip_id][2]) + 1) * \ - options.cost_per_trip + bonus_cost = (sum(routes[trip_id][2]) + 1) * options.cost_per_trip # generate dict with costs costs.update({idx: routes[trip_id][0] + bonus_cost}) # generate dict with vehicle used in the trip diff --git a/tools/game/racing.py b/tools/game/racing.py index 6ea9de8b32b2..aac580dfbe8f 100755 --- a/tools/game/racing.py +++ b/tools/game/racing.py @@ -52,7 +52,7 @@ # Check for playsound import try: - import playsound # noqa + import playsound # noqa except ImportError: sys.stderr.write("playsound not installed. Sounds will not be played on collisions.\n") playsound = None diff --git a/tools/import/vissim/convert_vissimXML_flows_statRoutes.py b/tools/import/vissim/convert_vissimXML_flows_statRoutes.py index 98e01407765e..558d68709944 100755 --- a/tools/import/vissim/convert_vissimXML_flows_statRoutes.py +++ b/tools/import/vissim/convert_vissimXML_flows_statRoutes.py @@ -353,7 +353,7 @@ def validate_rel_flow(routes_by_start_d, flow_d): continue else: # check if the time frame starts are the same - assert np.array_equal(ref_time_shape[:, 0], route["rel_flow"][:, 0]),\ + assert np.array_equal(ref_time_shape[:, 0], route["rel_flow"][:, 0]), \ "\nPROBLEM: flow count and relative flow time frames are not aligned\n\t"\ "for VISSIM start link id: " + start_link # copy back modifications diff --git a/tools/output/vehrouteCountValidation.py b/tools/output/vehrouteCountValidation.py index 28d656fb848d..37ff83c2ac6a 100755 --- a/tools/output/vehrouteCountValidation.py +++ b/tools/output/vehrouteCountValidation.py @@ -104,6 +104,7 @@ def get_options(args=None): class Routes: """dummy class to allow using the same methods as routeSampler.py""" + def __init__(self): self.unique = [] diff --git a/tools/purgatory/dijkstra.py b/tools/purgatory/dijkstra.py index 51e5dca8ca97..39531b1b81da 100644 --- a/tools/purgatory/dijkstra.py +++ b/tools/purgatory/dijkstra.py @@ -256,4 +256,4 @@ def least_cost(self, start, dest, costFactors=defaultdict(lambda: 1.0)): return D[dest] else: raise ("No path between %s and %s found" % - (start.getID(), dest.getID())) + (start.getID(), dest.getID())) diff --git a/tools/runSeeds.py b/tools/runSeeds.py index 28c5d9f9eb76..06136bbd8dfd 100755 --- a/tools/runSeeds.py +++ b/tools/runSeeds.py @@ -44,7 +44,7 @@ def get_options(args=None): ap.add_option("-k", "--configuration", category="input", metavar="FILE", required=True, type=ap.sumoconfig_file_list, help="configuration to run or comma-separated list of configurations") - ap.add_option("-a", "--application", category="processing", default="sumo", metavar="FILE", + ap.add_option("-a", "--application", category="processing", default=sumolib.checkBinary("sumo"), metavar="FILE", help="application to run or comma-separated list of applications") ap.add_option("-p", "--output-prefix", category="processing", default="SEED.", dest="prefix", help="output prefix",) diff --git a/tools/sumolib/color.py b/tools/sumolib/color.py index 564c7280a85b..ad751621e010 100644 --- a/tools/sumolib/color.py +++ b/tools/sumolib/color.py @@ -35,19 +35,19 @@ def toXML(self): def decodeXML(c): colorSwitch = { - "red": RGBAColor(255, 0, 0, 255), - "green": RGBAColor(0, 255, 0, 255), - "blue": RGBAColor(0, 0, 255, 255), - "yellow": RGBAColor(255, 255, 0, 255), - "cyan": RGBAColor(0, 255, 255, 255), - "magenta": RGBAColor(255, 0, 255, 255), - "orange": RGBAColor(255, 128, 0, 255), - "white": RGBAColor(255, 255, 255, 255), - "black": RGBAColor(0, 0, 0, 255), - "grey": RGBAColor(128, 128, 128, 255), - "gray": RGBAColor(128, 128, 128, 255), - "invisible": RGBAColor(0, 0, 0, 0) - } + "red": RGBAColor(255, 0, 0, 255), + "green": RGBAColor(0, 255, 0, 255), + "blue": RGBAColor(0, 0, 255, 255), + "yellow": RGBAColor(255, 255, 0, 255), + "cyan": RGBAColor(0, 255, 255, 255), + "magenta": RGBAColor(255, 0, 255, 255), + "orange": RGBAColor(255, 128, 0, 255), + "white": RGBAColor(255, 255, 255, 255), + "black": RGBAColor(0, 0, 0, 255), + "grey": RGBAColor(128, 128, 128, 255), + "gray": RGBAColor(128, 128, 128, 255), + "invisible": RGBAColor(0, 0, 0, 0) + } knownColor = colorSwitch.get(c) if knownColor is None: return RGBAColor(*[float(x) for x in c.split(",")])