Skip to content

Commit

Permalink
feat: rebuild Driver to have public and private different layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
k4black committed Sep 3, 2023
1 parent c6e294b commit 7ee485d
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 219 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(

Check warning on line 88 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L88

Added line #L88 was not covered by tests
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(

Check warning on line 146 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L146

Added line #L146 was not covered by tests
root_dir=Path(os.environ['CI_PROJECT_DIR']),
reference_root_dir=reference_root,
repo_type='public',
layout=course_config.layout,
)
private_course_driver = CourseDriver(

Check warning on line 151 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L151

Added line #L151 was not covered by tests
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(

Check warning on line 189 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L189

Added line #L189 was not covered by tests
root_dir=Path(os.environ['CI_PROJECT_DIR']),
reference_root_dir=reference_root,
repo_type='public',
layout=course_config.layout,
)
private_course_driver = CourseDriver(

Check warning on line 194 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L194

Added line #L194 was not covered by tests
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(

Check warning on line 236 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L236

Added line #L236 was not covered by tests
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)

Check warning on line 281 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L279-L281

Added lines #L279 - L281 were not covered by tests

public_course_driver = CourseDriver(

Check warning on line 283 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L283

Added line #L283 was not covered by tests
root_dir=export_dir,
repo_type='public',
layout=course_config.layout,
)
private_course_driver = CourseDriver(

Check warning on line 288 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L288

Added line #L288 was not covered by tests
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}.')

Check warning on line 307 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L306-L307

Added lines #L306 - L307 were not covered by tests
else:
print_info(f'Cleanup flag. Export dir {export_dir} removed.')

Check warning on line 309 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L309

Added line #L309 was not covered by tests
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'

Check warning on line 27 in checker/actions/check.py

View check run for this annotation

Codecov / codecov/patch

checker/actions/check.py#L22-L27

Added lines #L22 - L27 were not covered by tests

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)

Check warning on line 89 in checker/actions/check.py

View check run for this annotation

Codecov / codecov/patch

checker/actions/check.py#L89

Added line #L89 was not covered by tests
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 7ee485d

Please sign in to comment.