-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lingling Peng
committed
Mar 21, 2022
1 parent
7487d55
commit 47edb08
Showing
5 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
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,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = source | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
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,7 @@ | ||
============= | ||
CLI Reference | ||
============= | ||
|
||
.. click:: schematic.__main__:main | ||
:prog: schematic | ||
:nested: full |
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,69 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file only contains a selection of the most common options. For a full | ||
# list see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Path setup -------------------------------------------------------------- | ||
|
||
# If extensions (or modules to document with autodoc) are in another directory, | ||
# add these directories to sys.path here. If the directory is relative to the | ||
# documentation root, use os.path.abspath to make it absolute, like shown here. | ||
# | ||
import os | ||
import sys | ||
file_dir = os.path.dirname(__file__) | ||
sys.path.append(file_dir) | ||
from utils import _parse_toml | ||
import pathlib | ||
|
||
sys.path.insert(0, os.path.abspath("..")) | ||
|
||
|
||
# -- Project information ----------------------------------------------------- | ||
toml_file_path = pathlib.Path("../../pyproject.toml") | ||
|
||
toml_metadata = _parse_toml(toml_file_path) | ||
project = toml_metadata["name"] | ||
copyright = "2022, Sage Bionetworks" | ||
|
||
author = toml_metadata["authors"] | ||
|
||
# The full version, including alpha/beta/rc tags | ||
release = toml_metadata["version"] | ||
|
||
|
||
# -- General configuration --------------------------------------------------- | ||
|
||
# Add any Sphinx extension module names here, as strings. They can be | ||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
# ones. | ||
extensions = ["sphinx_click"] | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ["_templates"] | ||
|
||
# The language for content autogenerated by Sphinx. Refer to documentation | ||
# for a list of supported languages. | ||
# | ||
# This is also used if you do content translation via gettext catalogs. | ||
# Usually you set "language" from the command line for these cases. | ||
language = "English" | ||
|
||
# List of patterns, relative to source directory, that match files and | ||
# directories to ignore when looking for source files. | ||
# This pattern also affects html_static_path and html_extra_path. | ||
exclude_patterns = [] | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = "alabaster" | ||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
html_static_path = ["_static"] |
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,12 @@ | ||
.. Schematic documentation master file, created by | ||
sphinx-quickstart on Thu Feb 18 11:35:49 2021. | ||
You can adapt this file completely to your liking, but it should at least | ||
contain the root `toctree` directive. | ||
Welcome to Schematic's documentation! | ||
===================================== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
cli_reference |
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,60 @@ | ||
import re | ||
|
||
from typing import List, Dict | ||
from pathlib import Path | ||
|
||
import pkg_resources | ||
import toml | ||
|
||
|
||
def _extract_author_names(authors_list: List[str]) -> str: | ||
""" | ||
Parse out only names from 'name <email>' list. | ||
Args: | ||
authors_list: List of authors in 'name <email>' | ||
format. | ||
Returns: | ||
author_names_csv: String with only the 'name' part | ||
extracted from 'name <email>'. | ||
""" | ||
author_names = [] | ||
|
||
for author in authors_list: | ||
|
||
# extract name of each author by removing | ||
# <email> portion from each list item | ||
name = re.sub(r" \<[^)]*\>", "", author) | ||
author_names.append(name) | ||
|
||
# create comma separated string from list of authors | ||
author_names_csv = ", ".join(map(str, author_names)) | ||
return author_names_csv | ||
|
||
|
||
def _parse_toml(pyproject_path: Path) -> Dict[str, str]: | ||
""" | ||
Parse pyproject.toml file to extract attribute details. | ||
Args: | ||
pyproject_path: Path to pyproject.toml file being used | ||
by poetry. | ||
Returns: | ||
setup_metadata: Dictionary containing metadata like | ||
name, version and list of authors of the package. | ||
""" | ||
pyproject_text = pyproject_path.read_text() | ||
pyproject_data = toml.loads(pyproject_text) | ||
|
||
# read in [tool.poetry] section from pyproject.toml file | ||
poetry_data = pyproject_data["tool"]["poetry"] | ||
|
||
setup_metadata = { | ||
"name": poetry_data["name"], | ||
"version": poetry_data["version"], | ||
"authors": _extract_author_names(poetry_data["authors"]), | ||
} | ||
|
||
return setup_metadata |