Skip to content

Commit

Permalink
makes it easier to configure slugs/prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfrye committed Oct 26, 2021
1 parent de4cb1f commit e98b17a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
18 changes: 18 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,58 @@ elements=app,java

[EXAMPLE_SUBCONFIG]
# an example subconfig, all fields are mandatory but some can be empty
# see library.py for how these fields are used
dirname=name-of-directory-for-this
title=Human Readable Title for Sidebar
slug=prefix.for.markdown.filename.
elements=python,objects,that,you,want,to,document,commmaseparated
# see handle_additions in library.py for use of add-from and add-elements
add-from=submodule.toadd.elementsfrom
add-elements=elements,from,that,submodule
# see get_dunder_doc in library.py for use of module-doc-from
module-doc-from=other.module.with.dunderdoc

[SUBCONFIGS]
# add your subconfig's name here to document a new module
names=WANDB_CORE,WANDB_DATATYPES,WANDB_API,WANDB_INTEGRATIONS

[WANDB_CORE]
# main python client
dirname=python
title=Python Library
slug=wandb.
elements=Artifact,agent,config,controller,finish,init,log,save,summary,sweep,watch,__version__
add-from=wandb_sdk.wandb_run
add-elements=Run
module-doc-from=
#module-doc-from=self

[WANDB_DATATYPES]
# data types submodule, including media and tables
dirname=data-types
title=Data Types
slug=wandb.data\_types.
elements=Graph,Image,Plotly,Video,Audio,Table,Html,Object3D,Molecule,Histogram
add-from=data_types
add-elements=ImageMask,BoundingBoxes2D
module-doc-from=

[WANDB_API]
# public API subdmodule
dirname=public-api
title=Import & Export API
slug=wandb.apis.public.
elements=
add-from=apis.public
add-elements=Api,Projects,Project,Runs,Run,Sweep,Files,File,Artifact
module-doc-from=

[WANDB_INTEGRATIONS]
# integrations with other libraries that we host the code for
dirname=integrations
title=Integrations
# slugs for integrations are handled differently, see generate.py
slug=wandb.
elements=keras
# - keras
# - sklearn
Expand All @@ -77,4 +92,7 @@ elements=keras
# - torch
# - sagemaker
add-from=
#add-from=sdk.integration_utils.data_logging
add-elements=
#add-elements=ValidationDataLogger
module-doc-from=
21 changes: 16 additions & 5 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import cli
import library

import util


config = configparser.ConfigParser()
config.read("config.ini")
Expand All @@ -25,6 +27,12 @@
DIRNAMES_TO_TITLES = config["DIRNAMES_TO_TITLES"]
SKIPS = config["SKIPS"]["elements"].split(",")

subconfig_names = config["SUBCONFIGS"]["names"].split(",")

subconfigs = util.process_subconfigs(config, subconfig_names)

WANDB_CORE, WANDB_DATATYPES, WANDB_API, WANDB_INTEGRATIONS = subconfigs


def main(args):
commit_id = args.commit_id
Expand Down Expand Up @@ -142,14 +150,17 @@ def get_prefix(path):
if path == DIRNAME:
return [], ""
elif "data-types" in path:
return "wandb.data\_types." # noqa
return WANDB_DATATYPES["slug"]
elif "public-api" in path:
return "wandb.apis.public."
return WANDB_API["slug"]
elif "integrations" in path:
starter_slug = WANDB_INTEGRATIONS["slug"]
package_name = path.split("/")[-1]
return f"wandb.{package_name}."
if package_name == "integrations":
package_name = "sdk.integration_utils.data_logging"
return f"{starter_slug}{package_name}."
elif "python" in path:
return "wandb."
return WANDB_CORE["slug"]
elif "java" or "app" in path:
return ""
else:
Expand Down Expand Up @@ -275,7 +286,7 @@ def get_args():
"--template_file",
type=str,
default="_SUMMARY.md",
help="Template markdown file with {docugen} where filenames to be written. "
help="Template markdown file for table of contents. "
+ "Defaults to ./_SUMMARY.md",
)
parser.add_argument(
Expand Down
21 changes: 6 additions & 15 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from docugen import doc_controls
from docugen import generate

import util

config = configparser.ConfigParser()
config.read("config.ini")

Expand All @@ -16,15 +18,15 @@

subconfig_names = config["SUBCONFIGS"]["names"].split(",")

subconfigs = util.process_subconfigs(config, subconfig_names)

WANDB_CORE, WANDB_DATATYPES, WANDB_API, WANDB_INTEGRATIONS = subconfigs


def build(commit_id, code_url_prefix, output_dir):
"""Builds docs in stages: main library, then subcomponents."""
configure_doc_hiding()

subconfigs = process_subconfigs(config, subconfig_names)

WANDB_CORE, WANDB_DATATYPES, WANDB_API, WANDB_INTEGRATIONS = subconfigs

output_dir = os.path.join(output_dir, DIRNAME)
build_docs_from_config(WANDB_CORE, commit_id, code_url_prefix, output_dir)

Expand Down Expand Up @@ -113,14 +115,3 @@ def configure_doc_hiding():
deco = doc_controls.do_not_doc_in_subclasses
doc_controls.decorate_all_class_attributes(
decorator=deco, cls=keras.callbacks.Callback, skip=["__init__", "set_model", "set_params"])


def process_subconfigs(config, subconfig_names):
"""Applies some processing logic to config entries."""
subconfigs = []
for name in subconfig_names:
subconfig = dict(config[name])
subconfig["add-elements"] = subconfig["add-elements"].split(",")
subconfig["elements"] = subconfig["elements"].split(",")
subconfigs.append(subconfig)
return subconfigs
9 changes: 9 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def process_subconfigs(config, subconfig_names):
"""Applies some processing logic to config entries."""
subconfigs = []
for name in subconfig_names:
subconfig = dict(config[name])
subconfig["add-elements"] = subconfig["add-elements"].split(",")
subconfig["elements"] = subconfig["elements"].split(",")
subconfigs.append(subconfig)
return subconfigs

0 comments on commit e98b17a

Please sign in to comment.