Index: config.py ================================================================== --- config.py +++ config.py @@ -298,27 +298,32 @@ elif not src and not fn: module = inspect.getmodule(sys._getframe(frame)) fn = inspect.getsourcefile(module) src = inspect.getcomments(module) - # within zip archive or dir? + # real filename/path + elif fn and os.path.exists(fn): + src = open(fn).read(4096) + + # assume it's within a zip elif fn: - zip = rx.zipfn.match(fn) - if zip and zipfile.is_zipfile(zip.group(1)): - src = zipfile.ZipFile(zip.group(1), "r").read(zip.group(2)) - else: - src = open(fn).read(4096) + intfn = "" + while fn and len(fn) and not os.path.exists(fn): + fn, add = os.path.split(fn) + intfn = add + "/" + intfn + if len(fn) >= 3 and intfn and zipfile.is_zipfile(fn): + src = zipfile.ZipFile(fn, "r").read(intfn.strip("/")) - return plugin_meta_extract(src, fn) + return plugin_meta_extract(src or "", fn) # Actual comment extraction logic -def plugin_meta_extract(src="", fn="", literal=False): +def plugin_meta_extract(src="", fn=None, literal=False): # defaults meta = { - "id": os.path.basename(fn or "").split(".")[0], + "id": os.path.splitext(os.path.basename(fn or "")), "fn": fn, "title": fn, "description": "no description", "config": [], "type": "module", "api": "python", "doc": "" } @@ -352,14 +357,10 @@ config.append(opt) return config # Comment extraction regexps class rx: - zipfn = re.compile(r""" - ^ (.+ \.(?:zip|pyz|pyzw|pyzip) # zip-wrapping extensions - (?:\.py)? ) /(\w.*) $ - """, re.X) comment = re.compile(r"""(^ {0,4}#.*\n)+""", re.M) hash = re.compile(r"""(^ {0,4}# *)""", re.M) keyval = re.compile(r""" ^([\w-]+):(.*$(?:\n(?![\w-]+:).+$)*) # plain key:value lines """, re.M|re.X)