Remove common directory prefix from all strings in a. This uses a naive string replace; it seems to work well enough. Also remove trailing carriage returns.
(a: list[str])
| 270 | |
| 271 | |
| 272 | def clean_up(a: list[str]) -> list[str]: |
| 273 | """Remove common directory prefix from all strings in a. |
| 274 | |
| 275 | This uses a naive string replace; it seems to work well enough. Also |
| 276 | remove trailing carriage returns. |
| 277 | """ |
| 278 | res = [] |
| 279 | pwd = os.getcwd() |
| 280 | driver = pwd + "/driver.py" |
| 281 | for s in a: |
| 282 | prefix = os.sep |
| 283 | ss = s |
| 284 | for p in prefix, prefix.replace(os.sep, "/"): |
| 285 | if p != "/" and p != "//" and p != "\\" and p != "\\\\": |
| 286 | ss = ss.replace(p, "") |
| 287 | # Replace memory address with zeros |
| 288 | if "at 0x" in ss: |
| 289 | ss = re.sub(r"(at 0x)\w+>", r"\g<1>000000000000>", ss) |
| 290 | # Ignore spaces at end of line. |
| 291 | ss = re.sub(" +$", "", ss) |
| 292 | # Remove pwd from driver.py's path |
| 293 | ss = ss.replace(driver, "driver.py") |
| 294 | res.append(re.sub("\\r$", "", ss)) |
| 295 | return res |
| 296 | |
| 297 | |
| 298 | @contextlib.contextmanager |
no test coverage detected
searching dependent graphs…