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 sphinx docs #51

Merged
merged 3 commits into from
Dec 18, 2023
Merged
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
58 changes: 58 additions & 0 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy Docs to GitHub Pages

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: "3.11"
miniforge-version: latest
use-mamba: true
channels: conda-forge,gurobi,defaults
channel-priority: true

- name: Install package and dependencies
run: |
mamba install scip gurobi
python -m pip install -e .[docs]

- name: Build documentation
run: sphinx-build docs docs/_build/html -W -b html

- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@v2
with:
path: docs/_build/html
retention-days: 90

deploy:
if: github.ref == 'refs/heads/main'
needs: build
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ dist
.vscode
coverage.xml
coverage_cpp.xml
docs/_build/
docs/build/
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ exclude .gitmodules
exclude ilpy/wrapper.cpp
exclude Makefile
exclude .pre-commit-config.yaml
exclude docs/*
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)
9 changes: 9 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
API Reference
=======================

.. automodule:: ilpy
:members:
:undoc-members:
:private-members:
:special-members: __init__
:show-inheritance:
38 changes: 38 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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

project = "ilpy"
copyright = "2023, Jan Funke, Talley Lambert"
author = "Jan Funke, Talley Lambert"

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

extensions = [
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
]
autodoc_default_options = {
"members": True,
"undoc-members": True,
"private-members": True,
"special-members": "__init__",
"show-inheritance": True,
}
intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)}

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


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

html_theme = "sphinx_rtd_theme"
16 changes: 16 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Welcome to ilpy's documentation!
================================

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

api


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

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
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
2 changes: 1 addition & 1 deletion ilpy/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Expression(ast.AST):
write ``2 * Variable('x') - Variable('y') >= 0``.

Tip: you can use ``ast.dump`` to see the AST representation of an expression.
Or, use ``print(expr)` to see the string representation of an expression.
Or, use ``print(expr)`` to see the string representation of an expression.
"""

def as_constraint(self) -> Constraint:
Expand Down
8 changes: 4 additions & 4 deletions ilpy/wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from . cimport decl
from typing import Iterable, Mapping, Sequence

if TYPE_CHECKING:
from .expression import Expression
from .expressions import Expression # no-cython-lint

####################################
# Enums #
Expand Down Expand Up @@ -227,7 +227,7 @@ cdef class Constraints:
def clear(self):
self.p.clear()

def add(self, constraint: Constraint | Expression):
def add(self, constraint: Constraint | "Expression"):
cdef Constraint const
if hasattr(constraint, "as_constraint"):
const = constraint.as_constraint()
Expand Down Expand Up @@ -261,7 +261,7 @@ cdef class Solver:
self.num_variables = num_variables
deref(self.p).initialize(num_variables, default_variable_type, vtypes)

def set_objective(self, objective: Objective | Expression):
def set_objective(self, objective: Objective | "Expression"):
cdef Objective obj
if hasattr(objective, "as_objective"):
obj = objective.as_objective()
Expand All @@ -272,7 +272,7 @@ cdef class Solver:
def set_constraints(self, Constraints constraints):
deref(self.p).setConstraints(constraints.p[0])

def add_constraint(self, constraint: Constraint | Expression):
def add_constraint(self, constraint: Constraint | "Expression"):
cdef Constraint const
if hasattr(constraint, "as_constraint"):
const = constraint.as_constraint()
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ dev = [
"numpy",
"gurobipy", # used on CI to confirm equality of results
]
docs = [
"sphinx",
"sphinx_rtd_theme",
"sphinx-autodoc-typehints",
]

[project.urls]
homepage = "https://github.com/funkelab/ilpy"
Expand Down