-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from viash-io/auto_generate_reference_index
Auto generate reference index
- Loading branch information
Showing
7 changed files
with
237 additions
and
614 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
_src/automation/generate_reference_main_index_page/config.vsh.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
functionality: | ||
name: generate_reference_main_index_page | ||
description: | | ||
The script reads the viash cli & config schema json schemas and assembles it to the main reference page listing | ||
arguments: | ||
- name: "--cli" | ||
type: file | ||
direction: input | ||
description: The cli json file to use as input | ||
required: true | ||
must_exist: true | ||
- name: "--config" | ||
type: file | ||
direction: input | ||
description: The config json file to use as input | ||
required: true | ||
must_exist: true | ||
- name: "--output" | ||
type: file | ||
alternatives: "-o" | ||
direction: output | ||
default: 'reference/reference.yml' | ||
description: Path to use to store the index page listing | ||
resources: | ||
- type: python_script | ||
path: script.py | ||
- type: file | ||
path: ../config_pages_settings.yaml | ||
platforms: | ||
- type: native |
100 changes: 100 additions & 0 deletions
100
_src/automation/generate_reference_main_index_page/script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import json, re, yaml | ||
from pathlib import Path | ||
|
||
## VIASH START | ||
par = { | ||
'cli': 'reference/cli_schema_export.json', | ||
'config': 'reference/config_schema_export.json', | ||
'output': 'reference/cli' | ||
} | ||
meta = { | ||
"resources_dir": "_src/automation/generate_reference_cli_pages" | ||
} | ||
## VIASH END | ||
|
||
output = Path(par["output"]) | ||
# keyword_regex = r"\@\[(.*?)\]\((.*?)\)" | ||
|
||
config_file = Path(meta['resources_dir'], 'config_pages_settings.yaml') | ||
|
||
with open(config_file, 'r') as infile: | ||
config_pages_settings = yaml.safe_load(infile) | ||
|
||
ref_dict = {} | ||
def add_entry(topic, name, href): | ||
# print(f'topic: {topic}, name: {name}, href: {href} ') | ||
if topic in ref_dict: | ||
ref_dict[topic].append({ 'text': name, 'href': href + '.html' }) | ||
else: | ||
ref_dict[topic] = [{ 'text': name, 'href': href + '.html' }] | ||
|
||
def generate_reference_page(): | ||
""" Load the generated JSON files and create reference entries. """ | ||
|
||
# List the CLI commands | ||
with open(par['cli'], 'r') as infile: | ||
cli_json = json.load(infile) | ||
|
||
for entry in cli_json: | ||
if "bannerCommand" in entry: | ||
name = f'Viash {entry["name"]}'.title() | ||
filename = entry["name"] | ||
add_entry("Viash CLI Commands", name, f'/reference/cli/{filename}') | ||
else: | ||
for subcommand in entry['subcommands']: | ||
name = f'Viash {entry["name"]} {subcommand["name"]}'.title() | ||
filename = f'{entry["name"]}_{subcommand["name"]}' | ||
add_entry("Viash CLI Commands", name, f'/reference/cli/{filename}') | ||
|
||
# Add some static pages :( | ||
add_entry("Viash Config", "Config Overview", "/reference/config/index") | ||
add_entry("Viash Config", "Functionality", "/reference/config/functionality/index") | ||
add_entry("Viash Config", "Platforms", "/reference/config/platforms/index") | ||
add_entry("Miscellaneous", "Project Config", "/reference/project/index") | ||
add_entry("Miscellaneous", "Environment Variables", "/reference/config/environmentVariables") | ||
add_entry("Miscellaneous", "Config Mods", "/reference/config_mods/index") | ||
add_entry("Miscellaneous", "Viash Code Block", "/reference/viash_code_block/index") | ||
|
||
|
||
# Add config pages highlighting field groups | ||
with open(par['config'], 'r') as infile: | ||
config_json = json.load(infile) | ||
|
||
# Regex filters. Platforms are not simply contained in a main folder, grab index files. For other matches, skip the index files. | ||
to_document = { | ||
'\./platforms/\w*/index': "Platforms", | ||
'\./functionality/arguments/(?!index$)\w*': "Argument Types", | ||
'\./functionality/resources/(?!index$)\w*': "Resource Types", | ||
'\./platforms/docker/setup/(?!index$)\w*': "Docker Setup Requirements" | ||
} | ||
|
||
for entry in config_json: | ||
this_parameter = {} | ||
# Get the __this__ parameter | ||
for d in entry: | ||
if d['name'] == '__this__': | ||
this_parameter = d | ||
break | ||
|
||
topic = this_parameter['type'] | ||
title = re.sub(r"(\w)([A-Z])", r"\1 \2", topic).title() \ | ||
.replace("Java Script", "JavaScript") \ | ||
.replace("C Sharp", "C#") \ | ||
.replace(" Argument", "") | ||
filename = config_pages_settings['structure'][topic] | ||
for key, value in to_document.items(): | ||
if re.match(key, filename): | ||
add_entry(value, title, f'/reference/config{filename.strip(".")}') | ||
break | ||
|
||
# Minor final touch on the output and save to file | ||
output = [] | ||
for key, value in ref_dict.items(): | ||
output.append({ 'title': key, 'links': sorted(value, key=lambda k: k['text'] ) }) | ||
|
||
with open(par['output'], 'w') as outfile: | ||
outfile.write(yaml.safe_dump(output)) | ||
|
||
if __name__ == "__main__": | ||
generate_reference_page() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.