def _get_relative_base_path(filename, path_to_check):
importable_path = None<EOL>path_to_check = os.path.normcase(path_to_check)<EOL>abs_filename = os.path.abspath(filename)<EOL>if os.path.normcase(abs_filename).startswith(path_to_check):<EOL><INDENT>importable_path = abs_filename<EOL><DEDENT>real_filename = os.path.realpath(filename)<EOL>if os.path.normcase(real_filename).startswith(path_to_check):<EOL><INDENT>importable_path = real_filename<EOL><DEDENT>if importable_path:<EOL><INDENT>base_path = os.path.splitext(importable_path)[<NUM_LIT:0>]<EOL>relative_base_path = base_path[len(path_to_check) :]<EOL>return [pkg for pkg in relative_base_path.split(os.sep) if pkg]<EOL><DEDENT>return None<EOL>
Extracts the relative mod path of the file to import from

    Check if a file is within the passed in path and if so, returns the
    relative mod path from the one passed in.

    If the filename is no in path_to_check, returns None

    Note this function will look for both abs and realpath of the file,
    this allows to find the relative base path even if the file is a
    symlink of a file in the passed in path

    Examples:
        _get_relative_base_path("/a/b/c/d.py", "/a/b") ->  ["c","d"]
        _get_relative_base_path("/a/b/c/d.py", "/dev") ->  None