2014-05-19 21:20:30 +00:00
|
|
|
#!/usr/bin/env python3
|
2014-06-06 20:22:44 +00:00
|
|
|
# MicroPython will pick up glob from the current dir otherwise.
|
|
|
|
import sys
|
|
|
|
sys.path.pop(0)
|
|
|
|
|
2014-05-12 00:52:22 +00:00
|
|
|
import glob
|
|
|
|
|
2014-06-06 20:22:44 +00:00
|
|
|
|
2014-05-12 00:52:22 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2014-06-07 02:03:19 +00:00
|
|
|
setup(name='micropython-%(dist_name)s',
|
2014-05-12 00:52:22 +00:00
|
|
|
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,
|
2014-05-12 17:50:55 +00:00
|
|
|
%(_what_)s=['%(top_name)s']%(_inst_req_)s)
|
2014-05-12 00:52:22 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
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."""
|
|
|
|
|
2014-05-12 17:40:27 +00:00
|
|
|
CPYTHON_DESC = """\
|
|
|
|
This is a module ported from CPython standard library to be compatible with
|
|
|
|
MicroPython interpreter. Usually, this means applying small patches for
|
|
|
|
features not supported (yet, or at all) in MicroPython. Sometimes, heavier
|
|
|
|
changes are required. Note that CPython modules are written with availability
|
|
|
|
of vast resources in mind, and may not work for MicroPython ports with
|
|
|
|
limited heap. If you are affected by such a case, please help reimplement
|
|
|
|
the module from scratch."""
|
|
|
|
|
2014-05-12 17:24:34 +00:00
|
|
|
MICROPYTHON_LIB_DESC = """\
|
|
|
|
This is a module reimplemented specifically for MicroPython standard library,
|
|
|
|
with efficient and lean design in mind. Note that this module is likely work
|
|
|
|
in progress and likely supports just a subset of CPython's corresponding
|
2014-05-12 17:40:27 +00:00
|
|
|
module. Please help with the development if you are interested in this
|
2014-05-12 17:24:34 +00:00
|
|
|
module."""
|
|
|
|
|
2015-01-02 19:17:11 +00:00
|
|
|
BACKPORT_DESC = """\
|
|
|
|
This is MicroPython compatibility module, allowing applications using
|
|
|
|
MicroPython-specific features to run on CPython.
|
|
|
|
"""
|
|
|
|
|
2014-05-12 00:52:22 +00:00
|
|
|
MICROPYTHON_DEVELS = 'MicroPython Developers'
|
|
|
|
MICROPYTHON_DEVELS_EMAIL = 'micro-python@googlegroups.com'
|
|
|
|
CPYTHON_DEVELS = 'CPython Developers'
|
2014-05-12 17:40:27 +00:00
|
|
|
CPYTHON_DEVELS_EMAIL = 'python-dev@python.org'
|
2014-05-12 00:52:22 +00:00
|
|
|
|
|
|
|
def parse_metadata(f):
|
|
|
|
data = {}
|
|
|
|
for l in f:
|
|
|
|
l = l.strip()
|
2014-06-02 23:05:44 +00:00
|
|
|
if l[0] == "#":
|
|
|
|
continue
|
2014-05-12 00:52:22 +00:00
|
|
|
k, v = l.split("=", 1)
|
2014-05-12 17:50:55 +00:00
|
|
|
data[k.strip()] = v.strip()
|
2014-05-12 00:52:22 +00:00
|
|
|
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)
|
|
|
|
|
2015-01-02 19:17:11 +00:00
|
|
|
dirname = fname.split("/")[0]
|
|
|
|
module = dirname
|
2014-05-12 14:14:12 +00:00
|
|
|
if data["type"] == "module":
|
|
|
|
data["_what_"] = "py_modules"
|
|
|
|
elif data["type"] == "package":
|
|
|
|
data["_what_"] = "packages"
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
2014-05-12 10:01:09 +00:00
|
|
|
if data["srctype"] == "dummy":
|
2014-05-12 00:52:22 +00:00
|
|
|
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
|
2014-05-12 10:01:09 +00:00
|
|
|
elif data["srctype"] == "cpython":
|
2014-05-12 00:52:22 +00:00
|
|
|
data["author"] = CPYTHON_DEVELS
|
2014-05-12 17:40:27 +00:00
|
|
|
data["author_email"] = CPYTHON_DEVELS_EMAIL
|
2014-05-12 00:52:22 +00:00
|
|
|
data["maintainer"] = MICROPYTHON_DEVELS
|
|
|
|
data["license"] = "Python"
|
|
|
|
data["desc"] = "CPython %s module ported to MicroPython" % module
|
2014-05-12 17:40:27 +00:00
|
|
|
data["long_desc"] = CPYTHON_DESC
|
2014-05-12 17:24:34 +00:00
|
|
|
elif data["srctype"] == "micropython-lib":
|
2014-05-12 00:52:22 +00:00
|
|
|
if "author" not in data:
|
|
|
|
data["author"] = MICROPYTHON_DEVELS
|
2014-05-12 17:24:34 +00:00
|
|
|
if "author_email" not in data:
|
|
|
|
data["author_email"] = MICROPYTHON_DEVELS_EMAIL
|
2014-05-12 00:52:22 +00:00
|
|
|
if "maintainer" not in data:
|
2014-05-12 17:24:34 +00:00
|
|
|
data["maintainer"] = MICROPYTHON_DEVELS
|
|
|
|
if "desc" not in data:
|
|
|
|
data["desc"] = "%s module for MicroPython" % module
|
|
|
|
if "long_desc" not in data:
|
|
|
|
data["long_desc"] = MICROPYTHON_LIB_DESC
|
|
|
|
if "license" not in data:
|
|
|
|
data["license"] = "MIT"
|
2015-01-02 19:17:11 +00:00
|
|
|
elif data["srctype"] == "cpython-backport":
|
|
|
|
assert module.startswith("cpython-")
|
|
|
|
module = module[len("cpython-"):]
|
|
|
|
data["author"] = MICROPYTHON_DEVELS
|
|
|
|
data["author_email"] = MICROPYTHON_DEVELS_EMAIL
|
|
|
|
data["maintainer"] = MICROPYTHON_DEVELS
|
|
|
|
data["license"] = "Python"
|
|
|
|
data["desc"] = "MicroPython module %s ported to CPython" % module
|
|
|
|
data["long_desc"] = BACKPORT_DESC
|
2014-05-12 00:52:22 +00:00
|
|
|
else:
|
2014-05-12 14:14:12 +00:00
|
|
|
raise ValueError
|
2014-05-12 00:52:22 +00:00
|
|
|
|
2014-06-21 01:05:20 +00:00
|
|
|
if "dist_name" not in data:
|
2015-01-02 19:17:11 +00:00
|
|
|
data["dist_name"] = dirname
|
2014-06-07 02:03:19 +00:00
|
|
|
if "name" not in data:
|
|
|
|
data["name"] = module
|
|
|
|
data["top_name"] = data["name"].split(".", 1)[0]
|
2014-05-12 17:50:55 +00:00
|
|
|
|
|
|
|
if "depends" in data:
|
|
|
|
deps = ["micropython-" + x.strip() for x in data["depends"].split(",")]
|
|
|
|
data["_inst_req_"] = ",\n install_requires=['" + "', '".join(deps) + "']"
|
|
|
|
else:
|
|
|
|
data["_inst_req_"] = ""
|
|
|
|
|
2015-01-02 19:17:11 +00:00
|
|
|
write_setup(dirname + "/setup.py", data)
|
2014-05-12 00:52:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|