simonw / symbex

Find the Python code for specified symbols
Apache License 2.0
231 stars 6 forks source link

Bug: Exclusions not working for relative directories #43

Open jzumwalt opened 6 months ago

jzumwalt commented 6 months ago

I believe I found a case where excludes aren't found because the file path is relative, but the directory has been fully resolved.

To Reproduce

Expected

Actual

jzumwalt commented 6 months ago

I don't have permission to create a Pull request, but I have fixed this locally.

Exclude directory fully resolved here: https://github.com/simonw/symbex/blob/071d8a841c78718713cd4bd83bddd55544d639c8/symbex/cli.py#L55

When files are evaluated https://github.com/simonw/symbex/blob/071d8a841c78718713cd4bd83bddd55544d639c8/symbex/cli.py#L399

change to: if any(path.resolve().is_relative_to(exclude) for exclude in excludes): continue

Also noticed that path lib has a function that appears to be identical to is_subpath so I used that instead.

def is_subpath(path: pathlib.Path, parent: pathlib.Path) -> bool: try: path.relative_to(parent) return True except ValueError: return False

def is_relative_to(self, *other): """Return True if the path is relative to another path or False. """ try: self.relative_to(*other) return True except ValueError: return False