Skip to content

Commit b168b03

Browse files
authored
Better path handling and pypi releases (#11)
* Better path handling * Self-publish to pypi
1 parent ce62276 commit b168b03

37 files changed

+100
-35
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
pipenv install
3939
- name: Lint with Black linter
4040
run: >
41-
pipenv run black homework_checker --check --diff
41+
pipenv run black homework_checker/**/*.py --check --diff
4242
- name: Run unit tests
4343
run: >
44-
pipenv run python3 -m unittest discover -v homework_checker/tests/
44+
pipenv run python3 -m unittest discover -v homework_checker/core/tests/
4545
- name: Upload result md file
4646
uses: actions/upload-artifact@v2
4747
with:
@@ -69,3 +69,29 @@ jobs:
6969
git commit -m "Update results"
7070
git push
7171
72+
publish_to_pypi:
73+
needs: run_tests
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v2
77+
- name: Set up Python
78+
uses: actions/setup-python@v2
79+
with:
80+
python-version: '3.8'
81+
architecture: 'x64'
82+
- name: Install pypa/build
83+
run: python3 -m pip install build --user
84+
- name: Build a binary wheel and a source tarball
85+
run: >-
86+
python -m
87+
build
88+
--sdist
89+
--wheel
90+
--outdir dist/
91+
.
92+
- name: Publish package
93+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
94+
uses: pypa/gh-action-pypi-publish@release/v1
95+
with:
96+
user: __token__
97+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ build/
2424
/coverage.xml
2525

2626
!Pipfile
27+
dist/
28+
/result.md
29+
/results.md

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@
22

33
This is a python module and script that can be used to check homeworks.
44

5-
To be completed later
5+
The idea behind the script is the following:
6+
- There is a homework yaml file, see [`homework.yml`](homework_checker/core/tests/data/homework/example_job.yml) that follows the [schema](schema/schema.yml)
7+
- In this file we define the structure of the homework
8+
- The homework checker library knows how to execute certain types of tasks following the guides in the yaml file
9+
10+
It is expected that the submitted homework will follow the folder structure specified in the `homework.yml` file.
11+
12+
## Core funcionality ##
13+
14+
### Run different tests ###
15+
For now we support running tests for code written in different languages:
16+
- c++
17+
- bash
18+
19+
### Inject data into homeworks ###
20+
We sometimes want to inject a certain folder before running tests, there is an option to do this here.
21+
22+
## How it works ##
23+
24+
I will probably not go into details here at this level of the package maturity. For now you can start digging from the [`check_homework.py`](homework_checker/check_homework.py) script and hopefully the code is clear enough. You can also look at the [`homework.yml`](homework_checker/core/tests/data/homework/example_job.yml) file that we use to test all the implemented functionality.

check_homework.py renamed to homework_checker/check_homework.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
import logging
55
from pathlib import Path
66

7-
from homework_checker.checker import Checker
8-
from homework_checker.md_writer import MdWriter
9-
7+
if __name__ == "__main__":
8+
from core.checker import Checker
9+
from core.md_writer import MdWriter
10+
from core.tools import expand_if_needed
11+
else:
12+
from homework_checker.core.checker import Checker
13+
from homework_checker.core.md_writer import MdWriter
14+
from homework_checker.core.tools import expand_if_needed
1015

1116
logging.basicConfig()
1217
log = logging.getLogger("GHC")
@@ -32,15 +37,15 @@ def main():
3237
if args.verbose:
3338
log.setLevel(logging.DEBUG)
3439
log.debug("Enable DEBUG logging.")
35-
# Read the job file.
36-
log.debug('Reading from file "%s"', args.input)
37-
checker = Checker(Path(args.input))
40+
input_file = expand_if_needed(Path(args.input))
41+
log.debug('Reading from file "%s"', input_file)
42+
checker = Checker(input_file)
3843
results = checker.check_all_homeworks()
3944
md_writer = MdWriter()
4045
md_writer.update(results)
41-
# Write the resulting markdown file.
42-
log.debug('Writing to file "%s"', args.output)
43-
md_writer.write_md_file(args.output)
46+
output_file = expand_if_needed(Path(args.output))
47+
log.debug('Writing to file "%s"', output_file)
48+
md_writer.write_md_file(output_file)
4449

4550

4651
if __name__ == "__main__":

homework_checker/checker.py renamed to homework_checker/core/checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ def __init__(self: "Checker", job_file_path: Path):
3030
self._checked_code_folder = tools.expand_if_needed(
3131
Path(self._base_node[Tags.FOLDER_TAG])
3232
)
33+
log.debug("self._checked_code_folder: %s", self._checked_code_folder)
3334

3435
def check_homework(self: "Checker", homework_node: dict) -> HomeworkResultDict:
3536
"""Run over all Tasks in a single homework."""
3637
results: HomeworkResultDict = {}
3738
current_folder = Path(self._checked_code_folder, homework_node[Tags.FOLDER_TAG])
39+
log.debug("current_folder: %s", current_folder)
3840
if not current_folder.exists():
3941
log.warning("Folder '%s' does not exist. Skiping.", current_folder)
4042
return results
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)