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

[WIP] Create docs for config file #20

Draft
wants to merge 13 commits into
base: main
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
54 changes: 54 additions & 0 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: GitHub Pages

on:
push:
branches:
- main
pull_request:

jobs:
deploy:
runs-on: ubuntu-20.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.8'

- name: Upgrade pip
run: |
# install pip=>20.1 to use "pip cache dir"
python3 -m pip install --upgrade pip
python3 -m pip install .

- name: Get pip cache dir
id: pip-cache
run: echo "::set-output name=dir::$(pip cache dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: python3 -m pip install -r ./docs/requirements.txt

- run: touch .nojekyll

- run: |
touch ./docs/.nojekyll
cd docs && make html

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ pip-wheel-metadata

# editors
.vscode

docs/_build
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 = source
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)
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
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx
sphinx_autodoc_typehints
pydata-sphinx-theme
59 changes: 59 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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 --------------------------------------------------------------

# 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('.'))


# -- Project information -----------------------------------------------------

project = "pysen"
copyright = "2022, Preferred Networks, inc."
author = "Preferred Networks, inc."


# -- General configuration ---------------------------------------------------

# 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.napoleon",
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

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


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

# 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 = ["_static"]


# sphinx.ext.autodoc
autodoc_typehints = "description"
35 changes: 35 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. pysen documentation master file, created by
sphinx-quickstart on Mon Apr 25 09:37:35 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.


Tutorials
=========

.. toctree::
:maxdepth: 1

overview


API Reference
=============

.. toctree::
:maxdepth: 1

reference/ext/index
reference/factory
reference/mypy
reference/py_version
reference/pyproject_model
reference/source


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
44 changes: 44 additions & 0 deletions docs/source/overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. _Overview:

How to configure pysen
======================

Overview
--------

.. code-block:: toml

[tool.pysen]
version = "0.10"
builder = "lint.py"

[tool.pysen.lint]
enable_black = true
enable_flake8 = true
enable_isort = true
enable_mypy = true
mypy_preset = "strict"
line_length = 88
py_version = "py37"

[[tool.pysen.lint.mypy_targets]]
paths = ["."]


- ``tool.pysen`` corresponds to :class:`pysen.pyproject_model.Config`
- For example, ``builder`` under ``[tool.pysen]`` passes to :class:`pysen.pyproject_model.Config`

- ``tool.pysen.lint`` corresponds to :class:`pysen.pyproject_model.LintConfig`
- If you specify ``line_length`` to ``88``, it is passed to :class:`pysen.pyproject_model.LintConfig`

- ``tool.pysen.plugin``, corresponds to :class:`pysen.pyproject_model.PluginConfig`

You can know what you can change a configuration by checking :class:`~pysen.pyproject_model.Config`,
:class:`~pysen.pyproject_model.LintConfig`, and :class:`~pysen.pyproject_model.PluginConfig`.

If a entry is not an instance of Python built-in class, it cannot be directly specified.
For example, ``mypy_targets`` corresponds to :class:`pysen.ext.mypy_wrapper.MypyTarget`, which is not a Python built-in (or equivarent to built-in) class.
To configure such option, you need to create a section ``[[tool.pysen.lint.mypy_targets]]``.
:class:`~pysen.ext.mypy_wrapper.MypyPlugin` has parameters ``paths`` and ``namespace_packages``.
Since ``paths`` is equivarent to ``str`` and ``namespace_packages`` is ``bool``, you can set them in the section.
Note that ``namespace_packages`` is omitted since it is :obj:`False` by default.
7 changes: 7 additions & 0 deletions docs/source/reference/ext/black.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. module:: pysen.ext.black_wrapper

black
=====


.. autoclass:: BlackSetting
6 changes: 6 additions & 0 deletions docs/source/reference/ext/flake8.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. module:: pysen.ext.flake8_wrapper

flake8
======

.. autoclass:: Flake8Setting
11 changes: 11 additions & 0 deletions docs/source/reference/ext/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pysen.ext
=========

.. toctree::
:maxdepth: 2
:caption: Contents:

black
flake8
isort
mypy
10 changes: 10 additions & 0 deletions docs/source/reference/ext/isort.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. module:: pysen.ext.isort_wrapper

isort
=====

.. autoclass:: IsortSetting

.. autoclass:: IsortSectionName
:members:
:undoc-members:
10 changes: 10 additions & 0 deletions docs/source/reference/ext/mypy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. module:: pysen.ext.mypy_wrapper

mypy
====

.. autoclass:: MypySetting

.. autoclass:: MypyPlugin

.. autoclass:: MypyTarget
6 changes: 6 additions & 0 deletions docs/source/reference/factory.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. module:: pysen.factory

pysen.factory
=============

.. autoclass:: MypyModuleOption
6 changes: 6 additions & 0 deletions docs/source/reference/mypy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. module:: pysen.mypy

pysen.mypy
==========

.. autoclass:: MypyPreset
8 changes: 8 additions & 0 deletions docs/source/reference/py_version.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. module:: pysen.py_version

pysen.py_version
================

.. autoclass:: VersionRepresentation

.. autoclass:: PythonVersion
15 changes: 15 additions & 0 deletions docs/source/reference/pyproject_model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. module:: pysen.pyproject_model

pysen.pyproject_model
=====================


.. autoclass:: pysen.pyproject_model.Config

:class:`~pysen.pyproject_model.LintConfig`

.. autoclass:: pysen.pyproject_model.LintConfig

:class:`~pysen.pyproject_model.PluginConfig`

.. autoclass:: pysen.pyproject_model.PluginConfig
6 changes: 6 additions & 0 deletions docs/source/reference/source.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. module:: pysen.source

pysen.source
============

.. autoclass:: Source
Loading