# Path: src/tidypy/util.py
# def read_file(filepath):
#     """
#     Retrieves the contents of the specified file.
# 
#     This function performs simple caching so that the same file isn't read more
#     than once per process.
# 
#     :param filepath: the file to read
#     :type filepath: str
#     :returns: str
#     """
# 
#     with _FILE_CACHE_LOCK:
#         if filepath not in _FILE_CACHE:
#             _FILE_CACHE[filepath] = _read_file(filepath)
#     return _FILE_CACHE[filepath]
# 
# def compile_masks(masks):
#     """
#     Compiles a list of regular expressions.
# 
#     :param masks: the regular expressions to compile
#     :type masks: list(str) or str
#     :returns: list(regular expression object)
#     """
# 
#     if not masks:
#         masks = []
#     elif not isinstance(masks, (list, tuple)):
#         masks = [masks]
# 
#     return [
#         re.compile(mask)
#         for mask in masks
#     ]
# 
# def matches_masks(target, masks):
#     """
#     Determines whether or not the target string matches any of the regular
#     expressions specified.
# 
#     :param target: the string to check
#     :type target: str
#     :param masks: the regular expressions to check against
#     :type masks: list(regular expression object)
#     :returns: bool
#     """
# 
#     for mask in masks:
#         if mask.search(target):
#             return True
#     return False


from pathlib import Path
from .util import read_file, compile_masks, matches_masks
            if parent not in packages:
                paths.add(parent)

        paths.update(self.topmost_directories([
            str(Path(package).parent)
            for package in packages
        ]))

        return list(paths)

    def topmost_directories(self, directories):
        if not directories:
            return []
        directories = sorted(directories)

        topmost = directories[:1]

        for directory in directories[1:]:
            parents = sorted([
                str(parent)
                for parent in Path(directory).parents
            ])
            for parent in parents:
                if parent in topmost:
                    break
            else:
                topmost.append(directory)

        return topmost


# Path: src/tidypy/util.py
# def read_file(filepath):
#     """
#     Retrieves the contents of the specified file.
# 
#     This function performs simple caching so that the same file isn't read more
#     than once per process.
# 
#     :param filepath: the file to read
#     :type filepath: str
#     :returns: str
#     """
# 
#     with _FILE_CACHE_LOCK:
#         if filepath not in _FILE_CACHE:
#             _FILE_CACHE[filepath] = _read_file(filepath)
#     return _FILE_CACHE[filepath]
# 
# def compile_masks(masks):
#     """
#     Compiles a list of regular expressions.
# 
#     :param masks: the regular expressions to compile
#     :type masks: list(str) or str
#     :returns: list(regular expression object)
#     """
# 
#     if not masks:
#         masks = []
#     elif not isinstance(masks, (list, tuple)):
#         masks = [masks]
# 
#     return [
#         re.compile(mask)
#         for mask in masks
#     ]
# 
# def matches_masks(target, masks):
#     """
#     Determines whether or not the target string matches any of the regular
#     expressions specified.
# 
#     :param target: the string to check
#     :type target: str
#     :param masks: the regular expressions to check against
#     :type masks: list(regular expression object)
#     :returns: bool
#     """
# 
#     for mask in masks:
#         if mask.search(target):
#             return True
#     return False


# Path: src/tidypy/finder.py
from pathlib import Path
from .util import read_file, compile_masks, matches_masks

            if parent not in packages:
                paths.add(parent)

        paths.update(self.topmost_directories([
            str(Path(package).parent)
            for package in packages
        ]))

        return list(paths)

    def topmost_directories(self, directories):
        if not directories:
            return []
        directories = sorted(directories)

        topmost = directories[:1]

        for directory in directories[1:]:
            parents = sorted([
                str(parent)
                for parent in Path(directory).parents
            ])
            for parent in parents:
                if parent in topmost:
                    break
            else:
                topmost.append(directory)

        return topmost


    def read_file(self, filepath):