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

+28-2
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

+3
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

+20-1
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 homework_checker/check_homework.py

+14-9
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__":
File renamed without changes.

homework_checker/checker.py homework_checker/core/checker.py

+2
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.
File renamed without changes.
File renamed without changes.

homework_checker/core/tests/__init__.py

Whitespace-only changes.

homework_checker/tests/data/homework/example_job.yml homework_checker/core/tests/data/homework/example_job.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
folder: homework_checker/tests/data/homework
2+
folder: homework_checker/core/tests/data/homework
33
homeworks:
44
- name: "Sample homework"
55
folder: "homework_1"

homework_checker/tests/test_checker.py homework_checker/core/tests/test_checker.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from pathlib import Path
88
from typing import Dict
99

10-
from homework_checker.checker import Checker
11-
from homework_checker.md_writer import MdWriter
12-
from homework_checker import tools
10+
from homework_checker.core.checker import Checker
11+
from homework_checker.core.md_writer import MdWriter
12+
from homework_checker.core import tools
1313

1414

1515
class TestChecker(unittest.TestCase):
@@ -30,6 +30,7 @@ def test_everything(self: TestChecker):
3030
path_to_job = (
3131
tools.PROJECT_ROOT_FOLDER
3232
/ "homework_checker"
33+
/ "core"
3334
/ "tests"
3435
/ "data"
3536
/ "homework"

homework_checker/tests/test_task.py homework_checker/core/tests/test_task.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
from pathlib import Path
66
from typing import Tuple
77

8-
from homework_checker.tasks import Task, BUILD_SUCCESS_TAG, STYLE_ERROR_TAG
9-
from homework_checker.schema_tags import Tags
10-
from homework_checker.schema_manager import SchemaManager
11-
from homework_checker import tools
8+
from homework_checker.core.tasks import (
9+
Task,
10+
BUILD_SUCCESS_TAG,
11+
STYLE_ERROR_TAG,
12+
)
13+
from homework_checker.core.schema_tags import Tags
14+
from homework_checker.core.schema_manager import SchemaManager
15+
from homework_checker.core import tools
1216

1317

1418
class TestTask(unittest.TestCase):
@@ -20,6 +24,7 @@ def setUp(self: "TestTask"):
2024
self.job_file_path = (
2125
tools.PROJECT_ROOT_FOLDER
2226
/ "homework_checker"
27+
/ "core"
2328
/ "tests"
2429
/ "data"
2530
/ "homework"

homework_checker/tests/test_tools.py homework_checker/core/tests/test_tools.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from time import monotonic as timer
88
from pathlib import Path
9-
from homework_checker import tools
10-
from homework_checker.schema_tags import OutputTags
9+
from homework_checker.core import tools
10+
from homework_checker.core.schema_tags import OutputTags
1111

1212

1313
class TestTools(unittest.TestCase):
@@ -27,7 +27,7 @@ def test_temp_directory_copy(self: TestTools):
2727
with tools.TempDirCopy(source_folder=folder_name) as tempdir:
2828
self.assertIn(tools.get_unique_str(str(folder_name)), str(tempdir))
2929
self.assertTrue(tempdir.exists())
30-
self.assertTrue((tempdir / tools.PKG_NAME / "tests").exists())
30+
self.assertTrue((tempdir / tools.PKG_NAME / "core" / "tests").exists())
3131
with self.assertRaises(Exception):
3232
with tools.TempDirCopy(folder_name):
3333
pass

homework_checker/tools.py homework_checker/core/tools.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .schema_tags import OutputTags
1818

1919
PKG_NAME = "homework_checker"
20-
PROJECT_ROOT_FOLDER = Path(__file__).parent.parent
20+
PROJECT_ROOT_FOLDER = Path(__file__).parent.parent.parent
2121
DATE_PATTERN = "%Y-%m-%d %H:%M:%S"
2222
MAX_DATE_STR = datetime.datetime.max.strftime(DATE_PATTERN)
2323

@@ -84,15 +84,15 @@ def __exit__(self: TempDirCopy, *exc_info: Any):
8484
def expand_if_needed(input_path: Path) -> Path:
8585
"""Expand the path if it is not absolute."""
8686
if input_path.is_absolute():
87-
return Path(input_path)
87+
return input_path
8888
new_path = input_path.expanduser()
8989
if new_path.is_absolute():
9090
# This path needed user expansion. Now that the user home directory is
9191
# expanded this is a full absolute path.
9292
return new_path
9393
# The user could not be expanded, so we assume it is just another relative
94-
# path to the project directory. Mostly used for testing purposes here.
95-
return Path(PROJECT_ROOT_FOLDER, new_path)
94+
# path to the current working directory.
95+
return Path.cwd() / new_path
9696

9797

9898
def convert_to(

print_repo_name.py homework_checker/print_repo_name.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
44
Attributes:
55
WIKI_REPO_MASK (str): mask of wiki git repo
6+
REPO_MASK (str): mask of the git repo
67
"""
78
import sys
89

9-
from homework_checker.tools import parse_git_url
10+
if __name__ == "__main__":
11+
from core.tools import parse_git_url
12+
else:
13+
from homework_checker.core.tools import parse_git_url
1014

1115
WIKI_REPO_MASK = "git@{domain}:{user}/{project}.wiki.git"
1216
REPO_MASK = "git@{domain}:{user}/{project}.git"

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
description-file = readme.md
2+
description_file = readme.md
33

44
[nosetests]
55
verbosity=2

setup.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
"""Setup module for catkin_tools_fetch."""
21
import os
32
import sys
43
from stat import ST_MODE
54
from distutils import log
65
from setuptools import setup
76
from setuptools.command.install import install
87

9-
VERSION_STRING = "0.0.6"
8+
VERSION_STRING = "1.0.0"
109

1110
PACKAGE_NAME = "homework_checker"
1211

@@ -37,7 +36,7 @@ def run(self):
3736
os.chmod(file, mode)
3837

3938

40-
GITHUB_URL = "https://github.com/PRBonn/{}".format(PACKAGE_NAME)
39+
GITHUB_URL = "https://github.com/niosus/{}".format(PACKAGE_NAME)
4140

4241
setup(
4342
name=PACKAGE_NAME,
@@ -46,10 +45,10 @@ def run(self):
4645
install_requires=INSTALL_REQUIRES,
4746
setup_requires=["nose>=1.0"],
4847
author="Igor Bogoslavskyi",
49-
author_email="igor.bogoslavskyi@uni-bonn.de",
48+
author_email="igor.bogoslavskyi@gmail.com",
5049
maintainer="Igor Bogoslavskyi",
51-
maintainer_email="igor.bogoslavskyi@uni-bonn.de",
52-
keywords=["ipb", "homework-checker"],
50+
maintainer_email="igor.bogoslavskyi@gmail.com",
51+
keywords=["homework-checker"],
5352
license="Apache 2.0",
5453
url=GITHUB_URL,
5554
download_url=GITHUB_URL + "/tarball/" + VERSION_STRING,
@@ -61,6 +60,7 @@ def run(self):
6160
],
6261
description="""A generic homework checker.""",
6362
long_description=open("README.md").read(),
63+
long_description_content_type='text/markdown',
6464
test_suite="tests",
6565
entry_points={
6666
"console_scripts": [

0 commit comments

Comments
 (0)