mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Autogenerate examples for platforms and frameworks
This commit is contained in:
2
docs
2
docs
Submodule docs updated: db967e2b10...0953dbb686
2
examples
2
examples
Submodule examples updated: 41f3396c58...ebff9ae73f
@ -396,10 +396,8 @@ def update_platform_docs():
|
|||||||
rst_path = join(platforms_dir, "%s.rst" % name)
|
rst_path = join(platforms_dir, "%s.rst" % name)
|
||||||
with open(rst_path, "w") as f:
|
with open(rst_path, "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
generate_platform(name,
|
generate_platform(
|
||||||
isfile(
|
name, isfile(join(platforms_dir, "%s_extra.rst" % name))))
|
||||||
join(platforms_dir,
|
|
||||||
"%s_extra.rst" % name))))
|
|
||||||
|
|
||||||
|
|
||||||
def generate_framework(type_, data, has_extra=False):
|
def generate_framework(type_, data, has_extra=False):
|
||||||
@ -518,10 +516,9 @@ def update_framework_docs():
|
|||||||
rst_path = join(frameworks_dir, "%s.rst" % name)
|
rst_path = join(frameworks_dir, "%s.rst" % name)
|
||||||
with open(rst_path, "w") as f:
|
with open(rst_path, "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
generate_framework(name, framework,
|
generate_framework(
|
||||||
isfile(
|
name, framework,
|
||||||
join(frameworks_dir,
|
isfile(join(frameworks_dir, "%s_extra.rst" % name))))
|
||||||
"%s_extra.rst" % name))))
|
|
||||||
|
|
||||||
|
|
||||||
def update_create_platform_doc():
|
def update_create_platform_doc():
|
||||||
@ -691,19 +688,78 @@ Boards
|
|||||||
"\n".join(lines))
|
"\n".join(lines))
|
||||||
|
|
||||||
|
|
||||||
def update_examples_readme():
|
def update_project_examples():
|
||||||
examples_dir = join(util.get_source_dir(), "..", "examples")
|
platform_readme_tpl = """
|
||||||
|
# {title}: development platform for [PlatformIO](https://platformio.org)
|
||||||
|
|
||||||
# Platforms
|
{description}
|
||||||
|
|
||||||
|
* [Home](https://platformio.org/platforms/{name}) (home page in PlatformIO Registry)
|
||||||
|
* [Documentation](http://docs.platformio.org/page/platforms/{name}.html) (advanced usage, packages, boards, frameworks, etc.)
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
|
||||||
|
{examples}
|
||||||
|
"""
|
||||||
|
framework_readme_tpl = """
|
||||||
|
# {title}: framework for [PlatformIO](https://platformio.org)
|
||||||
|
|
||||||
|
{description}
|
||||||
|
|
||||||
|
* [Home](https://platformio.org/frameworks/{name}) (home page in PlatformIO Registry)
|
||||||
|
* [Documentation](http://docs.platformio.org/page/frameworks/{name}.html)
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
|
||||||
|
{examples}
|
||||||
|
"""
|
||||||
|
|
||||||
|
project_examples_dir = join(util.get_source_dir(), "..", "examples")
|
||||||
|
framework_examples_md_lines = {}
|
||||||
embedded = []
|
embedded = []
|
||||||
desktop = []
|
desktop = []
|
||||||
|
|
||||||
for manifest in PLATFORM_MANIFESTS:
|
for manifest in PLATFORM_MANIFESTS:
|
||||||
p = PlatformFactory.newPlatform(manifest['name'])
|
p = PlatformFactory.newPlatform(manifest['name'])
|
||||||
url = campaign_url(
|
github_platform_url = (
|
||||||
"http://docs.platformio.org/en/latest/platforms/%s.html#examples" %
|
"https://github.com/platformio/platform-%s" % p.name)
|
||||||
p.name,
|
|
||||||
source="github",
|
# Platform README
|
||||||
medium="examples")
|
platform_examples_dir = join(p.get_dir(), "examples")
|
||||||
|
examples_md_lines = []
|
||||||
|
if isdir(platform_examples_dir):
|
||||||
|
for item in os.listdir(platform_examples_dir):
|
||||||
|
if not isdir(join(platform_examples_dir, item)):
|
||||||
|
continue
|
||||||
|
url = ("%s/tree/develop/examples/%s" % (github_platform_url,
|
||||||
|
item))
|
||||||
|
examples_md_lines.append("* [%s](%s)" % (item, url))
|
||||||
|
|
||||||
|
readme_dir = join(project_examples_dir, "platforms", p.name)
|
||||||
|
if not isdir(readme_dir):
|
||||||
|
os.makedirs(readme_dir)
|
||||||
|
with open(join(readme_dir, "README.md"), "w") as fp:
|
||||||
|
fp.write(
|
||||||
|
platform_readme_tpl.format(
|
||||||
|
name=p.name,
|
||||||
|
title=p.title,
|
||||||
|
description=p.description,
|
||||||
|
examples="\n".join(examples_md_lines)))
|
||||||
|
|
||||||
|
# Framework README
|
||||||
|
for framework in API_FRAMEWORKS:
|
||||||
|
if not is_compat_platform_and_framework(p.name, framework['name']):
|
||||||
|
continue
|
||||||
|
if framework['name'] not in framework_examples_md_lines:
|
||||||
|
framework_examples_md_lines[framework['name']] = []
|
||||||
|
lines = []
|
||||||
|
lines.append("- [%s](%s)" % (p.title, github_platform_url))
|
||||||
|
lines.extend(" %s" % l for l in examples_md_lines)
|
||||||
|
lines.append("")
|
||||||
|
framework_examples_md_lines[framework['name']].extend(lines)
|
||||||
|
|
||||||
|
# Root README
|
||||||
|
url = "https://github.com/platformio/platform-%s/tree/develop/examples" % p.name
|
||||||
line = "* [%s](%s)" % (p.title, url)
|
line = "* [%s](%s)" % (p.title, url)
|
||||||
if p.is_embedded():
|
if p.is_embedded():
|
||||||
embedded.append(line)
|
embedded.append(line)
|
||||||
@ -713,6 +769,18 @@ def update_examples_readme():
|
|||||||
# Frameworks
|
# Frameworks
|
||||||
frameworks = []
|
frameworks = []
|
||||||
for framework in API_FRAMEWORKS:
|
for framework in API_FRAMEWORKS:
|
||||||
|
readme_dir = join(project_examples_dir, "frameworks",
|
||||||
|
framework['name'])
|
||||||
|
if not isdir(readme_dir):
|
||||||
|
os.makedirs(readme_dir)
|
||||||
|
with open(join(readme_dir, "README.md"), "w") as fp:
|
||||||
|
fp.write(
|
||||||
|
framework_readme_tpl.format(
|
||||||
|
name=framework['name'],
|
||||||
|
title=framework['title'],
|
||||||
|
description=framework['description'],
|
||||||
|
examples="\n".join(
|
||||||
|
framework_examples_md_lines[framework['name']])))
|
||||||
url = campaign_url(
|
url = campaign_url(
|
||||||
"http://docs.platformio.org/en/latest/frameworks/%s.html#examples"
|
"http://docs.platformio.org/en/latest/frameworks/%s.html#examples"
|
||||||
% framework['name'],
|
% framework['name'],
|
||||||
@ -720,7 +788,7 @@ def update_examples_readme():
|
|||||||
medium="examples")
|
medium="examples")
|
||||||
frameworks.append("* [%s](%s)" % (framework['title'], url))
|
frameworks.append("* [%s](%s)" % (framework['title'], url))
|
||||||
|
|
||||||
with open(join(examples_dir, "README.md"), "w") as fp:
|
with open(join(project_examples_dir, "README.md"), "w") as fp:
|
||||||
fp.write("""# PlatformIO Project Examples
|
fp.write("""# PlatformIO Project Examples
|
||||||
|
|
||||||
- [Development platforms](#development-platforms):
|
- [Development platforms](#development-platforms):
|
||||||
@ -750,7 +818,7 @@ def main():
|
|||||||
update_framework_docs()
|
update_framework_docs()
|
||||||
update_embedded_boards()
|
update_embedded_boards()
|
||||||
update_debugging()
|
update_debugging()
|
||||||
update_examples_readme()
|
update_project_examples()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user