From 339f15b4f191be14afeff1d6ee2b5ce3fe2fd53c Mon Sep 17 00:00:00 2001 From: Aronya Baksy <50787681+abaksy@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:24:36 +0530 Subject: [PATCH] Create and setup documentation on GH Pages (#5) * Create and setup documentation on GH Pages * Change workflow name * Fix docs path in workflow * Fix dependencies in docs build workflow --- .github/workflows/build_docs.yml | 28 +++++++++++++++++ docs/Makefile | 20 ++++++++++++ docs/conf.py | 54 ++++++++++++++++++++++++++++++++ docs/index.rst | 53 +++++++++++++++++++++++++++++++ docs/make.bat | 35 +++++++++++++++++++++ docs/pesuacademy-py.rst | 13 ++++++++ pesuacademy/pesuacademy.py | 7 +++++ 7 files changed, 210 insertions(+) create mode 100644 .github/workflows/build_docs.yml create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/pesuacademy-py.rst diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml new file mode 100644 index 0000000..af62599 --- /dev/null +++ b/.github/workflows/build_docs.yml @@ -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 \ No newline at end of file diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -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) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..b92c2e1 --- /dev/null +++ b/docs/conf.py @@ -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'] \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..2b67e27 --- /dev/null +++ b/docs/index.rst @@ -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() diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..153be5e --- /dev/null +++ b/docs/make.bat @@ -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 diff --git a/docs/pesuacademy-py.rst b/docs/pesuacademy-py.rst new file mode 100644 index 0000000..442a563 --- /dev/null +++ b/docs/pesuacademy-py.rst @@ -0,0 +1,13 @@ +pesuacademy package +=================== + +Submodules +---------- + +pesuacademy.pesuacademy +------------------------- + +.. automodule:: pesuacademy.pesuacademy + :members: + :undoc-members: + :show-inheritance: diff --git a/pesuacademy/pesuacademy.py b/pesuacademy/pesuacademy.py index bfedc9f..47b17b1 100644 --- a/pesuacademy/pesuacademy.py +++ b/pesuacademy/pesuacademy.py @@ -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. """ @@ -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. @@ -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. """ @@ -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: @@ -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. """ @@ -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. """