Skip to content

Commit f6d769d

Browse files
committed
feat: Add documentation generation support
1 parent a27e98a commit f6d769d

File tree

11 files changed

+283
-5
lines changed

11 files changed

+283
-5
lines changed

.readthedocs.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
3+
build:
4+
os: "ubuntu-22.04"
5+
tools:
6+
python: "3.10"
7+
jobs:
8+
post_create_environment:
9+
- pip install poetry
10+
- poetry config virtualenvs.create false
11+
post_install:
12+
- poetry install --with docs
13+
14+
sphinx:
15+
builder: html
16+
configuration: docs/conf.py
17+
fail_on_warning: true

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
PYTEST_FLAGS=-W error::SyntaxWarning
2+
3+
SPHINXOPTS = -W --keep-going
4+
SPHINXBUILD = sphinx-build
5+
SPHINXPROJ = launchdarkly-openfeature-server
6+
SOURCEDIR = docs
7+
BUILDDIR = $(SOURCEDIR)/build
8+
19
.PHONY: help
210
help: #! Show this help message
311
@echo 'Usage: make [target] ... '
@@ -22,3 +30,13 @@ test: install
2230
lint: #! Run type analysis and linting checks
2331
lint: install
2432
@poetry run mypy ld_openfeature tests
33+
34+
#
35+
# Documentation generation
36+
#
37+
38+
.PHONY: docs
39+
docs: #! Generate sphinx-based documentation
40+
@poetry install --with docs
41+
@cd docs
42+
@poetry run $(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# How the Python SDK documentation works
2+
3+
The generated API documentation is built with [Sphinx](http://www.sphinx-doc.org/en/master/), and is hosted on [Read the Docs](https://readthedocs.org/).
4+
5+
It uses the following:
6+
7+
* Docstrings within the code. Docstrings can use any of the markup supported by Sphinx.
8+
* The `.rst` files in the `docs` directory. These provide the overall page structure.
9+
* The `conf.py` file containing Sphinx settings.
10+
11+
## What to document
12+
13+
Every public class, method, and module should have a docstring. Classes and methods with no docstring will not be included in the API docs.
14+
15+
"Public" here means things that we want third-party developers to use. The SDK also contains many modules and classes that are not actually private (i.e. they aren't prefixed with `_`), but are for internal use only and aren't supported for any other use (we would like to reduce the amount of these in future).
16+
17+
To add an undocumented class or method in an existing module to the docs, just give it a docstring.
18+
19+
To add a new module to the docs, give it a docstring and then add a link to it in the appropriate `api-*.rst` file, in the same format as the existing links.
20+
21+
## Undocumented things
22+
23+
Modules that contain only implementation details are omitted from the docs by simply not including links to them in the `.rst` files.
24+
25+
Internal classes in a documented module will be omitted from the docs if they do not have any docstrings, unless they inherit from another class that has docstrings. In the latter case, the way to omit them from the docs is to edit the `.rst` file that contains the link to that module, and add a `:members:` directive under the module that specifically lists all the classes that _should_ be shown.
26+
27+
## Testing
28+
29+
In the `docs` directory, run `make html` to build all the docs. Then view `docs/build/html/index.html`.

docs/_static/.gitkeep

Whitespace-only changes.

docs/_templates/.gitkeep

Whitespace-only changes.

docs/api-main.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Core API
2+
========
3+
4+
ld_openfeature module
5+
---------------------
6+
7+
.. automodule:: ld_openfeature
8+
:members: LaunchDarklyProvider

docs/conf.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# -*- coding: utf-8 -*-
2+
# type: ignore
3+
# Configuration file for the Sphinx documentation builder.
4+
#
5+
# This file does only contain a selection of the most common options. For a
6+
# full list see the documentation:
7+
# http://www.sphinx-doc.org/en/master/config
8+
9+
# -- Path setup --------------------------------------------------------------
10+
11+
# If extensions (or modules to document with autodoc) are in another directory,
12+
# add these directories to sys.path here. If the directory is relative to the
13+
# documentation root, use os.path.abspath to make it absolute, like shown here.
14+
#
15+
# import os
16+
# import sys
17+
# sys.path.insert(0, os.path.abspath('.'))
18+
19+
import os
20+
import sys
21+
22+
sys.path.insert(0, os.path.abspath('..'))
23+
24+
import ld_openfeature
25+
26+
# -- Project information -----------------------------------------------------
27+
28+
project = u'launchdarkly-openfeature-server'
29+
copyright = u'2024, LaunchDarkly'
30+
author = u'LaunchDarkly'
31+
32+
# The short X.Y version.
33+
version = '0.1.0' # x-release-please-version
34+
# The full version, including alpha/beta/rc tags.
35+
release = '0.1.0' # x-release-please-version
36+
37+
38+
# -- General configuration ---------------------------------------------------
39+
40+
# If your documentation needs a minimal Sphinx version, state it here.
41+
#
42+
# needs_sphinx = '1.0'
43+
44+
# Add any Sphinx extension module names here, as strings. They can be
45+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
46+
# ones.
47+
extensions = [
48+
'sphinx.ext.autodoc',
49+
'sphinx.ext.coverage',
50+
'sphinx.ext.viewcode',
51+
]
52+
53+
# Add any paths that contain templates here, relative to this directory.
54+
templates_path = ['_templates']
55+
56+
# The suffix(es) of source filenames.
57+
# You can specify multiple suffix as a list of string:
58+
#
59+
# source_suffix = ['.rst', '.md']
60+
source_suffix = '.rst'
61+
62+
# The master toctree document.
63+
master_doc = 'index'
64+
65+
# The language for content autogenerated by Sphinx. Refer to documentation
66+
# for a list of supported languages.
67+
#
68+
# This is also used if you do content translation via gettext catalogs.
69+
# Usually you set "language" from the command line for these cases.
70+
language = 'en'
71+
72+
# List of patterns, relative to source directory, that match files and
73+
# directories to ignore when looking for source files.
74+
# This pattern also affects html_static_path and html_extra_path .
75+
exclude_patterns = ['build']
76+
77+
# The name of the Pygments (syntax highlighting) style to use.
78+
pygments_style = 'sphinx'
79+
80+
81+
# -- Options for HTML output -------------------------------------------------
82+
83+
# The theme to use for HTML and HTML Help pages. See the documentation for
84+
# a list of builtin themes.
85+
#
86+
#html_theme = 'sphinx_rtd_theme' # ReadTheDocs will set this
87+
88+
# Theme options are theme-specific and customize the look and feel of a theme
89+
# further. For a list of options available for each theme, see the
90+
# documentation.
91+
#
92+
# html_theme_options = {}
93+
94+
# Add any paths that contain custom static files (such as style sheets) here,
95+
# relative to this directory. They are copied after the builtin static files,
96+
# so a file named "default.css" will overwrite the builtin "default.css".
97+
html_static_path = ['_static']
98+
99+
# Custom sidebar templates, must be a dictionary that maps document names
100+
# to template names.
101+
#
102+
# The default sidebars (for documents that don't match any pattern) are
103+
# defined by theme itself. Builtin themes are using these templates by
104+
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
105+
# 'searchbox.html']``.
106+
#
107+
# html_sidebars = {}
108+
109+
110+
# -- Options for HTMLHelp output ---------------------------------------------
111+
112+
# Output file base name for HTML help builder.
113+
htmlhelp_basename = 'launchdarkly-openfeature-server-doc'
114+
115+
116+
# -- Options for LaTeX output ------------------------------------------------
117+
118+
latex_elements = {
119+
# The paper size ('letterpaper' or 'a4paper').
120+
#
121+
# 'papersize': 'letterpaper',
122+
123+
# The font size ('10pt', '11pt' or '12pt').
124+
#
125+
# 'pointsize': '10pt',
126+
127+
# Additional stuff for the LaTeX preamble.
128+
#
129+
# 'preamble': '',
130+
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
134+
}
135+
136+
# Grouping the document tree into LaTeX files. List of tuples
137+
# (source start file, target name, title,
138+
# author, documentclass [howto, manual, or own class]).
139+
latex_documents = [
140+
(master_doc, 'launchdarkly-openfeature-server.tex', u'launchdarkly-openfeature-server Documentation',
141+
u'LaunchDarkly', 'manual'),
142+
]
143+
144+
145+
# -- Options for manual page output ------------------------------------------
146+
147+
# One entry per manual page. List of tuples
148+
# (source start file, name, description, authors, manual section).
149+
man_pages = [
150+
(master_doc, 'launchdarkly-openfeature-server', u'launchdarkly-openfeature-server Documentation',
151+
[author], 1)
152+
]
153+
154+
155+
# -- Options for Texinfo output ----------------------------------------------
156+
157+
# Grouping the document tree into Texinfo files. List of tuples
158+
# (source start file, target name, title, author,
159+
# dir menu entry, description, category)
160+
texinfo_documents = [
161+
(master_doc, 'launchdarkly-openfeature-server', u'launchdarkly-openfeature-server Documentation',
162+
author, 'launchdarkly-openfeature-server', 'One line description of project.',
163+
'Miscellaneous'),
164+
]
165+
166+
167+
# -- Extension configuration -------------------------------------------------
168+
169+
autodoc_default_options = {
170+
'undoc-members': False
171+
}

docs/index.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. launchdarkly-openfeature-server documentation master file, created by
2+
sphinx-quickstart on Mon Feb 4 13:16:49 2019.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
LaunchDarkly OpenFeature provider for the Server-Side SDK for Python
7+
====================================================================
8+
9+
This is the API reference for the `LaunchDarkly <https://launchdarkly.com/>`_ OpenFeature Provider for the Server-Side SDK for Python
10+
11+
The latest version of the SDK can be found on `PyPI <https://pypi.org/project/launchdarkly-openfeature-server/>`_, and the source code is on `GitHub <https://github.com/launchdarkly/openfeature-python-server>`_.
12+
13+
For more information, see LaunchDarkly's `Quickstart <https://docs.launchdarkly.com/home>`_ and `SDK Reference Guide <https://docs.launchdarkly.com/sdk/server-side/python>`_.
14+
15+
Any types, functions, or constants that are not specifically described in this API reference should be considered implementation details that are not supported for external use; LaunchDarkly reserves the right to change them at any time and application code should not rely on them.
16+
17+
.. toctree::
18+
:maxdepth: 2
19+
:caption: Contents:
20+
21+
api-main

ld_openfeature/impl/context_converter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __build_multi_context(self, context: EvaluationContext) -> Context:
6666
continue
6767

6868
key = attributes.get('key')
69-
targeting_key = attributes.get('targeting_key')
69+
targeting_key = attributes.get('targetingKey')
7070

7171
if targeting_key is not None and not isinstance(targeting_key, str):
7272
continue
@@ -83,8 +83,7 @@ def __build_single_context(self, attributes: Dict, kind: str, key: str) -> Conte
8383
builder.kind(kind)
8484

8585
for k, v in attributes.items():
86-
# TODO: In PHP this was camel case. Is that the case for python? Check the docs.
87-
if k == 'key' or k == 'targeting_key':
86+
if k == 'key' or k == 'targetingKey':
8887
continue
8988

9089
if k == 'name' and isinstance(v, str):

pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ mypy = "==1.8.0"
4040
isort = "^5.13.2"
4141

4242

43+
[tool.poetry.group.docs]
44+
optional = true
45+
46+
[tool.poetry.group.docs.dependencies]
47+
sphinx = "^6.0.0"
48+
sphinx-rtd-theme = ">=1.3,<3.0"
49+
certifi = ">=2018.4.16"
50+
expiringdict = ">=1.1.4"
51+
pyrfc3339 = ">=1.0"
52+
jsonpickle = ">1.4.1"
53+
semver = ">=2.7.9"
54+
urllib3 = ">=1.22.0"
55+
jinja2 = "3.1.3"
56+
57+
4358
[tool.mypy]
4459
python_version = "3.8"
4560
install_types = true

0 commit comments

Comments
 (0)