"upload-process --exclude" flags don't seem to work when uploading reports #482
Description
While trying to exclude paths from search when running upload-process
, I found that excluded paths were still being searched (and producing false-positive uploads of un-processable data). I tried passing them as relative and absolute paths before rolling up my sleeves and splashing a hundred logger.debug()
calls through the code to trace it out. What I found follows:
When select_file_finder()
is called, it gets a list of Path objects. But search_files() compares this as a list of strings; if d in folders_to_ignore
is never true, so excluded paths still end up in the search tree when scanning for reports. I don't really know Python as much as I know how to be clumsy with Python but search_files()
seems to expect a List(str)
. While I'm unfamiliar with Typing it looks like there's no implicit casting for a List(Path)
to a List(str)
? Here's a very, very trivial example I worked up based on the code from folder_searcher.py
:
from pathlib import Path
paths = [Path("example1"), Path("example2"), Path("example3")]
strings = ["example1", "example2", "example3"]
matches = set(d for d in paths if d in strings)
print(f"paths that match: {matches}")
$ python3 example.py
paths that match: set()
Compared to:
from pathlib import Path
paths = [Path("example1"), Path("example2"), Path("example3")]
strings = ["example1", "example2", "example3"]
matches = set(d for d in paths if str(d) in strings)
print(f"paths that match: {matches}")
$ python3 example.py
paths that match: {PosixPath('example1'), PosixPath('example3'), PosixPath('example2')}
I'm not sure it's the cleanest way, but everything "just works" if I cast everything passed as folders_to_ignore
to strings during FileFinder
initialization but this feels kind of dodgy/hamfisted to me (again, not actually good at Python):
def select_file_finder(
root_folder_to_search,
folders_to_ignore,
explicitly_listed_files,
disable_search,
report_type="coverage",
):
# cast everything passed in folders_to_ignore as a string
folders_to_ignore = [str(dir) for dir in folders_to_ignore]
return FileFinder(
root_folder_to_search,
folders_to_ignore,
explicitly_listed_files,
disable_search,
report_type,
)