Skip to content

Commit

Permalink
python: Added r prefix to regex string literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
levy committed Sep 3, 2024
1 parent 98b131e commit 17f4915
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 101 deletions.
2 changes: 1 addition & 1 deletion bin/inet_diffingerprints
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def computeUniqueFingerprints(fingerprints):

def readFingerprints1(eventlogFile):
"RegExp version"
regExp = re.compile("^E # ([0-9]+) t ((?:[0-9]*\.)?[0-9]+) m [0-9]+ ce [0-9]+ msg [0-9]+ f (?:\"([^\"]*)\"|(\S+))$")
regExp = re.compile(r"^E # ([0-9]+) t ((?:[0-9]*\.)?[0-9]+) m [0-9]+ ce [0-9]+ msg [0-9]+ f (?:\"([^\"]*)\"|(\S+))$")
fingerprints = list()
for line in eventlogFile:
match = regExp.match(line)
Expand Down
18 changes: 9 additions & 9 deletions python/inet/common/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ def get_parameters_string(self, **kwargs):

def get_input_files(self):
output_folder = f"out/clang-{self.mode}"
object_path = re.sub("\\.msg", "_m.cc", self.file_path)
dependency_file_path = re.sub("\\.msg", "_m.h.d", self.file_path)
object_path = re.sub(r"\\.msg", "_m.cc", self.file_path)
dependency_file_path = re.sub(r"\\.msg", "_m.h.d", self.file_path)
full_file_path = self.simulation_project.get_full_path(os.path.join(output_folder, dependency_file_path))
if os.path.exists(full_file_path):
dependency = read_dependency_file(full_file_path)
# KLUDGE: src folder hacked in and out
file_paths = dependency[re.sub("src/", "", object_path)]
file_paths = dependency[re.sub(r"src/", "", object_path)]
return list(map(lambda file_path: self.simulation_project.get_full_path(os.path.join("src", file_path)), file_paths))
else:
return [self.file_path]

def get_output_files(self):
cpp_file_path = re.sub("\\.msg", "_m.cc", self.file_path)
header_file_path = re.sub("\\.msg", "_m.h", self.file_path)
cpp_file_path = re.sub(r"\\.msg", "_m.cc", self.file_path)
header_file_path = re.sub(r"\\.msg", "_m.h", self.file_path)
return [f"{cpp_file_path}", f"{header_file_path}"]

def get_arguments(self):
executable = "opp_msgc"
output_folder = f"out/clang-{self.mode}"
header_file_path = re.sub("\\.msg", "_m.h", self.file_path)
header_file_path = re.sub(r"\\.msg", "_m.h", self.file_path)
import_paths = list(map(lambda msg_folder: self.simulation_project.get_full_path(msg_folder), self.simulation_project.msg_folders))
return [executable,
"--msg6",
Expand Down Expand Up @@ -118,8 +118,8 @@ def get_parameters_string(self, **kwargs):

def get_input_files(self):
output_folder = f"out/clang-{self.mode}"
object_path = re.sub("\\.cc", ".o", self.file_path)
dependency_file_path = re.sub("\\.cc", ".o.d", self.file_path)
object_path = re.sub(r"\\.cc", ".o", self.file_path)
dependency_file_path = re.sub(r"\\.cc", ".o.d", self.file_path)
full_file_path = self.simulation_project.get_full_path(os.path.join(output_folder, dependency_file_path))
if os.path.exists(full_file_path):
dependency = read_dependency_file(full_file_path)
Expand All @@ -130,7 +130,7 @@ def get_input_files(self):

def get_output_files(self):
output_folder = f"out/clang-{self.mode}"
object_path = re.sub("\\.cc", ".o", self.file_path)
object_path = re.sub(r"\\.cc", ".o", self.file_path)
return [f"{output_folder}/{object_path}"]

def get_arguments(self):
Expand Down
4 changes: 2 additions & 2 deletions python/inet/common/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def collect_modules(simulation_project, path="src"):
match = re.match(r"^package ([\w\.]+)", line)
if match:
package = match.group(1)
package = re.sub("^\w+?\.", "", package)
package = re.sub(r"^\w+?\.", "", package)
match = re.match(r"^(simple|module|network) (\w+)\b", line)
if match:
module = match.group(2)
Expand Down Expand Up @@ -122,7 +122,7 @@ def collect_classes(simulation_project, path="src"):
if match:
class_name = match.group(1)
relative_path = os.path.relpath(os.path.dirname(file_name), project_path)
relative_path = re.sub("^(\w+)/", "", relative_path)
relative_path = re.sub(r"^(\w+)/", "", relative_path)
classes.append(relative_path + "/" + class_name)
file.close()
return classes
Expand Down
20 changes: 10 additions & 10 deletions python/inet/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def coalesce(*values):

def convert_to_seconds(s):
seconds_per_unit = {"ps": 1E-12, "ns": 1E-9, "us": 1E-6, "ms": 1E-3, "s": 1, "second": 1, "m": 60, "min": 60, "h": 3600, "hour": 3600, "d": 86400, "day": 86400, "w": 604800, "week": 604800}
match = re.match("(-?[0-9]*\.?[0-9]*) *([a-zA-Z]+)", s)
match = re.match(r"(-?[0-9]*\.?[0-9]*) *([a-zA-Z]+)", s)
return float(match.group(1)) * seconds_per_unit[match.group(2)]

def write_object(file_name, object):
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(self, logger):
def collect_existing_ned_types():
types = set()
for ini_file_path in glob.glob(get_inet_relative_path("**/*.ned"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ini_file_path, "r") as f:
text = f.read()
for type in re.findall("^simple (\\w+)", text, re.M):
Expand All @@ -294,17 +294,17 @@ def collect_existing_ned_types():
def collect_referenced_ned_types():
types = set()
for ini_file_path in glob.glob(get_inet_relative_path("**/*.ini"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ini_file_path, "r") as f:
for type in re.findall("typename = \"(\\w+?)\"", f.read()):
types.add(type)
for ned_file_path in glob.glob(get_inet_relative_path("**/*.ned"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ned_file_path, "r") as f:
for type in re.findall("~(\\w+)", f.read()):
types.add(type)
for rst_file_path in glob.glob(get_inet_relative_path("**/*.rst"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(rst_file_path, "r") as f:
for type in re.findall(":ned:`(\\w+?)`", f.read()):
types.add(type)
Expand All @@ -313,12 +313,12 @@ def collect_referenced_ned_types():
def collect_ned_type_reference_file_paths(type):
references = []
for ini_file_path in glob.glob(get_inet_relative_path("**/*.ini"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ini_file_path, "r") as f:
if re.search(f"typename = \"{type}\"", f.read()):
references.append(ini_file_path)
for rst_file_path in glob.glob(get_inet_relative_path("**/*.rst"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(rst_file_path, "r") as f:
if re.search(f":ned:`{type}`", f.read()):
references.append(rst_file_path)
Expand All @@ -327,7 +327,7 @@ def collect_ned_type_reference_file_paths(type):
def collect_existing_msg_types():
types = set()
for ini_file_path in glob.glob(get_inet_relative_path("**/*.msg"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ini_file_path, "r") as f:
text = f.read()
for type in re.findall("^class (\\w+)", text, re.M):
Expand All @@ -339,15 +339,15 @@ def collect_existing_msg_types():
def collect_existing_cpp_types():
types = set()
for ini_file_path in glob.glob(get_inet_relative_path("**/*.h"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ini_file_path, "r") as f:
text = f.read()
for type in re.findall("^class INET_API (\\w+)", text, re.M):
types.add(type)
for type in re.findall("^enum (\\w+)", text, re.M):
types.add(type)
for ini_file_path in glob.glob(get_inet_relative_path("**/*.cc"), recursive=True):
if not re.search("doc/src/_deploy", ini_file_path):
if not re.search(r"doc/src/_deploy", ini_file_path):
with open(ini_file_path, "r") as f:
text = f.read()
for type in re.findall("Register_Packet_Dropper_Function\\((\\w+),", text, re.M):
Expand Down
2 changes: 1 addition & 1 deletion python/inet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def process_run_tasks_arguments(args):
if not has_filter_kwarg and not args.simulation_project:
kwargs["working_directory_filter"] = os.path.relpath(os.getcwd(), os.path.realpath(simulation_project.get_full_path(".")))
if "working_directory_filter" in kwargs:
kwargs["working_directory_filter"] = re.sub("(.*)/$", "\\1", kwargs["working_directory_filter"])
kwargs["working_directory_filter"] = re.sub(r"(.*)/$", "\\1", kwargs["working_directory_filter"])
if args.simulation_runner == "inprocess":
import omnetpp.cffi
del kwargs["hosts"]
Expand Down
8 changes: 4 additions & 4 deletions python/inet/simulation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def __init__(self, simulation_project=None, name="MSG compile task", mode="relea
self.simulation_project = simulation_project
self.mode = mode
self.input_files = list(map(lambda input_file: self.simulation_project.get_full_path(input_file), self.simulation_project.get_msg_files()))
self.output_files = list(map(lambda output_file: re.sub("\\.msg", "_m.cc", output_file), self.input_files)) + \
list(map(lambda output_file: re.sub("\\.msg", "_m.h", output_file), self.input_files))
self.output_files = list(map(lambda output_file: re.sub(r"\\.msg", "_m.cc", output_file), self.input_files)) + \
list(map(lambda output_file: re.sub(r"\\.msg", "_m.h", output_file), self.input_files))

def get_description(self):
return self.simulation_project.get_name() + " " + super().get_description()
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_object_files(self):
object_files = []
for cpp_folder in self.simulation_project.cpp_folders:
file_paths = glob.glob(self.simulation_project.get_full_path(os.path.join(cpp_folder, "**/*.cc")), recursive=True)
object_files = object_files + list(map(lambda file_path: os.path.join(output_folder, self.simulation_project.get_relative_path(re.sub("\\.cc", ".o", file_path))), file_paths))
object_files = object_files + list(map(lambda file_path: os.path.join(output_folder, self.simulation_project.get_relative_path(re.sub(r"\\.cc", ".o", file_path))), file_paths))
return object_files

def is_up_to_date(self):
Expand Down Expand Up @@ -280,7 +280,7 @@ def get_build_tasks(self, **kwargs):
os.makedirs(output_folder)
msg_compile_tasks = list(map(lambda msg_file: MsgCompileTask(simulation_project=self.simulation_project, file_path=msg_file, mode=self.mode), self.simulation_project.get_msg_files()))
multiple_msg_compile_tasks = MultipleMsgCompileTasks(simulation_project=self.simulation_project, mode=self.mode, tasks=msg_compile_tasks, concurrent=self.concurrent_child_tasks)
msg_cpp_compile_tasks = list(map(lambda msg_file: CppCompileTask(simulation_project=self.simulation_project, file_path=re.sub("\\.msg", "_m.cc", msg_file), mode=self.mode), self.simulation_project.get_msg_files()))
msg_cpp_compile_tasks = list(map(lambda msg_file: CppCompileTask(simulation_project=self.simulation_project, file_path=re.sub(r"\\.msg", "_m.cc", msg_file), mode=self.mode), self.simulation_project.get_msg_files()))
cpp_compile_tasks = list(map(lambda cpp_file: CppCompileTask(simulation_project=self.simulation_project, file_path=cpp_file, mode=self.mode), self.simulation_project.get_cpp_files()))
all_cpp_compile_tasks = msg_cpp_compile_tasks + cpp_compile_tasks
multiple_cpp_compile_tasks = MultipleCppCompileTasks(simulation_project=self.simulation_project, mode=self.mode, tasks=all_cpp_compile_tasks, concurrent=self.concurrent_child_tasks)
Expand Down
2 changes: 1 addition & 1 deletion python/inet/simulation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def clean_simulation_results(self):
_logger.info("Cleaning simulation results, folder = " + self.working_directory)
simulation_project = self.simulation_project
path = os.path.join(simulation_project.get_full_path(self.working_directory), "results")
if not re.search(".*/home/.*", path):
if not re.search(r".*/home/.*", path):
raise Exception("Path is not in home")
if os.path.exists(path):
shutil.rmtree(path)
32 changes: 16 additions & 16 deletions python/inet/simulation/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ def get_effective_include_folders(self):
def get_cpp_files(self):
cpp_files = []
for cpp_folder in self.cpp_folders:
file_paths = list(filter(lambda file_path: not re.search("_m\\.cc", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.cc")), recursive=True)))
file_paths = list(filter(lambda file_path: not re.search(r"_m\\.cc", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.cc")), recursive=True)))
cpp_files = cpp_files + list(map(lambda file_path: self.get_relative_path(file_path), file_paths))
return cpp_files

def get_header_files(self):
header_files = []
for cpp_folder in self.cpp_folders:
file_paths = list(filter(lambda file_path: not re.search("_m\\.h", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.h")), recursive=True)))
file_paths = list(filter(lambda file_path: not re.search(r"_m\\.h", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.h")), recursive=True)))
header_files = header_files + list(map(lambda file_path: self.get_relative_path(file_path), file_paths))
return header_files

Expand Down Expand Up @@ -313,34 +313,34 @@ def create_config_dict(config):
config_dicts = {"General": create_config_dict("General")}
config_dict = {}
for line in file:
match = re.match("\\[(Config +)?(.*?)\\]", line)
match = re.match(r"\\[(Config +)?(.*?)\\]", line)
if match:
config = match.group(2) or match.group(3)
config_dict = create_config_dict(config)
config_dicts[config] = config_dict
match = re.match("#? *abstract-config *= *(\w+)", line)
match = re.match(r"#? *abstract-config *= *(\w+)", line)
if match:
config_dict["abstract_config"] = bool(match.group(1))
match = re.match("#? *emulation *= *(\w+)", line)
match = re.match(r"#? *emulation *= *(\w+)", line)
if match:
config_dict["emulation"] = bool(match.group(1))
match = re.match("#? *expected-result *= *\"(\w+)\"", line)
match = re.match(r"#? *expected-result *= *\"(\w+)\"", line)
if match:
config_dict["expected_result"] = match.group(1)
line = re.sub("(.*)#.*", "//1", line).strip()
match = re.match(" *extends *= *(\w+)", line)
line = re.sub(r"(.*)#.*", "//1", line).strip()
match = re.match(r" *extends *= *(\w+)", line)
if match:
config_dict["extends"] = match.group(1)
match = re.match(" *user-interface *= \"*(\w+)\"", line)
match = re.match(r" *user-interface *= \"*(\w+)\"", line)
if match:
config_dict["user_interface"] = match.group(1)
match = re.match("description *= *\"(.*)\"", line)
match = re.match(r"description *= *\"(.*)\"", line)
if match:
config_dict["description"] = match.group(1)
match = re.match("network *= *(.*)", line)
match = re.match(r"network *= *(.*)", line)
if match:
config_dict["network"] = match.group(1)
match = re.match("sim-time-limit *= *(.*)", line)
match = re.match(r"sim-time-limit *= *(.*)", line)
if match:
config_dict["sim_time_limit"] = match.group(1)
general_config_dict = config_dicts["General"]
Expand All @@ -362,14 +362,14 @@ def create_config_dict(config):
result = subprocess.run(args, cwd=working_directory, capture_output=True, env=self.get_env())
if result.returncode == 0:
# KLUDGE: this was added to test source dependency based task result caching
result.stdout = re.sub("INI dependency: (.*)", "", result.stdout.decode("utf-8"))
result.stdout = re.sub(r"INI dependency: (.*)", "", result.stdout.decode("utf-8"))
num_runs = int(result.stdout)
else:
_logger.warn("Cannot determine number of runs: " + result.stderr.decode("utf-8") + " in " + working_directory)
continue
sim_time_limit = get_sim_time_limit(config_dicts, config)
description = config_dict["description"]
description_abstract = (re.search("\((a|A)bstract\)", description) is not None) if description else False
description_abstract = (re.search(r"\((a|A)bstract\)", description) is not None) if description else False
abstract = (config_dict["network"] is None and config_dict["config"] == "General") or config_dict["abstract_config"] or description_abstract
emulation = config_dict["emulation"]
expected_result = config_dict["expected_result"]
Expand Down Expand Up @@ -420,7 +420,7 @@ def append_file_if_exists(file_name):
file_paths.append(self.get_executable(mode="release"))
file_paths.append(self.get_executable(mode="debug"))
file_paths += list(glob.glob(get_omnetpp_relative_path("lib/*.so")))
file_paths += list(filter(lambda path: not re.search("formatter", path), glob.glob(get_omnetpp_relative_path("python/**/*.py"), recursive=True)))
file_paths += list(filter(lambda path: not re.search(r"formatter", path), glob.glob(get_omnetpp_relative_path("python/**/*.py"), recursive=True)))
append_file_if_exists(self.get_full_path(".omnetpp"))
append_file_if_exists(self.get_full_path(".nedfolders"))
append_file_if_exists(self.get_full_path(".nedexclusions"))
Expand All @@ -432,7 +432,7 @@ def append_file_if_exists(file_name):
append_file_if_exists(self.get_full_path(os.path.join(self.library_folder, "lib" + dynamic_library + ".so")))
append_file_if_exists(self.get_full_path(os.path.join(self.library_folder, "lib" + dynamic_library + "_dbg.so")))
for ned_folder in self.ned_folders:
if not re.search("test", ned_folder):
if not re.search(r"test", ned_folder):
file_paths += glob.glob(self.get_full_path(os.path.join(ned_folder, "**/*.ini")), recursive=True)
file_paths += glob.glob(self.get_full_path(os.path.join(ned_folder, "**/*.ned")), recursive=True)
for python_folder in self.python_folders:
Expand Down
Loading

0 comments on commit 17f4915

Please sign in to comment.