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

Add action test and rendering README #1

Merged
merged 4 commits into from
Aug 13, 2024
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
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish to PyPI
on:
push:
tags:
- "v*.*.*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PIPY_API_TOKEN }}
68 changes: 68 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Tests
on:
push:
branches:
- main
- '*.x'
paths-ignore:
- '*.md'
pull_request:
paths-ignore:
- '*.md'
jobs:
local-test:
name: ubuntu20.04-py${{ matrix.python }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- {python: '3.12'}
- {python: '3.11'}
- {python: '3.10'}
- {python: '3.9'}
- {python: '3.8'}
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Install GCC and Make
run: |
sudo apt-get update
sudo apt-get install -y build-essential

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev

- name: Run Examples Test
run: poetry run pytest -vs -n auto

container-test:
name: GCC Docker Container
runs-on: ubuntu-latest
container:
image: gcc:latest
volumes:
- ${{ github.workspace }}:/app
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
apt-get update
apt-get install -y python3-pip
python3 -m pip install --upgrade pip --break-system-packages
pip install poetry --break-system-packages
poetry install --with dev

- name: Run Examples Test
run: poetry run pytest -vs -n auto
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# cpGrader: A Python Package to Grade Programming Assignments Automatically

cpGrader is designed to be used with the course ["NTNU CSIE Computer Programming I/II"](https://sites.google.com/gapps.ntnu.edu.tw/neokent/teaching) by instructor [neokent (紀博文 Po-Wen Chi)](https://sites.google.com/gapps.ntnu.edu.tw/neokent/about-me).

## Thanks for your Contribution

<p>
<a href="https://github.com/NaoCoding">
<img src="https://img.shields.io/badge/41247001S-盧昱安-blue"/>
</a>
<img src="https://img.shields.io/badge/41247012S-吳振榮-blue"/>
<img src="https://img.shields.io/badge/41247024S-廖妤恩-blue"/>
<img src="https://img.shields.io/badge/41247032S-吳俊廷-blue"/>
<a href="https://github.com/mrfish233">
<img src="https://img.shields.io/badge/41247039S-韓欣劭-blue"/>
</a>
<img src="https://img.shields.io/badge/41247057S-陳育渝-blue"/>
</p>
<div align="left">

[![Test](https://github.com/ryanlinjui/cpGrader/actions/workflows/tests.yml/badge.svg?branch=main&event=push)](https://github.com/ryanlinjui/cpGrader/actions?query=event%3Apush+branch%3Amain)

</div>

> cpGrader is designed to be used with the course ["NTNU CSIE Computer Programming I/II"](https://sites.google.com/gapps.ntnu.edu.tw/neokent/teaching) by instructor [neokent (紀博文 Po-Wen Chi)](https://sites.google.com/gapps.ntnu.edu.tw/neokent/about-me).

## Thanks for your Contribution 🌟

<div align="left">

[![41247001S-盧昱安](https://img.shields.io/badge/41247001S-盧昱安-important)](https://github.com/NaoCoding)
![41247012S-吳振榮](https://img.shields.io/badge/41247012S-吳振榮-important)
![41247024S-廖妤恩](https://img.shields.io/badge/41247024S-廖妤恩-important)
![41247032S-吳俊廷](https://img.shields.io/badge/41247032S-吳俊廷-important)
[![41247039S-韓欣劭](https://img.shields.io/badge/41247039S-韓欣劭-important)](https://github.com/mrfish233)
![41247057S-陳育渝](https://img.shields.io/badge/41247057S-陳育渝-important)

</div>


## Installation

Expand Down Expand Up @@ -105,4 +110,4 @@ pytest -k 2023-cp1-hw01
### Details and Muti-Threading
```bash
pytest -vs -n auto
```
```
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
description = "A Python Package to Grade Programming Assignments Automatically."
authors = ["ryanlinjui <[email protected]>"]
readme = "README.md"
packages = [{include = "cpGrader", from = "src"}]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
15 changes: 0 additions & 15 deletions requirements.txt

This file was deleted.

7 changes: 4 additions & 3 deletions src/cpGrader/cpGrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import objprint
from typing import (
List,
Callable
Callable,
Union
)

import toml
Expand All @@ -29,7 +30,7 @@
class Grader:
def __init__(
self,
config_file: str | None = DEFAULT_CONFIG_FILE
config_file: Union[str, None] = DEFAULT_CONFIG_FILE
):
self.grade_report: List[List[str]] = []

Expand Down Expand Up @@ -84,7 +85,7 @@ def __read_config(self, config_file: str) -> None:

def setcase(
self,
match_case: str | List[str] = ALL_MATCH_CASE
match_case: Union[str, List[str]] = ALL_MATCH_CASE
) -> Callable:

def wrapper(func: Callable) -> None:
Expand Down
25 changes: 13 additions & 12 deletions src/cpGrader/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from inspect import currentframe
from typing import (
List,
Callable
Callable,
Union
)

from .utils import (
Expand All @@ -22,18 +23,18 @@ class Case:
def __init__(
self,
name: str,
case_file: str | None,
command: str | None,
pts: int | float,
correct_file: str | None,
verify_func: Callable | None
case_file: Union[str, None],
command: Union[str, None],
pts: Union[int, float],
correct_file: Union[str, None],
verify_func: Union[Callable, None]
):
self.name: str = name
self.case_file: str | None = case_file
self.command: str | None = command
self.pts: int | float = pts
self.correct_file: str | None = correct_file
self.verify_func: Callable | None = verify_func
self.case_file: Union[str, None] = case_file
self.command: Union[str, None] = command
self.pts: Union[int, float] = pts
self.correct_file: Union[str, None] = correct_file
self.verify_func: Union[Callable, None] = verify_func

self.case_data: List[str] = []
self.student_output: str = ""
Expand Down Expand Up @@ -94,7 +95,7 @@ def __correct_setup(self) -> None:
with open(output_filepath, "w+") as f:
f.write(self.correct_output)

def execute(self, student_dir: str) -> ExecuteException | None:
def execute(self, student_dir: str) -> Union[None, ExecuteException]:
# setup case data and build/execute correct file
if self.case_file != None:
self.case_data = [line.strip() for line in open(self.case_file, "r").readlines()]
Expand Down
5 changes: 3 additions & 2 deletions src/cpGrader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import zipfile
from typing import (
List,
Tuple
Tuple,
Union
)

import pexpect
Expand Down Expand Up @@ -166,7 +167,7 @@ def execute(folder:str, command:str, stdin_list:list=[]) -> str:
return output

def grade(
grade_report: List[Tuple[str, List[int | float], List[str]]],
grade_report: List[Tuple[str, List[Union[int, str]], List[str]]],
save_path: str
) -> None:

Expand Down