Skip to content

Commit 32ca9ee

Browse files
committed
Completed tool chain
1 parent 4824b6b commit 32ca9ee

File tree

8 files changed

+85
-12
lines changed

8 files changed

+85
-12
lines changed

Lynx/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,26 @@
1919
# SOFTWARE.
2020

2121
import click
22+
from Lynx.utils.constants import VERSION
23+
24+
25+
def print_version(ctx, param, value):
26+
if not value or ctx.resilient_parsing:
27+
return
28+
click.echo(VERSION)
29+
ctx.exit()
2230

2331

2432
# register CLI group, must be placed before importing submodules
2533
@click.group()
34+
@click.option(
35+
"--version",
36+
is_flag=True,
37+
is_eager=True,
38+
expose_value=False,
39+
callback=print_version,
40+
help="Show the version of lynx.",
41+
)
2642
def cli():
2743
"""lynx: Next generation testcase tool set for OI / ACM contests."""
2844
pass

Lynx/modules/init.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,20 @@
2828
default="custom",
2929
help="Use a validator. You can also use the validator provided by testlib in a similar way as the checker.",
3030
)
31-
def init(problem, language, checker, validator):
31+
@click.option("--testcase", type=int, default=20, help="The number of testcases.")
32+
@click.option(
33+
"--time-limit",
34+
type=int,
35+
default=1000,
36+
help="The time limit of the problem, uses ms as unit.",
37+
)
38+
@click.option(
39+
"--memory-limit",
40+
type=int,
41+
default=512,
42+
help="The memory limit of the problem, uses MB as unit.",
43+
)
44+
def init(problem, language, checker, validator, testcase, time_limit, memory_limit):
3245
"""This command initializes a lynx problem directory."""
3346
# Turn the problem path into an absolute path
3447
if not os.path.isabs(problem):
@@ -37,4 +50,8 @@ def init(problem, language, checker, validator):
3750
if os.path.exists(problem):
3851
error_and_exit(f"Problem directory {problem} already exists.")
3952
if language in CPP_STANDARDS:
40-
cpp.init_problem(problem, language, checker, validator)
53+
cpp.init_problem(
54+
problem, language, checker, validator, testcase, time_limit, memory_limit
55+
)
56+
else: # Other languages will be supported in the future
57+
assert False # This should never happen

Lynx/utils/config.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import yaml
2+
import os
23

34

45
# Used to manage the range of variables more easily
56
# It will be replaced by some features of cyaron in the future.
67
class SubtaskManager: ...
78

89

9-
def read_config(file_path: str) -> dict: ...
10+
class CppProblemConfig:
11+
def __init__(self, problem_path: str):
12+
self.problem_path = problem_path
13+
self.problem_config_path = os.path.join(problem_path, "problem.yaml")
14+
self.testdata_config_path = os.path.join(
15+
problem_path, "testdata", "config.yaml"
16+
)
17+
18+
def init_configs(self, standard, testcase, time_limit, memory_limit): ...

Lynx/utils/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
VERSION = "2.0.1b2"
4+
35
# Some directories
46
LYNX_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
57
TEMPLATES_ROOT = os.path.join(LYNX_ROOT, "templates")

Lynx/utils/language/cpp.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import shutil
33

4-
from Lynx.utils.constants import *
54
from Lynx.utils.log import *
5+
from Lynx.utils.constants import *
6+
from Lynx.utils.config import CppProblemConfig
67

78
"""The structure of a problem directory is as follows:
89
.
@@ -20,10 +21,24 @@
2021
"""
2122

2223

23-
def init_problem(problem_path: str, standard: str, checker: str, validator: str):
24+
def init_problem(
25+
problem_path: str,
26+
standard: str,
27+
checker: str,
28+
validator: str,
29+
testcase: int,
30+
time_limit: int,
31+
memory_limit: int,
32+
):
2433
shutil.copytree(CPP_TEMPLATES_ROOT, problem_path)
2534
shutil.copyfile(
2635
os.path.join(TEMPLATES_ROOT, "generator.py"),
2736
os.path.join(problem_path, "programs", "generator.py"),
2837
)
2938
os.remove(os.path.join(problem_path, "additional_file", ".gitkeep"))
39+
if checker != "custom":
40+
...
41+
if validator != "custom":
42+
...
43+
config = CppProblemConfig(problem_path)
44+
config.init_configs(standard, testcase, time_limit, memory_limit)

Lynx/utils/log.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import click
2-
from Lynx.utils.constants import VERBOSE
32

43

54
def error(message: str) -> None:
@@ -15,5 +14,4 @@ def error_and_exit(message: str, code: int = 1) -> None:
1514

1615
def debug(message: str) -> None:
1716
"""Print a debug message."""
18-
if VERBOSE:
19-
click.echo(click.style(f"DEBUG: {message}", fg="blue"))
17+
click.echo(click.style(f"DEBUG: {message}", fg="blue"))

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ check: deps _build _check
3434
_build:
3535
rm -fR dist/
3636
python setup.py sdist build
37-
build: deps _build
37+
build: deps _build
38+
39+
publish: build
40+
twine upload dist/*

setup.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
# !/usr/bin/env python
22
from setuptools import setup, find_packages
3+
from Lynx.utils.constants import VERSION
34

45
packages = find_packages()
56

7+
# CPP templates
8+
packages += [
9+
"Lynx.templates",
10+
"Lynx.templates.cpp",
11+
"Lynx.templates.cpp.programs",
12+
"Lynx.templates.cpp.testdata",
13+
"Lynx.templates.cpp.additional_file",
14+
]
15+
16+
# testlib
17+
packages += ["testlib", "testlib.checkers", "testlib.validators"]
18+
619
setup(
7-
name="lynx",
8-
version="2.0.1b0",
20+
name="pyLynx",
21+
version=VERSION,
922
keywords="olympic informatics testcase testcase-tools tools",
1023
description="lynx: Next generation high performance testcase tool set for OI / ACM contests. - 新一代信息学竞赛数据生成工具集",
1124
license="MIT",
@@ -15,7 +28,7 @@
1528
packages=packages,
1629
include_package_data=True,
1730
platforms="any",
18-
install_requires=["Click", "cyaron", "tqdm"],
31+
install_requires=["Click", "cyaron", "tqdm", "PyYAML"],
1932
entry_points="""
2033
[console_scripts]
2134
lynx=Lynx:cli

0 commit comments

Comments
 (0)