Skip to content

Commit

Permalink
Run Python programs as a module
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinXPN authored May 16, 2024
1 parent 6a3029b commit 13ac80a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions coderunners/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def compile(self, submission_paths: list[Path]):
binary_paths = [path.with_suffix('.pyc') for path in submission_paths]
submission_paths_str = ' '.join([str(path) for path in submission_paths])
main_file_path = self.find_main_file_path(submission_paths, self.MAIN_FILE_NAME)
command = f'{self.language_standard} {main_file_path}'
main_module_path = '.'.join(str(main_file_path).split('/')[2:]).removesuffix('.py')
command = f'{self.language_standard} -m {main_module_path}'
print('Command:', command)

print('Creating python binary at:', binary_paths)
compile_res = Process(f'{self.language_standard} -m py_compile {submission_paths_str}',
Expand All @@ -144,7 +146,9 @@ def compile(self, submission_paths: list[Path]):
binary_paths = [path.with_suffix('.pyc') for path in submission_paths]
submission_paths_str = ' '.join([str(path) for path in submission_paths])
main_file_path = self.find_main_file_path(submission_paths, self.MAIN_FILE_NAME)
command = f'python {main_file_path}'
main_module_path = '.'.join(str(main_file_path).split('/')[2:]).removesuffix('.py')
command = f'python -m {main_module_path}'
print('Command:', command)

print('Creating python binary at:', binary_paths)
compile_res = Process(f'python -m py_compile {submission_paths_str}', timeout=10, memory_limit_mb=512).run()
Expand Down

0 comments on commit 13ac80a

Please sign in to comment.