Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 35bde54

Browse files
samaidshssf
authored andcommitted
Revised sections of the SDC documentation; getting rid of autodoc/autosummary/autolabel; scripts to traverse module classes and parse docstrings (#317)
1 parent 59f707e commit 35bde54

File tree

8 files changed

+526
-255
lines changed

8 files changed

+526
-255
lines changed

docs/source/apireference.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.. _apireference:
22

3-
API Reference: Supported Pandas APIs
4-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
API Reference
4+
~~~~~~~~~~~~~
55

6-
This page gives an overview of all Pandas APIs supported currently by Intel® SDC
6+
This page gives an overview of all Pandas APIs supported currently by Intel® Scalable Dataframe Compiler
77

8-
.. toctree::
9-
:maxdepth: 2
10-
11-
series
8+
.. autosummary::
9+
:toctree: _autosummary
10+
11+
pandas.Series

docs/source/compilation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
.. _compilation:
22
.. include:: ./ext_links.txt
33

4-
Compiling With Intel® SDC
5-
=========================
4+
Compiling With Intel® Scalable Dataframe Compiler
5+
=================================================
66

77
.. todo::
88
Basic compilation controls. What can be compiled and what cannot. How to work around compilation issues.
99
References to relevant discussion in `Numba*`_. Specifics for Series, Dataframes, and other hpat specific
1010
data structures
1111

1212
What if I get a compilation error
13-
=================================
13+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1414

1515
There are a few reasons why Intel SDC cannot compile your code out-of-the-box.
1616

docs/source/conf.py

Lines changed: 11 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151

5252
if not sdc_doc_no_api_ref:
5353
try:
54-
import sdc # TODO: Rename hpat module name to sdc
54+
import sdc
5555
except ImportError:
56-
print('IMPORT EXCEPTION: Cannot import sdc. ')
56+
print('IMPORT EXCEPTION: Cannot import SDC. ')
5757
print('Documentation generator for API Reference for a given module expects that module '
58-
'to be installed. Use conda/pip install hpat to install it prior to using API Reference generation')
58+
'to be installed. Use conda/pip install SDC to install it prior to using API Reference generation')
5959
print('If you want to disable API Reference generation, set the environment variable SDC_DOC_NO_API_REF=1')
6060

6161
raise
@@ -77,15 +77,15 @@
7777
# ones.
7878
extensions = [
7979
'sphinx.ext.todo',
80-
'sphinx.ext.autosummary',
80+
# 'sphinx.ext.autosummary',
8181
'sphinx.ext.intersphinx',
82-
'sphinx.ext.autodoc',
82+
# 'sphinx.ext.autodoc',
8383
'sphinx.ext.extlinks',
8484
'sphinx.ext.githubpages',
8585
'sphinx.ext.napoleon',
86-
'sphinx.ext.autosectionlabel',
87-
'sphinx.ext.graphviz',
88-
'sphinx.ext.coverage'
86+
# 'sphinx.ext.autosectionlabel',
87+
# 'sphinx.ext.graphviz',
88+
# 'sphinx.ext.coverage'
8989
]
9090

9191

@@ -149,94 +149,15 @@
149149

150150

151151
# -- Auto-section label configuration -----------------------------------------------
152-
autosectionlabel_prefix_document = True
152+
#autosectionlabel_prefix_document = True
153153

154154

155155
# -- Autodoc configuration ----------------------------------------------------------
156-
autodoc_docstring_signature = True
156+
#autodoc_docstring_signature = True
157157

158158

159159
# -- Auto-summary configuration -----------------------------------------------------
160-
autosummary_generate = True
160+
#autosummary_generate = True
161161

162162
# -- Prepend module name to an object name or not -----------------------------------
163163
add_module_names = False
164-
165-
166-
"""
167-
import API_Doc
168-
169-
# List of patterns, relative to source directory, that match files and
170-
# directories to ignore when looking for source files.
171-
# This patterns also effect to html_static_path and html_extra_path
172-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
173-
174-
# -- Options for HTMLHelp output ------------------------------------------
175-
176-
# Output file base name for HTML help builder.
177-
htmlhelp_basename = 'HPATdoc'
178-
179-
# -- Options for LaTeX output ---------------------------------------------
180-
181-
latex_engine = 'pdflatex'
182-
latex_elements = {
183-
# The paper size ('letterpaper' or 'a4paper').
184-
#
185-
# 'papersize': 'letterpaper',
186-
187-
# The font size ('10pt', '11pt' or '12pt').
188-
#
189-
# 'pointsize': '10pt',
190-
191-
# Additional stuff for the LaTeX preamble.
192-
#
193-
# 'preamble': '',
194-
195-
# Latex figure (float) alignment
196-
#
197-
# 'figure_align': 'htbp',
198-
}
199-
200-
# Grouping the document tree into LaTeX files. List of tuples
201-
# (source start file, target name, title,
202-
# author, documentclass [howto, manual, or own class]).
203-
latex_documents = [
204-
(master_doc, 'HPAT.tex', 'HPAT Documentation',
205-
'Intel', 'manual'),
206-
]
207-
208-
pdf_documents = [
209-
('index', u'HPATDocumentation', u'HPAT Documentation', u'Rujal Desai'),
210-
]
211-
212-
# -- Options for manual page output ---------------------------------------
213-
214-
# One entry per manual page. List of tuples
215-
# (source start file, name, description, authors, manual section).
216-
man_pages = [
217-
(master_doc, 'sdc', 'HPAT Documentation',
218-
[author], 1)
219-
]
220-
221-
222-
# -- Options for Texinfo output -------------------------------------------
223-
224-
# Grouping the document tree into Texinfo files. List of tuples
225-
# (source start file, target name, title, author,
226-
# dir menu entry, description, category)
227-
texinfo_documents = [
228-
(master_doc, 'HPAT', 'HPAT Documentation',
229-
author, 'HPAT', 'One line description of project.',
230-
'Miscellaneous'),
231-
]
232-
233-
numfig = True
234-
235-
# configuration for intersphinx
236-
intersphinx_mapping = {
237-
'python': ('https://docs.python.org/', None),
238-
'numba': ('https://numba.pydata.org/numba-doc/dev', None),
239-
'numpy': ('http://docs.scipy.org/doc/numpy', None),
240-
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
241-
}
242-
"""

docs/source/info.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Copyright 2015: Mirantis Inc.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import re
17+
import sys
18+
19+
PARAM_OR_RETURNS_REGEX = re.compile(":(?:param|returns)")
20+
RETURNS_REGEX = re.compile(":returns: (?P<doc>.*)", re.S)
21+
PARAM_REGEX = re.compile(":param (?P<name>[\*\w]+): (?P<doc>.*?)"
22+
"(?:(?=:param)|(?=:return)|(?=:raises)|\Z)", re.S)
23+
24+
def trim(docstring):
25+
"""trim function from PEP-257"""
26+
if not docstring:
27+
return ""
28+
# Convert tabs to spaces (following the normal Python rules)
29+
# and split into a list of lines:
30+
lines = docstring.expandtabs().splitlines()
31+
# Determine minimum indentation (first line doesn't count):
32+
indent = sys.maxsize
33+
for line in lines[1:]:
34+
stripped = line.lstrip()
35+
if stripped:
36+
indent = min(indent, len(line) - len(stripped))
37+
# Remove indentation (first line is special):
38+
trimmed = [lines[0].strip()]
39+
if indent < sys.maxsize:
40+
for line in lines[1:]:
41+
trimmed.append(line[indent:].rstrip())
42+
# Strip off trailing and leading blank lines:
43+
while trimmed and not trimmed[-1]:
44+
trimmed.pop()
45+
while trimmed and not trimmed[0]:
46+
trimmed.pop(0)
47+
48+
# Current code/unittests expects a line return at
49+
# end of multiline docstrings
50+
# workaround expected behavior from unittests
51+
if "\n" in docstring:
52+
trimmed.append("")
53+
54+
# Return a single string:
55+
return "\n".join(trimmed)
56+
57+
58+
def reindent(string):
59+
return "\n".join(l.strip() for l in string.strip().split("\n"))
60+
61+
62+
def parse_docstring(docstring):
63+
"""Parse the docstring into its components.
64+
:returns: a dictionary of form
65+
{
66+
"short_description": ...,
67+
"long_description": ...,
68+
"params": [{"name": ..., "doc": ...}, ...],
69+
"returns": ...
70+
}
71+
"""
72+
73+
short_description = long_description = returns = ""
74+
params = []
75+
76+
if docstring:
77+
docstring = trim(docstring)
78+
79+
lines = docstring.split("\n", 1)
80+
short_description = lines[0]
81+
82+
if len(lines) > 1:
83+
long_description = lines[1].strip()
84+
85+
params_returns_desc = None
86+
87+
match = PARAM_OR_RETURNS_REGEX.search(long_description)
88+
if match:
89+
long_desc_end = match.start()
90+
params_returns_desc = long_description[long_desc_end:].strip()
91+
long_description = long_description[:long_desc_end].rstrip()
92+
93+
if params_returns_desc:
94+
params = [
95+
{"name": name, "doc": trim(doc)}
96+
for name, doc in PARAM_REGEX.findall(params_returns_desc)
97+
]
98+
99+
match = RETURNS_REGEX.search(params_returns_desc)
100+
if match:
101+
returns = reindent(match.group("doc"))
102+
103+
return {
104+
"short_description": short_description,
105+
"long_description": long_description,
106+
"params": params,
107+
"returns": returns
108+
}
109+
110+
111+
class InfoMixin(object):
112+
113+
@classmethod
114+
def _get_doc(cls):
115+
"""Return documentary of class
116+
By default it returns docstring of class, but it can be overridden
117+
for example for cases like merging own docstring with parent
118+
"""
119+
return cls.__doc__
120+
121+
@classmethod
122+
def get_info(cls):
123+
doc = parse_docstring(cls._get_doc())
124+
125+
return {
126+
"name": cls.get_name(),
127+
"platform": cls.get_platform(),
128+
"platform": cls.get_platform(),
129+
"module": cls.__module__,
130+
"title": doc["short_description"],
131+
"description": doc["long_description"],
132+
"parameters": doc["params"],
133+
"schema": getattr(cls, "CONFIG_SCHEMA", None),
134+
"returns": doc["returns"]
135+
}

0 commit comments

Comments
 (0)