-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental domjudge_package rule (#5)
- Loading branch information
Showing
9 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def domjudge_package(name, metadata, dataset, statements = [], **kwargs): | ||
out = name + ".zip" | ||
args = [ | ||
"'$(execpath @rules_contest//contest/impls:domjudge_package)'", | ||
"--output='$@'", | ||
"--metadata='$(execpath " + metadata + ")'", | ||
"--dataset='$(execpath " + dataset + ")'", | ||
] | ||
for statement in statements: | ||
args.append("--statement='$(execpath " + statement + ")'") | ||
native.genrule( | ||
name = name, | ||
outs = [out], | ||
srcs = [metadata, dataset] + statements, | ||
tools = ["@rules_contest//contest/impls:domjudge_package"], | ||
cmd = " ".join(args), | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import argparse | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import yaml | ||
|
||
from contest.impls import datasets | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--output', required=True) | ||
parser.add_argument('--metadata', required=True) | ||
parser.add_argument('--statements', action='append') | ||
parser.add_argument('--dataset', required=True) | ||
options = parser.parse_args() | ||
|
||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
with open(options.metadata, 'r') as f: | ||
# Make sure the metadata YAML is well-formed. | ||
yaml.safe_load(f) | ||
shutil.copy(options.metadata, os.path.join(tmp_dir, 'problem.yaml')) | ||
|
||
for statement in options.statements: | ||
assert statement.endswith(('.html', '.pdf')) | ||
statement_ext = statement.split('.')[-1] | ||
shutil.copy( | ||
statement, | ||
os.path.join(tmp_dir, 'problem.%s' % statement_ext)) | ||
|
||
dataset_dir = os.path.join(tmp_dir, 'data', 'secret') | ||
os.makedirs(dataset_dir) | ||
datasets.extract(options.dataset, dataset_dir) | ||
|
||
# TODO: Do not reuse datasets.create to create a problem ZIP archive. | ||
datasets.create(tmp_dir, options.output) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: Square root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: Sum of two numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Sum two numbers | ||
# Sum of two numbers | ||
|
||
Compute the sum of two numbers. | ||
|
||
|