Skip to content

Commit

Permalink
Prepare exam repository
Browse files Browse the repository at this point in the history
  • Loading branch information
abhabongse committed Mar 13, 2022
0 parents commit d223338
Show file tree
Hide file tree
Showing 21 changed files with 6,824 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/project-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Project Test

on:
push:
branches: [ "*" ]
pull_request:
branches: [ main ]

jobs:
poetry-check:
name: Poetry check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: "3.7"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: "1.2.0a2"
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install library
run: poetry install --no-interaction
- name: Run poetry check
run: |
poetry check
notebook-check:
name: Grade the exam notebook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: "3.7"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: "1.2.0a2"
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install library
run: poetry install --no-interaction
- name: Notebook grading
run: |
poetry run ./grade.py exam.ipynb --force-color --width 120
133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# All files
.idea/
.vscode/
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.1.0"
hooks:
- id: check-json
- id: check-toml
- id: check-shebang-scripts-are-executable
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: fix-byte-order-marker
- repo: https://github.com/python-poetry/poetry
rev: 'a358be7d4cfff6d0823d4e18f867654724b11596'
hooks:
- id: poetry-check
name: poetry check
- id: poetry-lock
name: poetry lock
args: [ "--no-update" ]
- id: poetry-export
name: poetry export (requirements.txt)
args: [ "-f", "requirements.txt", "-o", "requirements.txt" ]
- id: poetry-export
name: poetry export (dev-requirements.txt)
args: [ "--dev", "-f", "requirements.txt", "-o", "dev-requirements.txt" ]
- repo: https://github.com/pycqa/flake8
rev: "4.0.1"
hooks:
- id: flake8
37 changes: 37 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Development Notes

This project adopts the new configuration file [`pyproject.toml`](pyproject.toml)
per [PEP 518](https://www.python.org/dev/peps/pep-0518/)
and uses [Poetry](https://python-poetry.org/) as build dependency.
Although Poetry is not required to use this project just for notebook grading,
we recommend installing it for project development.


## Project Structure

- [`src/nbnursery`](src/nbnursery) Python source code to grading scripts
- [`exam.ipynb`](exam.ipynb) Jupyter notebook containing exam questions
- [`grade.py`](grade.py) Grading script for [`exam.ipynb`](exam.ipynb)

## Development Setup

1. Install the following tools to local development machine:
- Python ≥ 3.7.1, < 3.8.0 (pro tip: use [pyenv](https://github.com/pyenv/pyenv))
- [Poetry 1.2.0a2](https://python-poetry.org/docs/master/)
- [Just](https://github.com/casey/just)
- [Pre-commit](https://pre-commit.com/)
2. Install dependencies with Poetry
```shell
$ poetry install
```
and run post installation script (will install pre-commit hooks)
```shell
$ just post-install
```

## Package Dependency Management

All Python package dependencies are configured in [`pyproject.toml`](pyproject.toml).
The pre-commit script will ensure that frozen dependencies
are automatically generated and saved into
[`poetry.lock`](poetry.lock) and [`requirements.txt`](requirements.txt).
81 changes: 81 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# List all available commands
default:
@just --list --unsorted

# ___ _ _ _
# / __| |_ ___ _ _| |_ __ _ _| |_ ___
# \__ \ ' \/ _ \ '_| _/ _| || | _(_-<
# |___/_||_\___/_| \__\__|\_,_|\__/__/
#

# Export Python dependencies from poetry into requirement files
export-requirements:
poetry export | tee requirements.txt
poetry export --dev | tee dev-requirements.txt

# ___ _ ___ _ _ _ _____ _
# / __|___ __| |___ / _ \ _ _ __ _| (_) |_ _ _ |_ _|__ ___| |___
# | (__/ _ \/ _` / -_) | (_) | || / _` | | | _| || | | |/ _ \/ _ \ (_-<
# \___\___/\__,_\___| \__\_\\_,_\__,_|_|_|\__|\_, | |_|\___/\___/_/__/
# |__/

# Run tests against source files (flake8 and pytest)
test: flake8

# Run flake8 linter against source files
flake8:
poetry run flake8 -v \
--application-import-names $(find src -maxdepth 2 -name '__init__.py' -printf '%h\n' | sed 's/^src\///' | paste -sd "," -)

# Run pytest against source files
pytest +ARGS='-v':
poetry run python -m pytest {{ARGS}}

# Run pytest with line coverage checks
coverage +ARGS='-v':
@echo Python packages: $(find src -maxdepth 2 -name '__init__.py' -printf '%h\n' | sed 's/^src\///')
poetry run python -m pytest \
$(find src -maxdepth 2 -name '__init__.py' -printf '%h\n' | sed 's/^src\//--cov=/') \
--cov-report=term-missing {{ARGS}}

# Clear out all cached files
clean:
find . -name '.*_cache' -type d | xargs rm -rf
find . -name '.ipynb_checkpoints' -type d | xargs rm -rf
rm -rf .coverage .dmypy.json

# ___ _ _ _
# / __| |_ ___ _ _| |_ __ _ _| |_ ___
# \__ \ ' \/ _ \ '_| _/ _| || | _(_-<
# |___/_||_\___/_| \__\__|\_,_|\__/__/
#

# Render markdown FILE
markdown FILE:
poetry run python -m rich.markdown -w 119 {{FILE}}

# Syntax highlight source FILE
syntax FILE:
poetry run python -m rich.syntax -l -r {{FILE}}

# Show git log tree
show-tree:
@git --no-pager log --graph --abbrev-commit --decorate --all \
--format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'

# Show git diff
show-diff:
@git --no-pager diff "$@" --name-only --diff-filter=d | xargs bat -P --diff --diff-context 5

# ___ _ ___ _ _ _
# | _ \___ __| |_ |_ _|_ _ __| |_ __ _| | |
# | _/ _ (_-< _| | || ' \(_-< _/ _` | | |
# |_| \___/__/\__| |___|_||_/__/\__\__,_|_|_|
#

# Run this command after cloning the repo
post-install: install-pre-commit-hooks

# Install pre-commit hooks
install-pre-commit-hooks:
pre-commit install
Loading

0 comments on commit d223338

Please sign in to comment.