Skip to content

Commit

Permalink
Remove GitHub API Call (#67)
Browse files Browse the repository at this point in the history
* Remove github call

* Remove dead code

---------

Co-authored-by: Gregory Bell <[email protected]>
  • Loading branch information
gregbell26 and Gregory Bell authored Jan 16, 2024
1 parent c518e92 commit 8b46b34
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 48 deletions.
20 changes: 1 addition & 19 deletions source/utils/config/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,39 +116,21 @@ class AutograderConfigurationSchema(BaseSchema[AutograderConfiguration]):
This class builds to :ref:`AutograderConfiguration` for easy typing.
"""
TAGS_ENDPOINT = "https://api.github.com/repos/CSCI128/128Autograder/tags"
IMPL_SOURCE = "./StudentSubmissionImpl"

@staticmethod
def getAvailableTags() -> List[str]:
"""
Description
---
This method gets the currently available version tags from GitHub.
This ensures that any version of the autorgader is using a spefic version of the autograder.
:return: a list of all the valid tags from GitHub
"""
headers = {"X-GitHub-Api-Version": "2022-11-28"}

tags = requests.get(url=AutograderConfigurationSchema.TAGS_ENDPOINT, headers=headers).json()

return [el["name"] for el in tags]

@staticmethod
def validateImplSource(implName: str) -> bool:
return implName in os.listdir(AutograderConfigurationSchema.IMPL_SOURCE)

def __init__(self):
self.TAGS = self.getAvailableTags()

self.currentSchema: Schema = Schema(
{
"assignment_name": And(str, Regex(r"^(\w+-?)+$")),
"semester": And(str, Regex(r"^(F|S|SUM)\d{2}$")),
"config": {
"impl_to_use": And(str, AutograderConfigurationSchema.validateImplSource),
Optional("student_submission_directory", default="."): And(str, os.path.exists, os.path.isdir),
"autograder_version": And(str, lambda x: x in self.TAGS),
"autograder_version": And(str, Regex(r"\d+\.\d+\.\d+")),
"test_directory": And(str, os.path.exists),
"enforce_submission_limit": bool,
Optional("submission_limit", default=1000): And(int, lambda x: x >= 1),
Expand Down
12 changes: 5 additions & 7 deletions source/utils/student/test_my_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SUBMISSION_REGEX: re.Pattern = re.compile(r"^(\w|\s)+\.py$")
FILE_HASHES_NAME: str = ".filehashes"

REQUIRED_PACKAGES = {"gradescope_utils":"gradescope-utils", "dill":"dill", "BetterPytUnitFormat":"Better-PyUnit-Format", "schema":"schema", "requests":"requests", "tomli":"tomli"}
REQUIRED_PACKAGES = {"gradescope_utils":"gradescope-utils", "dill":"dill", "BetterPyUnitFormat":"Better-PyUnit-Format", "schema":"schema", "requests":"requests", "tomli":"tomli"}

def printErrorMessage(errorType: str, errorText: str) -> None:
"""
Expand All @@ -40,8 +40,9 @@ def verifyRequiredPackages(packagesToVerify: dict[str, str]) -> bool:

for name, package in packagesToVerify.items():
if importlib.util.find_spec(name) is None:
print(f"Installing missing dependancy: {package}")
subprocess.run([sys.executable, "-m", "pip", "install", package])
print(f"Installing missing dependancy: {package}...", end="")
subprocess.run([sys.executable, "-m", "pip", "install", package], stdout=subprocess.DEVNULL)
print(f"Done.")

return not errorOccurred

Expand Down Expand Up @@ -157,10 +158,7 @@ def verifyFileChanged(submissionDirectory: str) -> bool:

command: list[str] = [sys.executable, "run.py", "--unit-test-only", "--submission-directory", submissionDirectory]

with subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
if p.stdout is not None:
for line in p.stdout:
print(line, end="")
subprocess.run(command)

if not fileChanged:
printWarningMessage("Student Submission Warning", "Student submision may not have changed")
25 changes: 3 additions & 22 deletions tests/testAutograderConfigurationSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@
from utils.config.Config import AutograderConfigurationSchema, InvalidConfigException


def mockRequestsGet(url, **kwargs):
class Response:
def __init__(self, jsonData, status: int):
self.jsonData = jsonData
self.statusCode = status

def json(self):
return self.jsonData

if re.match(r"https://api\.github\.com/repos/(\w|\d)+/(\w|\d)+/tags", url):
data = \
[
{"name": "1.0.0"},
{"name": "2.0.0"}
]

return Response(data, 200)

def mockValidateImpl(_) -> bool: return True

class TestAutograderConfigurationSchema(unittest.TestCase):
Expand Down Expand Up @@ -51,9 +33,8 @@ def setUp(self) -> None:

@staticmethod
def createAutograderConfigurationSchema() -> AutograderConfigurationSchema:
with mock.patch('requests.get', side_effect=mockRequestsGet):
AutograderConfigurationSchema.validateImplSource = mockValidateImpl # type: ignore
return AutograderConfigurationSchema()
AutograderConfigurationSchema.validateImplSource = mockValidateImpl # type: ignore
return AutograderConfigurationSchema()

def testValidNoOptionalFields(self):
schema = self.createAutograderConfigurationSchema()
Expand Down Expand Up @@ -98,7 +79,7 @@ def testExtraFields(self):
def testInvalidAutograderVersion(self):
schema = self.createAutograderConfigurationSchema()

self.configFile["config"]["autograder_version"] = "0.0.0"
self.configFile["config"]["autograder_version"] = "0.0"

with self.assertRaises(InvalidConfigException):
schema.validate(self.configFile)
Expand Down

0 comments on commit 8b46b34

Please sign in to comment.