Skip to content

Commit

Permalink
Create and setup documentation on GH Pages (#5)
Browse files Browse the repository at this point in the history
* Create and setup documentation on GH Pages

* Change workflow name

* Fix docs path in workflow

* Fix dependencies in docs build workflow
  • Loading branch information
abaksy authored Apr 19, 2024
1 parent 33759f6 commit 339f15b
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build Documentation

on: [push, pull_request, workflow_dispatch]

permissions:
contents: write

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Install dependencies
run: |
pip install sphinx sphinx_rtd_theme myst_parser
pip install -r requirements.txt
- name: Sphinx build
run: |
sphinx-build docs _build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _build/
force_orphan: true
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)
54 changes: 54 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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 = 'pesuacademy-py'
copyright = '2024, HackerSpace-PESU'
author = 'HackerSpace-PESU'

# The full version, including alpha/beta/rc tags
release = 'v0.0.1'


# -- 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.autodoc']

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


# -- 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'

# 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']
53 changes: 53 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.. pesuacademy-py documentation master file, created by
sphinx-quickstart on Fri Apr 19 17:35:18 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. toctree::
:maxdepth: 2
:caption: Contents:

pesuacademy-py

PESU Academy API
=======================================

Python wrapper and APIs for the PESU Academy website.

The wrapper requires the user's credentials to authenticate and provide **read-only** access to all the pages and
information accessible on the PESU Academy website. Without the credentials, the wrapper will only be able to fetch
details from the `Know Your Class and Section` page.

**Warning:** This is not an official API and is not endorsed by PESU. Use at your own risk.

Installation
+++++++++++++++++++++++++++++++++

Installing from pip
---------------------------------

.. code:: bash
pip install pesuacademy
Installing from source
---------------------------------

.. code:: bash
git clone https://github.com/HackerSpace-PESU/pesuacademy-py
cd pesuacademy-py
python setup.py install
Usage
+++++++++++++++++++++++++++++++++

.. code:: python
from pesuacademy import PESUAcademy
p = PESUAcademy("PRN_or_SRN", "password")
profile = p.profile()
courses = p.courses(semester=2)
attendance = p.attendance()
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

if "%1" == "" goto help

%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
)

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

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

:end
popd
13 changes: 13 additions & 0 deletions docs/pesuacademy-py.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pesuacademy package
===================

Submodules
----------

pesuacademy.pesuacademy
-------------------------

.. automodule:: pesuacademy.pesuacademy
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions pesuacademy/pesuacademy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
class PESUAcademy:
"""
A class to interact with PESU Academy website.
This class is the entrypoint to all the functionality in this module
"""

def __init__(self, username: Optional[str] = None, password: Optional[str] = None):
"""
Initialize the PESU Academy object.
:param username: Your SRN, PRN or email address.
:param password: Your password.
"""
Expand All @@ -32,6 +34,7 @@ def authenticated(self):
def generate_csrf_token(self, username: Optional[str] = None, password: Optional[str] = None) -> str:
"""
Generate a CSRF token. If username and password are provided, authenticate and get the CSRF token.
:param username: Your SRN, PRN or email address.
:param password: Your password.
:return: The CSRF token.
Expand Down Expand Up @@ -76,6 +79,7 @@ def generate_csrf_token(self, username: Optional[str] = None, password: Optional
def know_your_class_and_section(self, username: str) -> ClassAndSectionInfo:
"""
Get the publicly visible class and section information of a student from the Know Your Class and Section page.
:param username: The SRN, PRN or email address of the student.
:return: The profile information.
"""
Expand Down Expand Up @@ -112,6 +116,7 @@ def know_your_class_and_section(self, username: str) -> ClassAndSectionInfo:
def profile(self) -> Profile:
"""
Get the private profile information of the currently authenticated user.
:return: The profile information.
"""
if not self._authenticated:
Expand All @@ -122,6 +127,7 @@ def profile(self) -> Profile:
def courses(self, semester: Optional[int] = None) -> dict[int, list[Course]]:
"""
Get the courses of the currently authenticated user.
:param semester: The semester number. If not provided, all courses across all semesters are returned.
:return: The course information for the given semester.
"""
Expand All @@ -133,6 +139,7 @@ def courses(self, semester: Optional[int] = None) -> dict[int, list[Course]]:
def attendance(self, semester: Optional[int] = None) -> dict[int, list[Course]]:
"""
Get the attendance in courses of the currently authenticated user.
:param semester: The semester number. If not provided, attendance across all semesters are returned.
:return: The attendance information for the given semester.
"""
Expand Down

0 comments on commit 339f15b

Please sign in to comment.