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

docs: add documentation #8

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ repos:
- id: ruff
stages: [commit]

- repo: https://github.com/PyCQA/doc8
rev: "v1.1.1"
hooks:
- id: doc8
stages: [commit]
# silence until we use myst_nb directly
#- repo: https://github.com/PyCQA/doc8
# rev: "v1.1.1"
# hooks:
# - id: doc8
# stages: [commit]

# silence until we have a license file
#- repo: https://github.com/FHPythonUtils/LicenseCheck
# rev: "2023.1.1"
# hooks:
Expand Down
19 changes: 19 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

version: 2

build:
os: ubuntu-22.04
tools:
python: "3.10"
jobs:
# poetry groups are not supported by RDT yet
post_install:
- pip install poetry
- poetry config virtualenvs.create false
- poetry install --with docs
pre_build:
- sphinx-apidoc -o docs/api ipython_gpt

sphinx:
configuration: docs/conf.py
107 changes: 107 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Contribute
==========

Thank you for your help improving **ipython-gpt**!

**ipython-gpt** uses `nox <https://nox.thea.codes/en/stable/>`__ to automate several development-related tasks.
Currently, the project uses four automation processes (called sessions) in ``noxfile.py``:

- ``test``: to run the test with pytest;
- ``docs``: to build the documentation in the ``build`` folder;
- ``lint``: to run the pre-commits in an isolated environment

Every nox session is run in its own virtual environment, and the dependencies are installed automatically.

To run a specific nox automation process, use the following command:

.. code-block:: console

nox -s <session name>

For example: ``nox -s test`` or ``nox -s docs``.

Workflow for contributing changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We follow a typical GitHub workflow of:

- Create a personal fork of this repo
- Create a branch
- Open a pull request
- Fix findings of various linters and checks
- Work through code review

See the following sections for more details.

Clone the repository
^^^^^^^^^^^^^^^^^^^^

First off, you'll need your own copy of **ipython-gpt** codebase. You can clone it for local development like so:

Fork the repository so you have your own copy on GitHub. See the `GitHub forking guide for more information <https://docs.github.com/en/get-started/quickstart/fork-a-repo>`__.

Then, clone the repository locally so that you have a local copy to work on:

.. code-block:: console

git clone https://github.com/<YOUR USERNAME>/ipython-gpt
cd ipython-gpt

Then install the development version of the extension:

.. code-block:: console

pip install -e

This will install the **ipython-gpt** library, together with two additional tools:
- `pre-commit <https://pre-commit.com>`__ for automatically enforcing code standards and quality checks before commits.
- `nox <https://nox.thea.codes/en/stable/>`__, for automating common development tasks.

Lastly, activate the pre-commit hooks by running:

.. code-block:: console

pre-commit install

This will install the necessary dependencies to run pre-commit every time you make a commit with Git.

Contribute to the codebase
^^^^^^^^^^^^^^^^^^^^^^^^^^

Any larger updates to the codebase should include tests and documentation. The tests are located in the ``tests`` folder, and the documentation is located in the ``docs`` folder.

To run the tests locally, use the following command:

.. code-block:: console

nox -s test

See :ref:`below <contributing-docs>` for more information on how to update the documentation.

.. _contributing-docs:

Contribute to the docs
^^^^^^^^^^^^^^^^^^^^^^

The documentation is built using `Sphinx <https://www.sphinx-doc.org/en/master/>`__ and deployed to `Read the Docs <https://readthedocs.org/>`__.

To build the documentation locally, use the following command:

.. code-block:: console

nox -s docs

For each pull request, the documentation is built and deployed to make it easier to review the changes in the PR. To access the docs build from a PR, click on the "Read the Docs" preview in the CI/CD jobs.

Realease new version
^^^^^^^^^^^^^^^^^^^^

To release a new version, start by pushing a new bump from the local directory:

.. code-block::

cz bump

The commitizen-tool will detect the sementic version name based on the existing commits messages.

Then push to Github. In Github design a new release using the same tag name nad the ``release.yaml`` job will send it to pipy.
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)
6 changes: 6 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* add dollar sign in console code-block */
div.highlight-console pre span.go::before {
content: "$";
margin-right: 10px;
margin-left: 5px;
}
37 changes: 37 additions & 0 deletions docs/api/ipython_gpt.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ipython\_gpt package
====================

Submodules
----------

ipython\_gpt.api\_client module
-------------------------------

.. automodule:: ipython_gpt.api_client
:members:
:undoc-members:
:show-inheritance:

ipython\_gpt.displays module
----------------------------

.. automodule:: ipython_gpt.displays
:members:
:undoc-members:
:show-inheritance:

ipython\_gpt.subcommands module
-------------------------------

.. automodule:: ipython_gpt.subcommands
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: ipython_gpt
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/api/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ipython_gpt
===========

.. toctree::
:maxdepth: 4

ipython_gpt
64 changes: 64 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""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 ----------------------------------------------------------------
from datetime import datetime

# -- Project information -------------------------------------------------------
project = "ipython-gpt"
copyright = f"2023-{datetime.now().year}, Santiago Basulto"
author = "Santiago Basulto"
release = "0.0.4"

# -- General configuration -----------------------------------------------------
extensions = [
"sphinx_copybutton",
"sphinx.ext.napoleon",
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
"sphinx_design",
"sphinxcontrib.icon",
"sphinxcontrib.btn",
]
templates_path = ["_template"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# -- Options for HTML output ---------------------------------------------------
html_theme = "pydata_sphinx_theme"
html_static_path = ["_static"]
html_theme_options = {
"logo": {
"text": project,
},
"use_edit_page_button": True,
"footer_end": ["theme-version"],
"icon_links": [
{
"name": "GitHub",
"url": "https://github.com/santiagobasulto/ipython-gpt",
"icon": "fa-brands fa-github",
},
{
"name": "Pypi",
"url": "https://pypi.org/project/ipython-gpt/",
"icon": "fa-brands fa-python",
},
],
}
html_context = {
"github_user": "santiagobasulto",
"github_repo": "ipython-gpt",
"github_version": "master",
"doc_path": "docs",
}
html_css_files = ["custom.css"]

# -- Options for autosummary/autodoc output ------------------------------------
autosummary_generate = True
autoclass_content = "init"
autodoc_typehints = "description"
5 changes: 5 additions & 0 deletions docs/contribute.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Contribute
==========

.. include:: ../CONTRIBUTING.rst
:start-line: 3
45 changes: 45 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
:html_theme.sidebar_secondary.remove:

ipython-gpt
===========

.. toctree::
:hidden:

usage
contribute
API <api/modules>

This extension allows you to use ChatGPT directly from your Jupyter Notebook or IPython Shell (`demo <https://github.com/santiagobasulto/ipython-gpt/blob/master/Demo.ipynb>`__).


.. image:: https://user-images.githubusercontent.com/872296/232230492-9bc50342-9d78-4adb-8168-2f94fcbc3b73.png
:alt: ipython demo

Documentation contents
----------------------

The documentation contains 3 main sections:

.. grid:: 1 2 3 3

.. grid-item::

.. card:: Usage
:link: usage.html

Usage and installation

.. grid-item::

.. card:: Contribute
:link: contribute.html

Help us improve the lib.

.. grid-item::

.. card:: API
:link: api/modules.html

Discover the lib API.
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

%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.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

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

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

:end
popd
Loading