Skip to content

Commit 4c93026

Browse files
committed
Rename TOOLS_ROOT to RESOURCES_ROOT
1 parent deb0475 commit 4c93026

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

bapctools/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pathlib import Path
1010
from typing import Any, Final, Literal, Optional, TypeVar
1111

12+
import bapctools
13+
1214
# Randomly generated uuid4 for BAPCtools
1315
BAPC_UUID: Final[str] = "8ee7605a-d1ce-47b3-be37-15de5acd757e"
1416
BAPC_UUID_PREFIX: Final[int] = 8
@@ -98,14 +100,14 @@
98100

99101
SEED_DEPENDENCY_RETRIES: Final[int] = 10
100102

101-
# The root directory of the BAPCtools repository.
102-
TOOLS_ROOT: Final[Path] = Path(__file__).absolute().parent.parent
103+
# The directory containing all non-python resources
104+
RESOURCES_ROOT: Final[Path] = Path(bapctools.__file__).parent / "resources"
103105

104106
# The directory from which BAPCtools is invoked.
105107
current_working_directory: Final[Path] = Path.cwd().absolute()
106108

107109
# Add third_party/ to the $PATH for checktestdata.
108-
os.environ["PATH"] += os.pathsep + str(TOOLS_ROOT / "third_party")
110+
os.environ["PATH"] += os.pathsep + str(RESOURCES_ROOT / "third_party")
109111

110112
# Below here is some global state that will be filled in main().
111113

bapctools/latex.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def make_environment(builddir: Path) -> dict[str, str]:
237237
cwd / "solve_stats",
238238
cwd / "solve_stats" / "activity",
239239
cwd / "latex",
240-
config.TOOLS_ROOT / "latex",
240+
config.RESOURCES_ROOT / "latex",
241241
# The default empty element at the end makes sure that the new TEXINPUTS ends with a path separator.
242242
# This is required to make LaTeX look in the default global paths: https://tex.stackexchange.com/a/410353
243243
env.get("TEXINPUTS", ""),
@@ -382,7 +382,7 @@ def build_problem_pdf(
382382

383383
local_data = Path(main_file)
384384
copy_and_substitute(
385-
local_data if local_data.is_file() else config.TOOLS_ROOT / "latex" / main_file,
385+
local_data if local_data.is_file() else config.RESOURCES_ROOT / "latex" / main_file,
386386
builddir / main_file,
387387
problem_data(problem, language),
388388
bar=bar,
@@ -426,7 +426,7 @@ def find_logo() -> Path:
426426
logo = Path(directory + "logo." + extension)
427427
if logo.exists():
428428
return logo
429-
return config.TOOLS_ROOT / "latex" / "images" / "logo-not-found.pdf"
429+
return config.RESOURCES_ROOT / "latex" / "images" / "logo-not-found.pdf"
430430

431431

432432
def build_contest_pdf(
@@ -465,7 +465,7 @@ def build_contest_pdf(
465465
(
466466
local_contest_data
467467
if local_contest_data.is_file()
468-
else config.TOOLS_ROOT / "latex" / "contest_data.tex"
468+
else config.RESOURCES_ROOT / "latex" / "contest_data.tex"
469469
),
470470
builddir / "contest_data.tex",
471471
config_data,
@@ -487,7 +487,7 @@ def build_contest_pdf(
487487
per_problem_data_tex = (
488488
local_per_problem_data
489489
if local_per_problem_data.is_file()
490-
else config.TOOLS_ROOT / "latex" / local_per_problem_data.name
490+
else config.RESOURCES_ROOT / "latex" / local_per_problem_data.name
491491
).read_text()
492492

493493
for prob in problems:

bapctools/problem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ def _validators(
11061106
if problem.custom_output:
11071107
paths = [problem.path / validate.OutputValidator.source_dir]
11081108
else:
1109-
paths = [config.TOOLS_ROOT / "support" / "default_output_validator.cpp"]
1109+
paths = [config.RESOURCES_ROOT / "support" / "default_output_validator.cpp"]
11101110
else:
11111111
paths = list(glob(problem.path / cls.source_dir, "*"))
11121112

bapctools/program.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def languages() -> Sequence[Language]:
149149
if Path("languages.yaml").is_file():
150150
raw_languages = read_yaml(Path("languages.yaml"))
151151
else:
152-
raw_languages = read_yaml(config.TOOLS_ROOT / "config/languages.yaml")
152+
raw_languages = read_yaml(config.RESOURCES_ROOT / "config/languages.yaml")
153153
if not isinstance(raw_languages, dict):
154154
fatal("could not parse languages.yaml.")
155155

@@ -370,7 +370,7 @@ def _get_language(self, bar: ProgressBar) -> bool:
370370
self.tmpdir / "build" if (self.tmpdir / "build") in self.input_files else ""
371371
),
372372
"run": self.tmpdir / "run",
373-
"viva_jar": config.TOOLS_ROOT / "third_party/viva/viva.jar",
373+
"viva_jar": config.RESOURCES_ROOT / "third_party/viva/viva.jar",
374374
}
375375

376376
return True

bapctools/skel.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def new_contest() -> None:
6363
rights_owner = f"rights_owner: {rights_owner}\n" if rights_owner else ""
6464
title = title.replace("_", "-")
6565

66-
skeldir = config.TOOLS_ROOT / "skel/contest"
66+
skeldir = config.RESOURCES_ROOT / "skel/contest"
6767
log(f"Copying {skeldir} to {dirname}.")
6868
copytree_and_substitute(
6969
skeldir, Path(dirname), locals(), exist_ok=False, preserve_symlinks=False
7070
)
7171

7272

7373
def get_skel_dir(target_dir: Path) -> tuple[Path, bool]:
74-
skeldir = config.TOOLS_ROOT / "skel/problem"
74+
skeldir = config.RESOURCES_ROOT / "skel/problem"
7575
preserve_symlinks = False
7676
if (target_dir / "skel/problem").is_dir():
7777
skeldir = target_dir / "skel/problem"
@@ -303,12 +303,12 @@ def problem_source_dir(problem: Problem) -> Path:
303303
return problem.path.absolute().relative_to(git_root_path)
304304

305305
if config.args.latest_bt:
306-
header_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/header_latest_bt.yaml").read_text()
306+
header_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/header_latest_bt.yaml").read_text()
307307
else:
308-
header_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/header_docker_bt.yaml").read_text()
308+
header_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/header_docker_bt.yaml").read_text()
309309
print(header_yml)
310310

311-
contest_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/contest.yaml").read_text()
311+
contest_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/contest.yaml").read_text()
312312
contest_path = Path(".").absolute().relative_to(git_root_path)
313313
changes = "".join(
314314
f" - {problem_source_dir(problem)}/{pdf_type.path().parent}/**/*\n"
@@ -321,7 +321,7 @@ def problem_source_dir(problem: Problem) -> Path:
321321
)
322322
)
323323

324-
problem_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/problem.yaml").read_text()
324+
problem_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/problem.yaml").read_text()
325325
for problem_obj in problems:
326326
problem_path = problem_source_dir(problem_obj)
327327
problem = problem_obj.name
@@ -343,9 +343,9 @@ def create_forgejo_actions(contest: str, problems: list[Problem]) -> None:
343343
fatal(".git and ../.git not found after changing to contest directory.")
344344

345345
if config.args.latest_bt:
346-
src = config.TOOLS_ROOT / "skel/forgejo_actions_latest_bt"
346+
src = config.RESOURCES_ROOT / "skel/forgejo_actions_latest_bt"
347347
else:
348-
src = config.TOOLS_ROOT / "skel/forgejo_actions_docker_bt"
348+
src = config.RESOURCES_ROOT / "skel/forgejo_actions_docker_bt"
349349

350350
if config.args.latest_bt:
351351
# Copy the 'setup' action:
@@ -395,7 +395,7 @@ def create_github_actions(contest: str, problems: list[Problem]) -> None:
395395

396396
# Copy the contest-level workflow.
397397
contest_workflow_source = (
398-
config.TOOLS_ROOT / "skel/forgejo_actions_docker_bt/contest.yaml"
398+
config.RESOURCES_ROOT / "skel/forgejo_actions_docker_bt/contest.yaml"
399399
).read_text()
400400
contest_workflow = substitute(
401401
contest_workflow_source, {"contest": contest, "contest_path": str(contest_path)}
@@ -409,7 +409,7 @@ def create_github_actions(contest: str, problems: list[Problem]) -> None:
409409

410410
# Copy the problem-level workflows.
411411
problem_workflow_source = (
412-
config.TOOLS_ROOT / "skel/forgejo_actions_docker_bt/problem.yaml"
412+
config.RESOURCES_ROOT / "skel/forgejo_actions_docker_bt/problem.yaml"
413413
).read_text()
414414
for problem_obj in problems:
415415
problem = problem_obj.name

0 commit comments

Comments
 (0)