Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sphinx #2

Merged
merged 25 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2eb8eb8
Add docs badge to README
ItsDrike Dec 15, 2022
637c89f
Link docs in pyproject.toml
ItsDrike Dec 29, 2022
f36559d
Merge branch 'main' into add-docs
ItsDrike Dec 29, 2022
b8982cb
Add docs changelog fragment
ItsDrike Dec 29, 2022
1b14337
Merge branch 'main' into add-docs
ItsDrike Jan 8, 2023
65a92b3
Add Sphinx
ItsDrike Feb 7, 2023
02f559e
Add base docs files
ItsDrike Feb 7, 2023
4452ccf
Obtain sphinx config vars dynamically
ItsDrike Feb 7, 2023
1ff63a0
Add config forsphinx extensions
ItsDrike Feb 7, 2023
9ecacd2
Ignore _build/ for sphinx docs
ItsDrike Feb 7, 2023
df06460
Create general docs structure
ItsDrike Feb 7, 2023
32e91f7
Install docs dependencies for validation of docs/conf.py
ItsDrike Feb 7, 2023
5dfb094
Update docs changelog fragment
ItsDrike Feb 7, 2023
2824665
Merge branch 'main' into add-docs
ItsDrike Feb 7, 2023
1a7f490
Use spaces, not tabs
ItsDrike Feb 7, 2023
db45786
Add readthedocs config for building
ItsDrike Feb 7, 2023
67d3618
Update docs template
ItsDrike Feb 7, 2023
00ad2ec
Override the build process with custom commands
ItsDrike Feb 7, 2023
ca9a1aa
Don't use mdinclude for code-of-conduct and contributing
ItsDrike Feb 7, 2023
c612ae4
Remove html_static_path option
ItsDrike Feb 7, 2023
1fce81e
Add taskipy docs task
ItsDrike Feb 7, 2023
5874d1d
Remove makefile for docs, not needed
ItsDrike Feb 7, 2023
0f7dc31
Use taskipy docs task during building
ItsDrike Feb 7, 2023
5e5d0a3
Add sphinx-copybutton extension
ItsDrike Feb 7, 2023
1ce8452
Merge branch 'main' into add-docs
ItsDrike Feb 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ ignore=
# ANN: All flake8-annotations errors
per-file-ignores=
tests/*: DALL000,S101,ANN
docs/*: DALL000, FA101

# vi: ft=config
2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
python-version: 3.11
poetry-version: 1.3.1
install-args: "--without release"
install-args: "--without release --with docs"

- name: Pre-commit Environment Caching
uses: actions/cache@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ htmlcov/
.coverage*
coverage.xml

# Sphinx documentation
docs/_build/

# Pyenv local version information
.python-version

Expand Down
20 changes: 20 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.11"
commands:
- pip install poetry
- poetry config virtualenvs.create false
- poetry install --only main,docs,docs-ci
- poetry run poetry-dynamic-versioning
- poetry run task docs
- mkdir ./_readthedocs
- mv ./docs/_build/html ./_readthedocs


sphinx:
builder: dirhtml
configuration: "docs/conf.py"
fail_on_warning: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/9464f1037f07a795de35/test_coverage)](https://codeclimate.com/github/py-mine/mcproto/test_coverage)
[![Validation](https://github.com/ItsDrike/mcproto/actions/workflows/validation.yml/badge.svg)](https://github.com/ItsDrike/mcproto/actions/workflows/validation.yml)
[![Unit tests](https://github.com/ItsDrike/mcproto/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/ItsDrike/mcproto/actions/workflows/unit-tests.yml)
[![Docs](https://img.shields.io/readthedocs/mcproto?label=Docs)](https://mcproto.readthedocs.io/)

This is a heavily Work-In-Progress library, which attempts to be a full wrapper around the minecraft protocol, allowing
for simple interactions with minecraft servers, and perhaps even for use as a base to a full minecraft server
Expand Down
1 change: 1 addition & 0 deletions changes/2.docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Sphinx and basic docs layout
5 changes: 5 additions & 0 deletions docs/api/basic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Basic Usage
===========

..
TODO: Write this
10 changes: 10 additions & 0 deletions docs/api/internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Internal API
============

Everything listed on this page is considered internal, and is only present to provide linkable references, and
as an easy quick reference for contributors. These components **are not a part of the public API** and **they
should not be used externally**, as we do not guarantee their backwards compatibility, which means breaking changes
may be introduced between patch versions without any warnings.

..
TODO: Write this
127 changes: 127 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""
Configuration file for the Sphinx documentation builder.

For the full list of built-in configuration values, see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
"""

import sys
from datetime import date

from packaging.version import parse as parse_version

if sys.version_info >= (3, 11):
from tomllib import load as toml_parse
else:
from tomli import load as toml_parse


with open("../pyproject.toml", "rb") as f:
pkg_meta: dict[str, str] = toml_parse(f)["tool"]["poetry"]

project = str(pkg_meta["name"])
copyright = f"{date.today().year}, ItsDrike" # noqa: A001
author = "ItsDrike"

parsed_version = parse_version(pkg_meta["version"])
release = str(parsed_version)

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
"sphinx.ext.autosectionlabel",
# Used to reference for third party projects:
"sphinx.ext.intersphinx",
# Used to include .md files:
"m2r2",
# Copyable codeblocks
"sphinx_copybutton",
]

autoclass_content = "both"
autodoc_member_order = "bysource"

autodoc_default_flags = {
"members": "",
"undoc-members": "code,error_template",
"exclude-members": "__dict__,__weakref__",
}

# Automatically generate section labels:
autosectionlabel_prefix_document = True

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = [".rst", ".md"]

# The master toctree document.
master_doc = "index"

# 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 = "en"

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

add_module_names = False

autodoc_default_options = {
"show-inheritance": True,
}

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "alabaster"

# -- Extension configuration -------------------------------------------------

# Third-party projects documentation references:
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
}


# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True


# -- Other options -----------------------------------------------------------


def mock_autodoc() -> None:
"""Mock autodoc to not add ``Bases: object`` to the classes, that do not have super classes.

See also https://stackoverflow.com/a/75041544/20952782.
"""
from sphinx.ext import autodoc

class MockedClassDocumenter(autodoc.ClassDocumenter):
def add_line(self, line: str, source: str, *lineno: int) -> None:
if line == " Bases: :py:class:`object`":
return
super().add_line(line, source, *lineno)

autodoc.ClassDocumenter = MockedClassDocumenter


mock_autodoc()
13 changes: 13 additions & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Examples
========

Here are some examples of using the project in practice.


.. toctree::
:maxdepth: 1
:caption: Examples

status.rst

Feel free to propose any further examples, we'll be happy to add them to the list!
5 changes: 5 additions & 0 deletions docs/examples/status.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Obtaining status data from a server
===================================

..
TODO: Write this
29 changes: 29 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. mdinclude:: ../README.md

Content
-------

.. toctree::
:maxdepth: 1
:caption: Pages

pages/installation.rst
examples/index.rst
pages/faq.rst
pages/contributing.rst
pages/code-of-conduct.rst

.. toctree::
:maxdepth: 1
:caption: API Documentation

api/basic.rst
api/internal.rst


Indices and tables
------------------

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
11 changes: 11 additions & 0 deletions docs/pages/code-of-conduct.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Code of Conduct
===============

..
TODO: Rewrite the code of conduct here directly, rather than including it
like this, and just include a link to the docs in CODE-OF-CONDUCT.md

Temporarily using ``.. mdinclude:: ../../CODE-OF-CONDUCT.md`` doesn't work,
as it contains multiple references to same URLs, and while m2r2 has
--anonymous-references option, it doesn't seem like it's possible to use it
with .. mdinclude
11 changes: 11 additions & 0 deletions docs/pages/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Contributing Guidelines
=======================

..
TODO: Rewrite CONTRIBUTING.md here directly, rather than including it
like this, and just include a link to the docs in CONTRIBUTING.md

Temporarily using ``.. mdinclude:: ../../CONTRIBUTING.md`` doesn't work,
as it contains multiple references to same URLs, and while m2r2 has
--anonymous-references option, it doesn't seem like it's possible to use it
with .. mdinclude
4 changes: 4 additions & 0 deletions docs/pages/faq.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Frequently Asked Questions
==========================

There aren't any questions here yet. Feel free to help us change that and propose some!
5 changes: 5 additions & 0 deletions docs/pages/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Installation
============

..
TODO: Write this
Loading