code: def filenameToModname(self, filename):
          
          for ext in reversed(self._exts):
              if filename.endswith(ext):
                  filename = filename[:-len(ext)]
                  break
          else:
              self.warn(filename, '%s: unknown file name extension', filename)
          filename = os.path.abspath(filename)
          elements = filename.split(os.path.sep)
          modname = []
          while elements:
              modname.append(elements[-1])
              del elements[-1]
              if not os.path.exists(os.path.sep.join(elements + ['__init__.py'])):
                  break
          modname.reverse()
          modname = ".".join(modname)
          return modname
docs: Convert a filename to a module name.