Skip to content

Commit

Permalink
feat: Lectures layout: singe task source (#25)
Browse files Browse the repository at this point in the history
* feat: add reserved task names

* feat: add template create function

* test: add task reserved name tests

* feat: add template clearing raise if unable to find marks

* wip: create template

* docs: small update in driver docstring

* feat: lectures template code

* feat: rebuild Driver to have public and private different layouts

* style: fix mypy, ruff and isort

* tests: add driver unit tests

* style: apply isort
  • Loading branch information
k4black authored Sep 3, 2023
1 parent 54e6f0a commit b14752a
Show file tree
Hide file tree
Showing 17 changed files with 949 additions and 266 deletions.
75 changes: 46 additions & 29 deletions checker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ def check(
execution_folder: Path = context['execution_folder']

root = root or execution_folder
course_driver = CourseDriver(
private_course_driver = CourseDriver(
root_dir=root,
reference_root_dir=root,
repo_type='private',
layout=course_config.layout,
use_reference_source=True,
)
course_schedule = CourseSchedule(
deadlines_config=course_driver.get_deadlines_file_path(),
deadlines_config=private_course_driver.get_deadlines_file_path(),
)
tester = Tester.create(
system=course_config.system,
Expand Down Expand Up @@ -120,7 +119,7 @@ def check(

pre_release_check_tasks(
course_schedule,
course_driver,
private_course_driver,
tester,
tasks=tasks,
parallelize=parallelize,
Expand All @@ -144,14 +143,18 @@ def grade(
execution_folder: Path = context['execution_folder']

reference_root = reference_root or execution_folder
course_driver = CourseDriver(
public_course_driver = CourseDriver(
root_dir=Path(os.environ['CI_PROJECT_DIR']),
reference_root_dir=reference_root,
repo_type='public',
layout=course_config.layout,
)
private_course_driver = CourseDriver(
root_dir=reference_root,
repo_type='private',
layout=course_config.layout,
use_reference_tests=True,
)
course_schedule = CourseSchedule(
deadlines_config=course_driver.get_deadlines_file_path(),
deadlines_config=private_course_driver.get_deadlines_file_path(),
)
tester = Tester.create(
system=course_config.system,
Expand All @@ -160,7 +163,8 @@ def grade(
grade_on_ci(
course_config,
course_schedule,
course_driver,
public_course_driver,
private_course_driver,
tester,
test_full_groups=test_full_groups,
)
Expand All @@ -182,14 +186,18 @@ def grade_mrs(
execution_folder: Path = context['execution_folder']

reference_root = reference_root or execution_folder
course_driver = CourseDriver(
public_course_driver = CourseDriver(
root_dir=Path(os.environ['CI_PROJECT_DIR']),
reference_root_dir=reference_root,
repo_type='public',
layout=course_config.layout,
)
private_course_driver = CourseDriver(
root_dir=reference_root,
repo_type='private',
layout=course_config.layout,
use_reference_tests=True,
)
course_schedule = CourseSchedule(
deadlines_config=course_driver.get_deadlines_file_path(),
deadlines_config=private_course_driver.get_deadlines_file_path(),
)

username = os.environ['CI_PROJECT_NAME']
Expand All @@ -202,7 +210,7 @@ def grade_mrs(
grade_student_mrs(
course_config,
course_schedule,
course_driver,
public_course_driver,
gitlab_connection,
username,
dry_run=dry_run,
Expand All @@ -225,13 +233,13 @@ def grade_students_mrs(
execution_folder: Path = context['execution_folder']

root = root or execution_folder
course_driver = CourseDriver(
private_course_driver = CourseDriver(
root_dir=root,
reference_root_dir=root,
repo_type='private',
layout=course_config.layout,
)
course_schedule = CourseSchedule(
deadlines_config=course_driver.get_deadlines_file_path(),
deadlines_config=private_course_driver.get_deadlines_file_path(),
)

gitlab_connection = GitlabConnection(
Expand All @@ -242,7 +250,7 @@ def grade_students_mrs(
grade_students_mrs_to_master(
course_config,
course_schedule,
course_driver,
private_course_driver,
gitlab_connection,
dry_run=dry_run,
)
Expand All @@ -267,30 +275,39 @@ def export_public(
execution_folder: Path = context['execution_folder']

root = root or execution_folder
course_driver = CourseDriver(

export_dir = export_dir or Path(tempfile.mkdtemp())
if not export_dir.exists():
export_dir.mkdir(exist_ok=True, parents=True)

public_course_driver = CourseDriver(
root_dir=export_dir,
repo_type='public',
layout=course_config.layout,
)
private_course_driver = CourseDriver(
root_dir=root,
reference_root_dir=root,
repo_type='private',
layout=course_config.layout,
)
course_schedule = CourseSchedule(
deadlines_config=course_driver.get_deadlines_file_path(),
deadlines_config=private_course_driver.get_deadlines_file_path(),
)

export_dir = export_dir or Path(tempfile.mkdtemp())
if not export_dir.exists():
export_dir.mkdir(exist_ok=True, parents=True)

export_public_files(
course_config,
course_schedule,
course_driver,
public_course_driver,
private_course_driver,
export_dir,
dry_run=dry_run,
)

if not no_cleanup:
if no_cleanup:
print_info(f'No cleanup flag. Exported files stored in {export_dir}.')
else:
print_info(f'Cleanup flag. Export dir {export_dir} removed.')
shutil.rmtree(export_dir)
print_info(f'No cleanup flag. Exported files stored in {export_dir}')


# @main.command()
Expand Down
27 changes: 14 additions & 13 deletions checker/actions/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@
def _check_single_task(
task: Task,
tester: Tester,
course_driver: CourseDriver,
private_course_driver: CourseDriver,
verbose: bool = False,
catch_output: bool = False,
) -> str | None:
source_dir = course_driver.get_task_source_dir(task)
public_tests_dir, private_tests_dir = course_driver.get_task_test_dirs(task)
assert source_dir, f'{source_dir=} have to exists'
assert public_tests_dir, f'{public_tests_dir=} have to exists'
assert private_tests_dir, f'{private_tests_dir=} have to exists'
reference_source_dir = private_course_driver.get_task_solution_dir(task)
reference_public_tests_dir = private_course_driver.get_task_public_test_dir(task)
reference_private_tests_dir = private_course_driver.get_task_private_test_dir(task)
assert reference_source_dir, f'{reference_source_dir=} have to exists'
assert reference_public_tests_dir, f'{reference_public_tests_dir=} have to exists'
assert reference_private_tests_dir, f'{reference_private_tests_dir=} have to exists'

if catch_output:
f = io.StringIO()
with redirect_stderr(f), redirect_stdout(f):
print_task_info(task.full_name)
try:
tester.test_task(
source_dir, public_tests_dir, private_tests_dir,
reference_source_dir, reference_public_tests_dir, reference_private_tests_dir,
verbose=verbose, normalize_output=True
)
except RunFailedError as e:
Expand All @@ -43,7 +44,7 @@ def _check_single_task(
else:
print_task_info(task.full_name)
tester.test_task(
source_dir, public_tests_dir, private_tests_dir,
reference_source_dir, reference_public_tests_dir, reference_private_tests_dir,
verbose=verbose, normalize_output=True
)
return None
Expand All @@ -52,7 +53,7 @@ def _check_single_task(
def _check_tasks(
tasks: list[Task],
tester: Tester,
course_driver: CourseDriver,
private_course_driver: CourseDriver,
parallelize: bool = False,
num_processes: int | None = None,
verbose: bool = True,
Expand All @@ -66,7 +67,7 @@ def _check_tasks(
# with ThreadPoolExecutor(max_workers=num_cores) as e:
with ProcessPoolExecutor(max_workers=_num_processes) as e:
check_futures = {
e.submit(_check_single_task, task, tester, course_driver, verbose=verbose, catch_output=True)
e.submit(_check_single_task, task, tester, private_course_driver, verbose=verbose, catch_output=True)
for task in tasks
}

Expand All @@ -85,7 +86,7 @@ def _check_tasks(
else:
for task in tasks:
try:
_check_single_task(task, tester, course_driver, verbose=verbose, catch_output=False)
_check_single_task(task, tester, private_course_driver, verbose=verbose, catch_output=False)
except RunFailedError:
return False
except Exception as e:
Expand All @@ -97,7 +98,7 @@ def _check_tasks(

def pre_release_check_tasks(
course_schedule: CourseSchedule,
course_driver: CourseDriver,
private_course_driver: CourseDriver,
tester: Tester,
tasks: list[Task] | None = None,
*,
Expand All @@ -123,7 +124,7 @@ def pre_release_check_tasks(
success = _check_tasks(
tasks,
tester,
course_driver,
private_course_driver,
parallelize=parallelize,
num_processes=num_processes,
verbose=not contributing,
Expand Down
Loading

0 comments on commit b14752a

Please sign in to comment.