Skip to content

Commit

Permalink
Better path handling and pypi releases (#11)
Browse files Browse the repository at this point in the history
* Better path handling

* Self-publish to pypi
  • Loading branch information
niosus authored Feb 13, 2022
1 parent ce62276 commit b168b03
Show file tree
Hide file tree
Showing 37 changed files with 100 additions and 35 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
pipenv install
- name: Lint with Black linter
run: >
pipenv run black homework_checker --check --diff
pipenv run black homework_checker/**/*.py --check --diff
- name: Run unit tests
run: >
pipenv run python3 -m unittest discover -v homework_checker/tests/
pipenv run python3 -m unittest discover -v homework_checker/core/tests/
- name: Upload result md file
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -69,3 +69,29 @@ jobs:
git commit -m "Update results"
git push
publish_to_pypi:
needs: run_tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
architecture: 'x64'
- name: Install pypa/build
run: python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ build/
/coverage.xml

!Pipfile
dist/
/result.md
/results.md
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,23 @@

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

To be completed later
The idea behind the script is the following:
- 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)
- In this file we define the structure of the homework
- The homework checker library knows how to execute certain types of tasks following the guides in the yaml file

It is expected that the submitted homework will follow the folder structure specified in the `homework.yml` file.

## Core funcionality ##

### Run different tests ###
For now we support running tests for code written in different languages:
- c++
- bash

### Inject data into homeworks ###
We sometimes want to inject a certain folder before running tests, there is an option to do this here.

## How it works ##

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.
23 changes: 14 additions & 9 deletions check_homework.py → homework_checker/check_homework.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import logging
from pathlib import Path

from homework_checker.checker import Checker
from homework_checker.md_writer import MdWriter

if __name__ == "__main__":
from core.checker import Checker
from core.md_writer import MdWriter
from core.tools import expand_if_needed
else:
from homework_checker.core.checker import Checker
from homework_checker.core.md_writer import MdWriter
from homework_checker.core.tools import expand_if_needed

logging.basicConfig()
log = logging.getLogger("GHC")
Expand All @@ -32,15 +37,15 @@ def main():
if args.verbose:
log.setLevel(logging.DEBUG)
log.debug("Enable DEBUG logging.")
# Read the job file.
log.debug('Reading from file "%s"', args.input)
checker = Checker(Path(args.input))
input_file = expand_if_needed(Path(args.input))
log.debug('Reading from file "%s"', input_file)
checker = Checker(input_file)
results = checker.check_all_homeworks()
md_writer = MdWriter()
md_writer.update(results)
# Write the resulting markdown file.
log.debug('Writing to file "%s"', args.output)
md_writer.write_md_file(args.output)
output_file = expand_if_needed(Path(args.output))
log.debug('Writing to file "%s"', output_file)
md_writer.write_md_file(output_file)


if __name__ == "__main__":
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def __init__(self: "Checker", job_file_path: Path):
self._checked_code_folder = tools.expand_if_needed(
Path(self._base_node[Tags.FOLDER_TAG])
)
log.debug("self._checked_code_folder: %s", self._checked_code_folder)

def check_homework(self: "Checker", homework_node: dict) -> HomeworkResultDict:
"""Run over all Tasks in a single homework."""
results: HomeworkResultDict = {}
current_folder = Path(self._checked_code_folder, homework_node[Tags.FOLDER_TAG])
log.debug("current_folder: %s", current_folder)
if not current_folder.exists():
log.warning("Folder '%s' does not exist. Skiping.", current_folder)
return results
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
folder: homework_checker/tests/data/homework
folder: homework_checker/core/tests/data/homework
homeworks:
- name: "Sample homework"
folder: "homework_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from pathlib import Path
from typing import Dict

from homework_checker.checker import Checker
from homework_checker.md_writer import MdWriter
from homework_checker import tools
from homework_checker.core.checker import Checker
from homework_checker.core.md_writer import MdWriter
from homework_checker.core import tools


class TestChecker(unittest.TestCase):
Expand All @@ -30,6 +30,7 @@ def test_everything(self: TestChecker):
path_to_job = (
tools.PROJECT_ROOT_FOLDER
/ "homework_checker"
/ "core"
/ "tests"
/ "data"
/ "homework"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
from pathlib import Path
from typing import Tuple

from homework_checker.tasks import Task, BUILD_SUCCESS_TAG, STYLE_ERROR_TAG
from homework_checker.schema_tags import Tags
from homework_checker.schema_manager import SchemaManager
from homework_checker import tools
from homework_checker.core.tasks import (
Task,
BUILD_SUCCESS_TAG,
STYLE_ERROR_TAG,
)
from homework_checker.core.schema_tags import Tags
from homework_checker.core.schema_manager import SchemaManager
from homework_checker.core import tools


class TestTask(unittest.TestCase):
Expand All @@ -20,6 +24,7 @@ def setUp(self: "TestTask"):
self.job_file_path = (
tools.PROJECT_ROOT_FOLDER
/ "homework_checker"
/ "core"
/ "tests"
/ "data"
/ "homework"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from time import monotonic as timer
from pathlib import Path
from homework_checker import tools
from homework_checker.schema_tags import OutputTags
from homework_checker.core import tools
from homework_checker.core.schema_tags import OutputTags


class TestTools(unittest.TestCase):
Expand All @@ -27,7 +27,7 @@ def test_temp_directory_copy(self: TestTools):
with tools.TempDirCopy(source_folder=folder_name) as tempdir:
self.assertIn(tools.get_unique_str(str(folder_name)), str(tempdir))
self.assertTrue(tempdir.exists())
self.assertTrue((tempdir / tools.PKG_NAME / "tests").exists())
self.assertTrue((tempdir / tools.PKG_NAME / "core" / "tests").exists())
with self.assertRaises(Exception):
with tools.TempDirCopy(folder_name):
pass
Expand Down
8 changes: 4 additions & 4 deletions homework_checker/tools.py → homework_checker/core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .schema_tags import OutputTags

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

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


def convert_to(
Expand Down
6 changes: 5 additions & 1 deletion print_repo_name.py → homework_checker/print_repo_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
Attributes:
WIKI_REPO_MASK (str): mask of wiki git repo
REPO_MASK (str): mask of the git repo
"""
import sys

from homework_checker.tools import parse_git_url
if __name__ == "__main__":
from core.tools import parse_git_url
else:
from homework_checker.core.tools import parse_git_url

WIKI_REPO_MASK = "git@{domain}:{user}/{project}.wiki.git"
REPO_MASK = "git@{domain}:{user}/{project}.git"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
description-file = readme.md
description_file = readme.md

[nosetests]
verbosity=2
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Setup module for catkin_tools_fetch."""
import os
import sys
from stat import ST_MODE
from distutils import log
from setuptools import setup
from setuptools.command.install import install

VERSION_STRING = "0.0.6"
VERSION_STRING = "1.0.0"

PACKAGE_NAME = "homework_checker"

Expand Down Expand Up @@ -37,7 +36,7 @@ def run(self):
os.chmod(file, mode)


GITHUB_URL = "https://github.com/PRBonn/{}".format(PACKAGE_NAME)
GITHUB_URL = "https://github.com/niosus/{}".format(PACKAGE_NAME)

setup(
name=PACKAGE_NAME,
Expand All @@ -46,10 +45,10 @@ def run(self):
install_requires=INSTALL_REQUIRES,
setup_requires=["nose>=1.0"],
author="Igor Bogoslavskyi",
author_email="igor.bogoslavskyi@uni-bonn.de",
author_email="igor.bogoslavskyi@gmail.com",
maintainer="Igor Bogoslavskyi",
maintainer_email="igor.bogoslavskyi@uni-bonn.de",
keywords=["ipb", "homework-checker"],
maintainer_email="igor.bogoslavskyi@gmail.com",
keywords=["homework-checker"],
license="Apache 2.0",
url=GITHUB_URL,
download_url=GITHUB_URL + "/tarball/" + VERSION_STRING,
Expand All @@ -61,6 +60,7 @@ def run(self):
],
description="""A generic homework checker.""",
long_description=open("README.md").read(),
long_description_content_type='text/markdown',
test_suite="tests",
entry_points={
"console_scripts": [
Expand Down

0 comments on commit b168b03

Please sign in to comment.