Skip to content

Commit

Permalink
Rename MemoryIO *_fd to *_io
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 committed Dec 30, 2024
1 parent 6ad987d commit 315ede5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dmoj/checkers/bridged.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def check(
args_format_string = args_format_string or contrib_modules[type].ContribModule.get_checker_args_format_string()

with mktemp(process_output) as output_file, mktemp(judge_output) as answer_file:
input_path = case.input_data_fd().to_path()
input_path = case.input_data_io().to_path()

checker_args = shlex.split(
args_format_string.format(
Expand Down
2 changes: 1 addition & 1 deletion dmoj/graders/bridged.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _interact_with_process(self, case: TestCase, result: Result) -> bytes:
)

with mktemp(judge_output) as answer_file:
input_path = case.input_data_fd().to_path()
input_path = case.input_data_io().to_path()

# TODO(@kirito): testlib.h expects a file they can write to,
# but we currently don't have a sane way to allow this.
Expand Down
2 changes: 1 addition & 1 deletion dmoj/graders/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StandardGrader(BaseGrader):
def grade(self, case: TestCase) -> Result:
result = Result(case)

input_file = case.input_data_fd()
input_file = case.input_data_io()

self._launch_process(case, input_file)

Expand Down
22 changes: 11 additions & 11 deletions dmoj/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class TestCase(BaseTestCase):
batch: int
output_prefix_length: int
has_binary_data: bool
_input_data_fd: Optional[MmapableIO]
_input_data_io: Optional[MmapableIO]
_generated: Optional[Tuple[MmapableIO, bytes]]

def __init__(self, count: int, batch_no: int, config: ConfigNode, problem: Problem):
Expand All @@ -356,7 +356,7 @@ def __init__(self, count: int, batch_no: int, config: ConfigNode, problem: Probl
self.output_prefix_length = config.output_prefix_length
self.has_binary_data = config.binary_data
self._generated = None
self._input_data_fd = None
self._input_data_io = None

def _normalize(self, data: bytes) -> bytes:
# Perhaps the correct answer may be 'no output', in which case it'll be
Expand Down Expand Up @@ -454,16 +454,16 @@ def _run_generator(self, gen: Union[str, ConfigNode], args: Optional[Iterable[st
parse_helper_file_error(proc, executor, 'generator', stderr, time_limit, memory_limit)

def input_data(self) -> bytes:
return self.input_data_fd().to_bytes()
return self.input_data_io().to_bytes()

def input_data_fd(self) -> MmapableIO:
if self._input_data_fd:
return self._input_data_fd
def input_data_io(self) -> MmapableIO:
if self._input_data_io:
return self._input_data_io

result = self._input_data_fd = self._make_input_data_fd()
result = self._input_data_io = self._make_input_data_io()
return result

def _make_input_data_fd(self) -> MmapableIO:
def _make_input_data_io(self) -> MmapableIO:
gen = self.config.generator

# don't try running the generator if we specify an output file explicitly,
Expand Down Expand Up @@ -516,15 +516,15 @@ def checker(self) -> partial:

def free_data(self) -> None:
self._generated = None
if self._input_data_fd:
self._input_data_fd.close()
if self._input_data_io:
self._input_data_io.close()

def __str__(self) -> str:
return f'TestCase(in={self.config["in"]},out={self.config["out"]},points={self.config["points"]})'

# FIXME(tbrindus): this is a hack working around the fact we can't pickle these fields, but we do need parts of
# TestCase itself on the other end of the IPC.
_pickle_blacklist = ('_generated', 'config', 'problem', '_input_data_fd')
_pickle_blacklist = ('_generated', 'config', 'problem', '_input_data_io')

def __getstate__(self) -> dict:
k = {k: v for k, v in self.__dict__.items() if k not in self._pickle_blacklist}
Expand Down

0 comments on commit 315ede5

Please sign in to comment.