Skip to content

Commit

Permalink
Jm/docs (#13)
Browse files Browse the repository at this point in the history
* Docs and supporting refactoring

* test updates

* add train section to docs

* docstring fix

* docs reqs

* install all reqs for docs build

* custom css for rtd....maybe?

* remove extra css import and use SSL for font download

* Version bump and README updates

* reset notebook

Co-authored-by: John Myers <john@gretel.ai>
  • Loading branch information
johntmyers and John Myers committed May 10, 2020
1 parent a92a026 commit b3a769e
Show file tree
Hide file tree
Showing 21 changed files with 347 additions and 96 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ dmypy.json
.idea/
venv*

checkpoints
checkpoints

docs/_build
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# gretel-synthetics
# Gretel Synthetics

![gretel-synthetics workflows](https://github.com/gretelai/gretel-synthetics/workflows/gretel-synthetics%20workflows/badge.svg)

[![Documentation Status](https://readthedocs.org/projects/gretel-synthetics/badge/?version=stable)](https://gretel-synthetics.readthedocs.io/en/stable/?badge=stable)


This code has been developed and tested on Python 3.7. Python 3.8 is currently unsupported.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.1
0.8.0
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 = .
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)
1 change: 1 addition & 0 deletions docs/_static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('https://fonts.googleapis.com/css?family=Inter');
5 changes: 5 additions & 0 deletions docs/api/config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Config
======

.. automodule:: gretel_synthetics.config
:members:
5 changes: 5 additions & 0 deletions docs/api/generate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Generate
========

.. automodule:: gretel_synthetics.generate
:members:
5 changes: 5 additions & 0 deletions docs/api/train.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Train
========

.. automodule:: gretel_synthetics.train
:members:
83 changes: 83 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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

import sphinx

sys.path.insert(0, os.path.abspath('../src'))


# -- Project information -----------------------------------------------------

project = 'Gretel Synthetics'
copyright = '2020, Gretel.ai'
author = 'Gretel.ai'


# -- 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.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon', 'm2r']

source_suffix = ['.rst', '.md']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# 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 = ['_build', 'Thumbs.db', '.DS_Store']


# -- 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']

html_theme_options = {
'sidebar_width': '250px',
'font_family': 'Inter'
}

html_css_files = [
'styles.css'
]


def monkeypatch(cls):
""" decorator to monkey-patch methods """
def decorator(f):
method = f.__name__
old_method = getattr(cls, method)
setattr(cls, method, lambda self, *args, **kwargs: f(old_method, self, *args, **kwargs))
return decorator

# workaround until https://github.com/miyakogi/m2r/pull/55 is merged
@monkeypatch(sphinx.registry.SphinxComponentRegistry)
def add_source_parser(_old_add_source_parser, self, *args, **kwargs):
# signature is (parser: Type[Parser], **kwargs), but m2r expects
# the removed (str, parser: Type[Parser], **kwargs).
if isinstance(args[0], str):
args = args[1:]
return _old_add_source_parser(self, *args, **kwargs)
Binary file added docs/img/gretel-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. image:: ./img/gretel-logo.png
:alt: Gretel Logo

.. mdinclude:: ../README.md

.. toctree::
:maxdepth: 2
:caption: Contents:


Modules
=======
.. toctree::
:maxdepth: 2

api/config.rst
api/train.rst
api/generate.rst


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
m2r
sphinx==3.0.3
-r ../requirements.txt
13 changes: 3 additions & 10 deletions examples/synthetic_records.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -110,15 +110,8 @@
" raise Exception('record not 6 parts')\n",
" \n",
"for line in generate_text(config, line_validator=validate_record):\n",
" print(line)\n"
" print(line)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -137,7 +130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.7.5"
}
},
"nbformat": 4,
Expand Down
15 changes: 8 additions & 7 deletions src/gretel_synthetics/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@dataclass
class BaseConfig:
class _BaseConfig:
"""Base dataclass that contains all of the main parameters for
training a model and generating data. This base config generally
should not be used directly. Instead you should use one of the
Expand Down Expand Up @@ -63,7 +63,7 @@ def _set_tokenizer(self): # pragma: no cover


@dataclass
class PathSettings:
class _PathSettings:
"""This dataclass stores path locations to
store tokenizer and training data locations. It should not
be used directly. It will be utilized by any configuration
Expand All @@ -75,7 +75,7 @@ class PathSettings:


@dataclass
class PathSettingsMixin:
class _PathSettingsMixin:
"""If a specific config needs to make use of
``PathSettings``, this dataclass will make an
attr of ``paths`` available and also bring in
Expand All @@ -85,7 +85,7 @@ class PathSettingsMixin:
This makes it possible to easily remove the path
settings when serializing the configuration.
"""
paths: PathSettings = field(default_factory=PathSettings)
paths: _PathSettings = field(default_factory=_PathSettings)

@property
def tokenizer_prefix(self):
Expand All @@ -101,15 +101,16 @@ def training_data(self):


@dataclass
class LocalConfig(BaseConfig, PathSettingsMixin):
class LocalConfig(_BaseConfig, _PathSettingsMixin):
"""This configuration will use the local file system
to store all models, training data, and checkpoints
Args:
checkpoint_dir: The local directory where all checkpoints should be stored
checkpoint_dir: The local directory where all checkpoints and additional support
files for training and generation will be stored.
input_data_path: A path to a file that will be used as initial training input.
This file will be opened, annotated, and then written out to a path
that is generated from the ``training_data` attribute.
that is generated based on the ``checkpoint_dir.``
"""
checkpoint_dir: str = None
input_data_path: str = None
Expand Down

0 comments on commit b3a769e

Please sign in to comment.