Skip to content

Commit

Permalink
add source folder and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingling Peng committed Mar 21, 2022
1 parent 7487d55 commit 47edb08
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
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)
7 changes: 7 additions & 0 deletions docs/source/cli_reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=============
CLI Reference
=============

.. click:: schematic.__main__:main
:prog: schematic
:nested: full
69 changes: 69 additions & 0 deletions docs/source/conf.py
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"]
12 changes: 12 additions & 0 deletions docs/source/index.rst
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
60 changes: 60 additions & 0 deletions docs/source/utils.py
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

0 comments on commit 47edb08

Please sign in to comment.