From c372b386b66764165b9a0b71f17aa9adde8b4b16 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 12 May 2014 03:52:22 +0300 Subject: [PATCH] make_metadata.py: Script to make a setup.py from concise module metadata. --- make_metadata.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 make_metadata.py diff --git a/make_metadata.py b/make_metadata.py new file mode 100644 index 00000000..c1f014fc --- /dev/null +++ b/make_metadata.py @@ -0,0 +1,83 @@ +import glob + +TEMPLATE = """\ +import sys +# Remove current dir from sys.path, otherwise setuptools will peek up our +# module instead of system. +sys.path.pop(0) +from setuptools import setup + + +setup(name='micropython-%(name)s', + version='%(version)s', + description=%(desc)r, + long_description=%(long_desc)r, + url='https://github.com/micropython/micropython/issues/405', + author=%(author)r, + author_email=%(author_email)r, + maintainer=%(maintainer)r, + maintainer_email='micro-python@googlegroups.com', + license=%(license)r, + py_modules=['%(name)s']) +""" + +DUMMY_DESC = """\ +This is a dummy implementation of a module for MicroPython standard library. +It contains zero or very little functionality, and primarily intended to +avoid import errors (using idea that even if an application imports a +module, it may be not using it onevery code path, so may work at least +partially). It is expected that more complete implementation of the module +will be provided later. Please help with the development if you are +interested in this module.""" + +MICROPYTHON_DEVELS = 'MicroPython Developers' +MICROPYTHON_DEVELS_EMAIL = 'micro-python@googlegroups.com' +CPYTHON_DEVELS = 'CPython Developers' + +def parse_metadata(f): + data = {} + for l in f: + l = l.strip() + k, v = l.split("=", 1) + data[k] = v + return data + + +def write_setup(fname, substs): + with open(fname, "w") as f: + f.write(TEMPLATE % substs) + + +def main(): + for fname in glob.iglob("*/metadata.txt"): + print(fname) + with open(fname) as f: + data = parse_metadata(f) + + module = fname.split("/")[0] + if data["type"] == "dummy": + data["author"] = MICROPYTHON_DEVELS + data["author_email"] = MICROPYTHON_DEVELS_EMAIL + data["maintainer"] = MICROPYTHON_DEVELS + data["license"] = "MIT" + data["desc"] = "Dummy %s module for MicroPython" % module + data["long_desc"] = DUMMY_DESC + elif data["type"] == "cpython": + data["author"] = CPYTHON_DEVELS + data["maintainer"] = MICROPYTHON_DEVELS + data["license"] = "Python" + data["desc"] = "CPython %s module ported to MicroPython" % module + elif data["type"] == "micropython": + if "author" not in data: + data["author"] = MICROPYTHON_DEVELS + if "maintainer" not in data: + data["author"] = MICROPYTHON_DEVELS + else: + raise NotImplementedError + + data["name"] = module + write_setup(module + "/setup.py", data) + + +if __name__ == "__main__": + main()