Skip to content

Commit

Permalink
Change validate import from path extention to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Barabanov committed Aug 21, 2023
1 parent 675cda9 commit d31bef8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions hworker/check/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from ..log import get_logger
from ..config import get_check_directory, get_validator_name, get_version_validator_name

import time
from importlib.util import module_from_spec, spec_from_file_location
from datetime import datetime
from importlib import import_module


def validate_wo_store(validator: Check, solution: Solution, check_num: int = 0) -> CheckResult:
Expand All @@ -21,14 +20,14 @@ def validate_wo_store(validator: Check, solution: Solution, check_num: int = 0)
:return:
"""
# TODO: add check nums for parallel work
if get_check_directory() not in sys.path:
sys.path.append(get_check_directory())

name, b = list(validator.content.items())[0]
module_path = Path(get_check_directory()) / name
with open(module_path, "wb") as m:
m.write(b)
module = import_module(name.rpartition(".")[0])

spec = spec_from_file_location(name.rpartition(".")[0], module_path)
module = module_from_spec(spec)
spec.loader.exec_module(module)

validator_type = None
if get_validator_name() in dir(module):
Expand Down

0 comments on commit d31bef8

Please sign in to comment.