Skip to content

Commit c8c80b3

Browse files
committed
Rename TOOLS_ROOT to RESOURCES_ROOT
1 parent 52f41ca commit c8c80b3

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
@@ -236,7 +236,7 @@ def make_environment() -> dict[str, str]:
236236
Path.cwd() / "solve_stats",
237237
Path.cwd() / "solve_stats" / "activity",
238238
Path.cwd() / "latex",
239-
config.TOOLS_ROOT / "latex",
239+
config.RESOURCES_ROOT / "latex",
240240
# The default empty element at the end makes sure that the new TEXINPUTS ends with a path separator.
241241
# This is required to make LaTeX look in the default global paths: https://tex.stackexchange.com/a/410353
242242
env.get("TEXINPUTS", ""),
@@ -381,7 +381,7 @@ def build_problem_pdf(
381381

382382
local_data = Path(main_file)
383383
copy_and_substitute(
384-
local_data if local_data.is_file() else config.TOOLS_ROOT / "latex" / main_file,
384+
local_data if local_data.is_file() else config.RESOURCES_ROOT / "latex" / main_file,
385385
builddir / main_file,
386386
problem_data(problem, language),
387387
bar=bar,
@@ -425,7 +425,7 @@ def find_logo() -> Path:
425425
logo = Path(directory + "logo." + extension)
426426
if logo.exists():
427427
return logo
428-
return config.TOOLS_ROOT / "latex" / "images" / "logo-not-found.pdf"
428+
return config.RESOURCES_ROOT / "latex" / "images" / "logo-not-found.pdf"
429429

430430

431431
def build_contest_pdf(
@@ -467,7 +467,7 @@ def build_contest_pdf(
467467
(
468468
local_contest_data
469469
if local_contest_data.is_file()
470-
else config.TOOLS_ROOT / "latex" / "contest_data.tex"
470+
else config.RESOURCES_ROOT / "latex" / "contest_data.tex"
471471
),
472472
builddir / "contest_data.tex",
473473
config_data,
@@ -489,7 +489,7 @@ def build_contest_pdf(
489489
per_problem_data_tex = (
490490
local_per_problem_data
491491
if local_per_problem_data.is_file()
492-
else config.TOOLS_ROOT / "latex" / local_per_problem_data.name
492+
else config.RESOURCES_ROOT / "latex" / local_per_problem_data.name
493493
).read_text()
494494

495495
for prob in problems:

bapctools/problem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def _validators(
10991099
if problem.custom_output:
11001100
paths = [problem.path / validate.OutputValidator.source_dir]
11011101
else:
1102-
paths = [config.TOOLS_ROOT / "support" / "default_output_validator.cpp"]
1102+
paths = [config.RESOURCES_ROOT / "support" / "default_output_validator.cpp"]
11031103
else:
11041104
paths = list(glob(problem.path / cls.source_dir, "*"))
11051105

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

@@ -372,7 +372,7 @@ def _get_language(self, bar: ProgressBar) -> bool:
372372
self.tmpdir / "build" if (self.tmpdir / "build") in self.input_files else ""
373373
),
374374
"run": self.tmpdir / "run",
375-
"viva_jar": config.TOOLS_ROOT / "third_party/viva/viva.jar",
375+
"viva_jar": config.RESOURCES_ROOT / "third_party/viva/viva.jar",
376376
}
377377

378378
return True

bapctools/skel.py

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

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

7171

7272
def get_skel_dir(target_dir: Path) -> tuple[Path, bool]:
73-
skeldir = config.TOOLS_ROOT / "skel/problem"
73+
skeldir = config.RESOURCES_ROOT / "skel/problem"
7474
preserve_symlinks = False
7575
if (target_dir / "skel/problem").is_dir():
7676
skeldir = target_dir / "skel/problem"
@@ -311,12 +311,12 @@ def problem_source_dir(problem: Problem) -> Path:
311311
return problem.path.absolute().relative_to(git_root_path)
312312

313313
if config.args.latest_bt:
314-
header_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/header_latest_bt.yaml").read_text()
314+
header_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/header_latest_bt.yaml").read_text()
315315
else:
316-
header_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/header_docker_bt.yaml").read_text()
316+
header_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/header_docker_bt.yaml").read_text()
317317
print(header_yml)
318318

319-
contest_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/contest.yaml").read_text()
319+
contest_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/contest.yaml").read_text()
320320
contest_path = Path(".").absolute().relative_to(git_root_path)
321321
changes = "".join(
322322
f" - {problem_source_dir(problem)}/{pdf_type.path().parent}/**/*\n"
@@ -329,7 +329,7 @@ def problem_source_dir(problem: Problem) -> Path:
329329
)
330330
)
331331

332-
problem_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/problem.yaml").read_text()
332+
problem_yml = (config.RESOURCES_ROOT / "skel/gitlab_ci/problem.yaml").read_text()
333333
for problem_obj in problems:
334334
problem_path = problem_source_dir(problem_obj)
335335
problem = problem_obj.name
@@ -351,9 +351,9 @@ def create_forgejo_actions(contest: str, problems: list[Problem]) -> None:
351351
fatal(".git and ../.git not found after changing to contest directory.")
352352

353353
if config.args.latest_bt:
354-
src = config.TOOLS_ROOT / "skel/forgejo_actions_latest_bt"
354+
src = config.RESOURCES_ROOT / "skel/forgejo_actions_latest_bt"
355355
else:
356-
src = config.TOOLS_ROOT / "skel/forgejo_actions_docker_bt"
356+
src = config.RESOURCES_ROOT / "skel/forgejo_actions_docker_bt"
357357

358358
if config.args.latest_bt:
359359
# Copy the 'setup' action:
@@ -403,7 +403,7 @@ def create_github_actions(contest: str, problems: list[Problem]) -> None:
403403

404404
# Copy the contest-level workflow.
405405
contest_workflow_source = (
406-
config.TOOLS_ROOT / "skel/forgejo_actions_docker_bt/contest.yaml"
406+
config.RESOURCES_ROOT / "skel/forgejo_actions_docker_bt/contest.yaml"
407407
).read_text()
408408
contest_workflow = substitute(
409409
contest_workflow_source, {"contest": contest, "contest_path": str(contest_path)}
@@ -417,7 +417,7 @@ def create_github_actions(contest: str, problems: list[Problem]) -> None:
417417

418418
# Copy the problem-level workflows.
419419
problem_workflow_source = (
420-
config.TOOLS_ROOT / "skel/forgejo_actions_docker_bt/problem.yaml"
420+
config.RESOURCES_ROOT / "skel/forgejo_actions_docker_bt/problem.yaml"
421421
).read_text()
422422
for problem_obj in problems:
423423
problem = problem_obj.name

0 commit comments

Comments
 (0)