From 5fe5acff15412c4b20d9654f9ec9d5d5c55ccac0 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 15 Aug 2016 20:51:24 +0100 Subject: [PATCH] Start to document API --- CMakeLists.txt | 5 +- README.md | 19 +-- docs/README.md | 14 ++ docs/conf.py | 351 +++++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 15 ++ docs/reference.rst | 40 ++++++ docs/usage.rst | 62 ++++++++ src/main.cpp | 36 ++--- 8 files changed, 507 insertions(+), 35 deletions(-) create mode 100644 docs/README.md create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/reference.rst create mode 100644 docs/usage.rst diff --git a/CMakeLists.txt b/CMakeLists.txt index 434d546..cd435da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,11 +102,12 @@ add_test(NAME test ######################################## install(TARGETS loot_api - DESTINATION bin + DESTINATION "." CONFIGURATIONS Release) install(FILES "${LOOT_API_EXTRACTED_PATH}/${LOOT_API_SHARED_LIBRARY}" - DESTINATION bin + "${CMAKE_SOURCE_DIR}/docs/README.md" + DESTINATION "." CONFIGURATIONS Release) ######################################## diff --git a/README.md b/README.md index 1750472..c3e80e8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ LOOT API Python Module ======================= [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/loot/loot-api-python?branch=master&svg=true)](https://ci.appveyor.com/project/WrinklyNinja/loot-api-python) +[![Documentation Status](https://readthedocs.org/projects/loot-api-python/badge/)](http://loot-api-python.readthedocs.io/) A Python module that wraps the LOOT API, generated by [pybind11](https://github.com/pybind/pybind11). @@ -17,24 +18,12 @@ loot_api_python--win32.7z For example `loot_api_python-94de368-win32.7z` was built using the revision with shortened commit ID `94de368`. -The build archives contain a `loot_api.pyd` and a `loot_api.dll`: see the usage section below on how to use them. +## Documentation + +The documentation can be found online at [Read The Docs](http://loot-api-python.readthedocs.org/). ## Build Instructions The module's build system uses [CMake](https://cmake.org/) and requires [Python](https://www.python.org) (tested with 2.7). Make sure they're installed, then run CMake, and build the generated solution file. Only Windows support has been tested, though Linux builds should also be possible. - -## Usage - -Copy the `loot_api.pyd` file that is built and the `loot_api.dll` file in the same directory to wherever you wish to import the module from, then: - -``` ->>> import loot_api ->>> loot_api.is_compatible(0,9,0) -True -``` - -The DLL requires the [Visual C++ 2015 Redistributable (x86)](https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe) to be installed. - -**Note:** The module is currently built against revision [e40624c](https://github.com/loot/loot/tree/e40624cf7498f69b9393a02572a1eaf31065df44) of the API, which is post-0.9.2 and pre-0.10.0, but uses the v0.10 metadata syntax (as specified at that revision, in case there are further changes before the v0.10 release). diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..de0f913 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,14 @@ +LOOT API Python Wrapper +======================= + +This archive contains a build of the LOOT API Python wrapper module and its corresponding 32-bit Windows build of the LOOT API. + +The DLL requires the [MSVC 2015 x86 redistributable](https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe) +to be installed. + +See the [online documentation](http://loot-api-python.readthedocs.org/) for more information. +The library source code is available [on GitHub](https://github.com/loot/loot-api-python). + +--- + +Copyright (C) 2013-2016 WrinklyNinja diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..10d25c2 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,351 @@ +# -*- coding: utf-8 -*- +# +# LOOT API Python Module documentation build configuration file, created by +# sphinx-quickstart on Mon Aug 15 07:11:32 2016. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# 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 +# sys.path.insert(0, os.path.abspath('.')) + +import os +import sys +sys.path.insert(0, os.path.abspath('../build/Release')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# 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.intersphinx', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +# +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'LOOT API Python Module' +copyright = u'2016, WrinklyNinja' +author = u'WrinklyNinja' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'latest' +# The full version, including alpha/beta/rc tags. +release = u'latest' + +# 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 = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# +# today = '' +# +# Else, today_fmt is used as the format for a strftime call. +# +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- 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 = 'sphinx_rtd_theme' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. +# " v documentation" by default. +# +# html_title = u'LOOT API Python Module v;atest' + +# A shorter title for the navigation bar. Default is the same as html_title. +# +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# +# html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# +# html_favicon = None + +# 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 = [] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# +# html_extra_path = [] + +# If not None, a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +# The empty string is equivalent to '%b %d, %Y'. +# +# html_last_updated_fmt = None + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# +# html_additional_pages = {} + +# If false, no module index is generated. +# +# html_domain_indices = True + +# If false, no index is generated. +# +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh' +# +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# 'ja' uses this config value. +# 'zh' user can custom change `jieba` dictionary path. +# +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'LOOTAPIPythonModuledoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'LOOTAPIPythonModule.tex', u'LOOT API Python Module Documentation', + u'WrinklyNinja', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# +# latex_use_parts = False + +# If true, show page references after internal links. +# +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# +# latex_appendices = [] + +# It false, will not define \strong, \code, itleref, \crossref ... but only +# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added +# packages. +# +# latex_keep_old_macro_names = True + +# If false, no module index is generated. +# +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'lootapipythonmodule', u'LOOT API Python Module Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +# +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'LOOTAPIPythonModule', u'LOOT API Python Module Documentation', + author, 'LOOTAPIPythonModule', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +# +# texinfo_appendices = [] + +# If false, no module index is generated. +# +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + 'loot_api': ('http://loot.readthedocs.io/en/c---api/', None), +} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..c29b0c2 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,15 @@ +.. LOOT API Python Module documentation master file, created by + sphinx-quickstart on Mon Aug 15 07:11:32 2016. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +LOOT API Python Module +====================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + usage + reference diff --git a/docs/reference.rst b/docs/reference.rst new file mode 100644 index 0000000..725348f --- /dev/null +++ b/docs/reference.rst @@ -0,0 +1,40 @@ +************* +API Reference +************* + +As this API is just a wrapper for LOOT's C++ API, its documentation is linked to for all non-Python-specific information. + +Enumerations +============ + +.. autoclass:: loot_api.GameType + :members: + +.. autoclass:: loot_api.MessageType + :members: + +Public-Field Data Structures +============================ + +.. autoclass:: loot_api.Message + :members: + +.. autoclass:: loot_api.PluginTags + :members: + + +Functions +========= + +.. autofunction:: loot_api.is_compatible + +.. autofunction:: loot_api.create_database + +Classes +======= + +.. autoclass:: loot_api.DatabaseInterface + :members: + +.. autoclass:: loot_api.Version + :members: diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 0000000..479c201 --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,62 @@ +***** +Usage +***** + +Installing the wrapper +====================== + +Build archives contain two binaries: + +* ``loot_api.pyd`` is the Python wrapper +* ``loot_api.dll`` is the C++ API DLL that the Python wrapper was built against. + +The C++ DLL requires the `Visual C++ 2015 Redistributable (x86)`_ +to be installed. + +To use the wrapper, copy both files to wherever you want to import them from +(they must be in the same folder), and you're done! + +.. _Visual C++ 2015 Redistributable (x86): https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe + +Using the wrapper +================= + +Checking Compatibility +********************** + +To check if the module loaded is compatible with the version of the API that you +developed against:: + + >>> import loot_api + >>> loot_api.is_compatible(0,9,0) + True + >>> loot_api.is_compatible(0,8,0) + False + +**Note:** LOOT's development cycle increments its version number just before +releases, so snapshot builds created from commits between releases may use the +last release's version number, and so appear compatible, but contain breaking +changes that aren't yet reflected by the version numbering. + +The module is currently built against revision `e40624c`_ +of the API, which is post-0.9.2 and pre-0.10.0, but uses the v0.10 metadata +syntax (as specified at that revision, in case there are further changes before +the v0.10 release). + +.. _e40624c: https://github.com/loot/loot/tree/e40624cf7498f69b9393a02572a1eaf31065df44 + +Getting a Plugin's Bash Tag Suggestions +*************************************** + +To get a plugin's Bash Tag suggestions from a ``masterlist.yaml`` metadata file:: + + >>> import loot_api + >>> db = loot_api.create_database(loot_api.GameType.tes4, '', '') + >>> db.load_lists('masterlist.yaml', '') + >>> tags = db.get_plugin_tags(u'Unofficial Oblivion Patch.esp') + >>> tags.added + set([u'Scripts', u'Relations', u'C.Owner', u'Actors.AIPackages', u'Actors.Stats', u'Actors.ACBS', u'C.Music', u'Factions', u'Invent', u'Relev', u'Names', u'C.Light', u'Delev', u'C.Name', u'C.Climate', u'NPC.Class', u'Stats', u'Actors.DeathItem', u'Creatures.Blood', u'Actors.CombatStyle', u'Actors.AIData']) + >>> tags.removed + set([u'C.Water']) + >>> tags.userlist_modified + False diff --git a/src/main.cpp b/src/main.cpp index 4c315d3..04d6136 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,37 +43,37 @@ PYBIND11_PLUGIN(loot_api) { pybind11::module module("loot_api", "A Python module that wraps the LOOT API, generated by pybind11."); - enum_(module, "GameType") + enum_(module, "GameType", "Wraps :cpp:type:`GameType `.") .value("tes4", GameType::tes4); - class_(module, "Message") - .def_readwrite("type", &PluginMessage::type) - .def_readwrite("text", &PluginMessage::text); - - enum_(module, "MessageType") + enum_(module, "MessageType", "Wraps :cpp:type:`MessageType `.") .value("say", MessageType::say) .value("warn", MessageType::warn) .value("error", MessageType::error); - class_(module, "Version") + class_(module, "Message", "Wraps :cpp:class:`PluginMessage `.") + .def_readwrite("type", &PluginMessage::type) + .def_readwrite("text", &PluginMessage::text); + + class_(module, "PluginTags", "Wraps :cpp:class:`PluginTags `.") + .def_readwrite("added", &PluginTags::added) + .def_readwrite("removed", &PluginTags::removed) + .def_readwrite("userlist_modified", &PluginTags::userlist_modified); + + class_(module, "Version", "Wraps :cpp:class:`LootVersion `.") .def_readonly_static("major", &LootVersion::major) .def_readonly_static("minor", &LootVersion::minor) .def_readonly_static("patch", &LootVersion::patch) .def_readonly_static("revision", &LootVersion::revision); - class_(module, "PluginTags") - .def_readwrite("added", &PluginTags::added) - .def_readwrite("removed", &PluginTags::removed) - .def_readwrite("userlist_modified", &PluginTags::userlist_modified); + class_>(module, "DatabaseInterface", "Wraps :cpp:class:`DatabaseInterface `.") + .def("load_lists", &DatabaseInterface::LoadLists, "Loads the masterlist and userlist from the paths specified. Wraps :cpp:func:`LoadLists`.") + .def("get_plugin_tags", &DatabaseInterface::GetPluginTags, "Outputs the Bash Tags suggested for addition and removal by the database for the given plugin. Wraps :cpp:func:`GetPluginTags`.") + .def("get_plugin_messages", &DatabaseInterface::GetPluginMessages, "Outputs the messages associated with the given plugin in the database. Wraps :cpp:func:`GetPluginMessages`."); - class_>(module, "DatabaseInterface") - .def("load_lists", &DatabaseInterface::LoadLists, "Loads the masterlist and userlist from the paths specified.") - .def("get_plugin_tags", &DatabaseInterface::GetPluginTags, "Outputs the Bash Tags suggested for addition and removal by the database for the given plugin.") - .def("get_plugin_messages", &DatabaseInterface::GetPluginMessages, "Outputs the messages associated with the given plugin in the database."); + module.def("is_compatible", &IsCompatible, "Checks for API compatibility. Wraps :cpp:func:`IsCompatible `."); - module.def("is_compatible", &IsCompatible, "Checks for API compatibility."); - - module.def("create_database", &CreateDatabase, "Initialise a new database handle."); + module.def("create_database", &CreateDatabase, "Initialise a new database handle. Wraps :cpp:func:`CreateDatabase `."); return module.ptr(); }