Skip to content

Commit

Permalink
bt pdf learns --language
Browse files Browse the repository at this point in the history
Some use cases:

    bt pdf --language da : create Danish statement
    bt pdf               : defaults to English statement

Performs some consistency checks between problem.yaml and the
statements in problem_statement/problem.*.tex

hellowholeworld in test/problems contains statements in various
language formats (and some deliberate warning-producing entries)
  • Loading branch information
thorehusfeldt committed May 12, 2023
1 parent d78017d commit 84fdb98
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 4 deletions.
3 changes: 1 addition & 2 deletions bin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
grep -Ev '^(h|jobs|time|verbose)$' | sed "s/^/'/;s/$/',/" | tr '\n' ' ' | sed 's/^/args_list = [/;s/, $/]\n/'
"""
# fmt: off
args_list = ['1', 'add_manual', 'all', 'api', 'author', 'check_deterministic', 'clean', 'clean_generated', 'cleanup_generated', 'colors', 'contest', 'contest_id', 'contestname', 'cp', 'cpp_flags', 'default_solution', 'directory', 'error', 'force', 'force_build', 'ignore_validators', 'input', 'interaction', 'interactive', 'kattis', 'memory', 'move_manual', 'move_to', 'no_bar', 'no_generate', 'no_solutions', 'no_timelimit', 'order', 'order_from_ccs', 'output', 'password', 'post_freeze', 'problem', 'problemname', 'remove', 'samples', 'skel', 'skip', 'skip_solution', 'skip_testcase_sanity_checks', 'skip_visualizer', 'submissions', 'table', 'testcases', 'timelimit', 'timeout', 'token', 'username', 'validation', 'watch', 'web']
args_list = ['1', 'add_manual', 'all', 'api', 'author', 'check_deterministic', 'clean', 'clean_generated', 'cleanup_generated', 'colors', 'contest', 'contest_id', 'contestname', 'cp', 'cpp_flags', 'default_solution', 'directory', 'error', 'force', 'force_build', 'language', 'ignore_validators', 'input', 'interaction', 'interactive', 'kattis', 'memory', 'move_manual', 'move_to', 'no_bar', 'no_generate', 'no_solutions', 'no_timelimit', 'order', 'order_from_ccs', 'output', 'password', 'post_freeze', 'problem', 'problemname', 'remove', 'samples', 'skel', 'skip', 'skip_solution', 'skip_testcase_sanity_checks', 'skip_visualizer', 'submissions', 'table', 'testcases', 'timelimit', 'timeout', 'token', 'username', 'validation', 'watch', 'web']
# fmt: on


Expand All @@ -87,7 +87,6 @@ def set_default_args():
if not hasattr(args, arg):
setattr(args, arg, value)


level = None

# The number of warnings and errors encountered.
Expand Down
3 changes: 2 additions & 1 deletion bin/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ def build_problem_pdf(problem, solutions=False):
builddir / main_file,
{
'problemlabel': problem.label,
'problemyamlname': problem.settings.name.replace('_', ' '),
'problemyamlname': problem.settings.name[problem.language].replace('_', ' '),
'problemauthor': problem.settings.author,
'timelimit': get_tl(problem),
'problemdir': problem.path.absolute().as_posix(),
'builddir': problem.tmpdir.as_posix(),
'stmlang': problem.language
},
)

Expand Down
39 changes: 39 additions & 0 deletions bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@ def __init__(self, path, tmpdir, label=None):
f'Problem has a bad shortname: {self.name} does not match {self._SHORTNAME_REGEX_STRING}'
)

self.language = self._determine_statement_language()

def _determine_statement_language(self):
"""Determine the languages that are both mentioned in the problem.yaml under name
and have a corresponding problem statement.
If problem.yaml's name key is a string, convert into dict.
From the specification:
> If a string this is the name of the problem
> in English. If a map the keys are language codes and the values are
> the name of the problem in that language. It is an error for a
> language to be missing if there exists a problem statement for that
> language.
"""
if isinstance(self.settings.name, str):
self.settings.name = {'en': self.settings.name}
statement_languages = set(
texfile.suffixes[0][1:]
for texfile in glob(self.path, 'problem_statement/problem.*.tex')
)
for lang in statement_languages:
if lang not in self.settings.name:
warn(
f"Found problem_statement/problem.{lang}.tex, but no corresponding name in problem.yaml."
)
for lang in self.settings.name:
if lang not in statement_languages:
warn(
f"Found problem name for language {lang} in problem.yaml, but no problem_statement/problem.{lang}.tex."
)

available_languages = statement_languages & set(self.settings.name)
lang = config.args.language or self.settings.language
if lang not in available_languages:
fatal(f"Unable to build statement for language {lang}")
return lang

def _read_settings(self):
# some defaults
self.settings = {
Expand All @@ -60,6 +97,7 @@ def _read_settings(self):
'validation': 'default',
'validator_flags': [],
'author': '',
'language': 'en',
}

# parse problem.yaml
Expand Down Expand Up @@ -113,6 +151,7 @@ def _read_settings(self):

self.interactive = self.settings.validation == 'custom interactive'


# Walk up from the in_path directory looking for the first testdata.yaml
# file, and return its contents, or None if no testdata.yaml is found.
def get_testdata_yaml(p, in_path):
Expand Down
1 change: 1 addition & 0 deletions bin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def build_parser():
action='store_true',
help='Create problem statements for individual problems as well.',
)
pdfparser.add_argument('--language', type=str, help='Set statement language.')
pdfparser.add_argument('--no-timelimit', action='store_true', help='Do not print timelimits.')
pdfparser.add_argument(
'--watch',
Expand Down
2 changes: 1 addition & 1 deletion latex/problem.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
\renewcommand{\problemyamlname}{{%problemyamlname%}}
\renewcommand{\problemauthor}{{%problemauthor%}}
\renewcommand{\timelimit}{{%timelimit%}}
\input{{%problemdir%}/problem_statement/problem.en.tex}
\input{{%problemdir%}/problem_statement/problem.{%stmlang%}.tex}
\input{{%builddir%}/samples.tex}
\endgroup
\end{document}
Empty file.
1 change: 1 addition & 0 deletions test/problems/hellowholeworld/data/sample/1.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
1 change: 1 addition & 0 deletions test/problems/hellowholeworld/data/sample/1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Empty file.
25 changes: 25 additions & 0 deletions test/problems/hellowholeworld/en-problem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: hello
author: DOMjudge
# BAPC 2020
source:
# 2020.bapc.eu
source_url:
license:
rights_owner:
# 'default', 'custom', or 'interactive'
validation: default

# One or more of:
# case_sensitive
# space_change_sensitive
# float_absolute_tolerance eps
# float_relative_tolerance eps
# float_tolerance eps
#validator_flags:

# To change the time limit factors for Kattis, use:
# limits:
# Time limit is 2*slowest accepted submission:
# time_multiplier: 2
# Warning for submissions within 1 second of limit:
# time_safety_margin: 1
6 changes: 6 additions & 0 deletions test/problems/hellowholeworld/problem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name:
en: Hello, Whole World!
de: Hallo, ganze Welt!
da: Hej, hele verden!
author: Thore Husfeldt
validation: default
12 changes: 12 additions & 0 deletions test/problems/hellowholeworld/problem_statement/problem.da.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\problemname{\problemyamlname}

Hils på hele verden.

\section*{Indlæsning}

Dette problem har ingen indlæsning.

\section*{Udskrift}

Udskriften består af en enkelt linje, der indeholder strengen »Hello World!«.

12 changes: 12 additions & 0 deletions test/problems/hellowholeworld/problem_statement/problem.en.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\problemname{Hello World}

Greet the world.

\section*{Input}

There is no input for this problem.

\section*{Output}

Output should contain one line, containing the string “Hello World!”.

12 changes: 12 additions & 0 deletions test/problems/hellowholeworld/problem_statement/problem.sv.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\problemname{\problemyamlname}

Hälsa på världen.

\section*{Indata}

Detta problemet har ingen inddata.

\section*{Utskrift}

Utskriften består av en enskild rad med strängen »Hello World!».

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world!")

0 comments on commit 84fdb98

Please sign in to comment.