Strip/normalize given path Left side part of the target is replaced with the configured strip path This is to prevent temporary locations to appear in a part and are instead replaced with a normalize path E.g.: `/var/tmp/some_extracted_archive.zip/setup.py`
(self, target: Union[str, Path], include_parent: bool=True)
| 297 | return child |
| 298 | |
| 299 | def strip(self, target: Union[str, Path], include_parent: bool=True) -> str: |
| 300 | """ |
| 301 | Strip/normalize given path |
| 302 | Left side part of the target is replaced with the configured strip path |
| 303 | This is to prevent temporary locations to appear in a part and are instead replaced with a normalize path |
| 304 | E.g.: |
| 305 | `/var/tmp/some_extracted_archive.zip/setup.py` |
| 306 | would become: |
| 307 | `some_extracted_archive.zip$setup.py` |
| 308 | which signifies that the setup.py is inside the archive and leaves out the temporary unpack location |
| 309 | |
| 310 | :param target: Path to replace/strip |
| 311 | :return: normalized path |
| 312 | """ |
| 313 | if type(target) == str: |
| 314 | target = Path(target) |
| 315 | |
| 316 | try: |
| 317 | target = target.relative_to(self.strip_path) |
| 318 | except ValueError: # strip_path is not a prefix of target |
| 319 | pass |
| 320 | |
| 321 | if include_parent and self.parent: |
| 322 | p = str(self.parent) |
| 323 | line_no = self.metadata.get("parent_line") |
| 324 | if line_no is not None: |
| 325 | p = f"{p}:{line_no}" |
| 326 | |
| 327 | return f"{p}${str(target)}" |
| 328 | |
| 329 | return str(target) |
| 330 | |
| 331 | def should_continue(self) -> Union[bool, Detection]: |
| 332 | """ |