kattis2canvas 0.1.7__tar.gz → 0.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kattis2canvas
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: CLI tool to integrate Kattis offerings with Canvas LMS courses
5
5
  Author: bcr33d
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "kattis2canvas"
7
- version = "0.1.7"
7
+ version = "0.1.8"
8
8
  description = "CLI tool to integrate Kattis offerings with Canvas LMS courses"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -2,6 +2,7 @@ import collections
2
2
  import concurrent.futures
3
3
  import configparser
4
4
  import datetime
5
+ import html
5
6
  import os
6
7
  import re
7
8
  import sys
@@ -476,6 +477,38 @@ def download_submission(url):
476
477
  def sanitize(name):
477
478
  return re.sub(r"[^\w.]", "_", name)
478
479
 
480
+
481
+ def get_submission_source(url: str) -> tuple[str, str] | None:
482
+ """
483
+ Download the source code of a submission if it's less than 8KB.
484
+ Returns (filename, source_code) tuple or None if file is too large or not found.
485
+ """
486
+ try:
487
+ rsp = web_get(f"https://{config.kattis_hostname}{url}?tab=submitted-files")
488
+ bs = BeautifulSoup(rsp.content, 'html.parser')
489
+ src_div = bs.find(class_="file_source-content-file", recursive=True)
490
+ if not src_div:
491
+ return None
492
+
493
+ h3 = src_div.find("h3")
494
+ filename = os.path.basename(h3.get_text().strip()) if h3 else "source"
495
+
496
+ # Find the source-highlight div containing the actual code
497
+ code_elem = bs.find(class_="source-highlight", recursive=True)
498
+ if not code_elem:
499
+ return None
500
+
501
+ source_code = code_elem.get_text()
502
+
503
+ # Check if less than 8KB
504
+ if len(source_code.encode('utf-8')) > 8 * 1024:
505
+ return None
506
+
507
+ return (filename, source_code)
508
+ except Exception as e:
509
+ warn(f"failed to get source for {url}: {e}")
510
+ return None
511
+
479
512
  def get_course(canvas, name, is_active=True) -> Course:
480
513
  """ find one course based on partial match """
481
514
  course_list = get_courses(canvas, name, is_active)
@@ -813,13 +846,21 @@ def submissions2canvas(offering, canvas_course, dryrun, assignment_group, sectio
813
846
  elif user not in kattis_user2canvas_id:
814
847
  warn(f'skipping submission for unknown user {user}')
815
848
  elif kattis_submission.date > submissions_by_user[user].last_comment or force_comment:
849
+ href_url = f"https://{config.kattis_hostname}{kattis_submission.url}"
850
+ comment_text = f"{prefix}Submission <a href={href_url}>{href_url}</a> scored {kattis_submission.score} on {kattis_submission.problem}."
851
+
852
+ # Try to include source code if < 8KB
853
+ source_info = get_submission_source(kattis_submission.url)
854
+ if source_info:
855
+ filename, source_code = source_info
856
+ comment_text += f"\n<br/>\n<strong>{html.escape(filename)}</strong>\n<pre>{html.escape(source_code)}</pre>"
857
+
816
858
  if dryrun:
817
- warn(
818
- f"would update {kattis_user2canvas_id[kattis_submission.user]} on problem {kattis_submission.problem} scored {kattis_submission.score}")
859
+ warn(f"would update {kattis_user2canvas_id[kattis_submission.user]} on problem {kattis_submission.problem}:")
860
+ print(comment_text)
861
+ print("---")
819
862
  else:
820
- href_url = f"https://{config.kattis_hostname}{kattis_submission.url}"
821
- submissions_by_user[user].edit(comment={
822
- 'text_comment': f"{prefix}Submission <a href={href_url}>{href_url}</a> scored {kattis_submission.score} on {kattis_submission.problem}."})
863
+ submissions_by_user[user].edit(comment={'text_comment': comment_text})
823
864
  info(
824
865
  f"updated {submissions_by_user[user]} {kattis_user2canvas_id[kattis_submission.user]} for {assignment.title}")
825
866
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kattis2canvas
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: CLI tool to integrate Kattis offerings with Canvas LMS courses
5
5
  Author: bcr33d
6
6
  License-Expression: MIT
File without changes
File without changes