def insert_on(self, path, loc=None, replace=False):
loc = loc or self.location<EOL>if not loc:<EOL><INDENT>return<EOL><DEDENT>nloc = _normalize_cached(loc)<EOL>bdir = os.path.dirname(nloc)<EOL>npath = [(p and _normalize_cached(p) or p) for p in path]<EOL>for p, item in enumerate(npath):<EOL><INDENT>if item == nloc:<EOL><INDENT>if replace:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT><DEDENT>elif item == bdir and self.precedence == EGG_DIST:<EOL><INDENT>if (not replace) and nloc in npath[p:]:<EOL><INDENT>return<EOL><DEDENT>if path is sys.path:<EOL><INDENT>self.check_version_conflict()<EOL><DEDENT>path.insert(p, loc)<EOL>npath.insert(p, nloc)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if path is sys.path:<EOL><INDENT>self.check_version_conflict()<EOL><DEDENT>if replace:<EOL><INDENT>path.insert(<NUM_LIT:0>, loc)<EOL><DEDENT>else:<EOL><INDENT>path.append(loc)<EOL><DEDENT>return<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>np = npath.index(nloc, p + <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>del npath[np], path[np]<EOL>p = np<EOL><DEDENT><DEDENT>return<EOL>
Ensure self.location is on path

        If replace=False (default):
            - If location is already in path anywhere, do nothing.
            - Else:
              - If it's an egg and its parent directory is on path,
                insert just ahead of the parent.
              - Else: add to the end of path.
        If replace=True:
            - If location is already on path anywhere (not eggs)
              or higher priority than its parent (eggs)
              do nothing.
            - Else:
              - If it's an egg and its parent directory is on path,
                insert just ahead of the parent,
                removing any lower-priority entries.
              - Else: add it to the front of path.