From e5069826d4df6ea61ea71ce8055ebe9122ca94bc Mon Sep 17 00:00:00 2001 From: mzuenni Date: Sat, 29 Mar 2025 17:35:52 +0100 Subject: [PATCH 1/3] use more absolute --- bin/config.py | 4 ++-- bin/problem.py | 2 +- bin/skel.py | 6 +++--- bin/tools.py | 4 ++-- bin/util.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/config.py b/bin/config.py index 026cb965..49f54603 100644 --- a/bin/config.py +++ b/bin/config.py @@ -92,10 +92,10 @@ SEED_DEPENDENCY_RETRIES: Final[int] = 10 # The root directory of the BAPCtools repository. -TOOLS_ROOT: Final[Path] = Path(__file__).resolve().parent.parent +TOOLS_ROOT: Final[Path] = Path(__file__).absolute().parent.parent # The directory from which BAPCtools is invoked. -current_working_directory: Final[Path] = Path.cwd().resolve() +current_working_directory: Final[Path] = Path.cwd().absolute() # Add third_party/ to the $PATH for checktestdata. os.environ["PATH"] += os.pathsep + str(TOOLS_ROOT / "third_party") diff --git a/bin/problem.py b/bin/problem.py index 1dce47b7..31761234 100644 --- a/bin/problem.py +++ b/bin/problem.py @@ -323,7 +323,7 @@ class Problem: def __init__(self, path: Path, tmpdir: Path, label: Optional[str] = None): # The problem name/shortname, which is the name of the directory and used as a display name. - self.name = path.resolve().name + self.name = path.name # The Path of the problem directory. self.path = path self.tmpdir: Path = tmpdir / self.name diff --git a/bin/skel.py b/bin/skel.py index 36206996..bad43194 100644 --- a/bin/skel.py +++ b/bin/skel.py @@ -270,10 +270,10 @@ def copy_skel_dir(problems: list[Problem]) -> None: # NOTE: This is one of few places that prints to stdout instead of stderr. def create_gitlab_jobs(contest: str, problems: list[Problem]) -> None: - git_root_path = Path(os.popen("git rev-parse --show-toplevel").read().strip()).resolve() + git_root_path = Path(os.popen("git rev-parse --show-toplevel").read().strip()).absolute() def problem_source_dir(problem: Problem) -> Path: - return problem.path.resolve().relative_to(git_root_path) + return problem.path.absolute().relative_to(git_root_path) if config.args.latest_bt: header_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/header_latest_bt.yaml").read_text() @@ -282,7 +282,7 @@ def problem_source_dir(problem: Problem) -> Path: print(header_yml) contest_yml = (config.TOOLS_ROOT / "skel/gitlab_ci/contest.yaml").read_text() - contest_path = Path(".").resolve().relative_to(git_root_path) + contest_path = Path(".").absolute().relative_to(git_root_path) changes = "".join( f" - {problem_source_dir(problem)}/{pdf_type.path().parent}/**/*\n" for problem in problems diff --git a/bin/tools.py b/bin/tools.py index 5aaabc9c..86ec79e2 100755 --- a/bin/tools.py +++ b/bin/tools.py @@ -86,12 +86,12 @@ def is_problem_directory(path): level: Optional[Literal["problem", "problemset"]] = None if config.args.contest: # TODO #102: replace cast with typed Namespace field - contest = cast(Path, config.args.contest).resolve() + contest = cast(Path, config.args.contest).absolute() os.chdir(contest) level = "problemset" if config.args.problem: # TODO #102: replace cast with typed Namespace field - problem = cast(Path, config.args.problem).resolve() + problem = cast(Path, config.args.problem).absolute() level = "problem" os.chdir(problem.parent) elif is_problem_directory(Path(".")): diff --git a/bin/util.py b/bin/util.py index 75abb587..a2b874d3 100644 --- a/bin/util.py +++ b/bin/util.py @@ -1130,7 +1130,7 @@ def copytree_and_substitute( pass elif preserve_symlinks and os.path.islink(src): shutil.copy(src, dst, follow_symlinks=False) - elif os.path.islink(src) and src.resolve().is_relative_to(base): + elif os.path.islink(src) and src.absolute().is_relative_to(base.absolute()): shutil.copy(src, dst, follow_symlinks=False) elif os.path.isdir(src): names = os.listdir(src) From c5f7339e2832ceaa15de0c78400f2dfc198e48e4 Mon Sep 17 00:00:00 2001 From: mzuenni Date: Sat, 29 Mar 2025 22:17:33 +0100 Subject: [PATCH 2/3] use more absolute --- bin/interactive.py | 6 +++--- bin/util.py | 2 +- bin/validate.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/interactive.py b/bin/interactive.py index 2ba533cc..e2a92099 100644 --- a/bin/interactive.py +++ b/bin/interactive.py @@ -52,9 +52,9 @@ def get_validator_command(): return ( output_validator.run_command + [ - run.in_path.resolve(), - run.testcase.ans_path.resolve(), - run.feedbackdir.resolve(), + run.in_path.absolute(), + run.testcase.ans_path.absolute(), + run.feedbackdir.absolute(), ] + run.testcase.testdata_yaml_args( output_validator, diff --git a/bin/util.py b/bin/util.py index a2b874d3..5fe350fb 100644 --- a/bin/util.py +++ b/bin/util.py @@ -1028,7 +1028,7 @@ def ensure_symlink(link: Path, target: Path, output: bool = False, relative: boo # Use os.path.relpath instead of Path.relative_to for non-subdirectories. link.symlink_to(os.path.relpath(target, link.parent), target.is_dir()) else: - link.symlink_to(target.resolve(), target.is_dir()) + link.symlink_to(target.absolute(), target.is_dir()) return True except (FileNotFoundError, FileExistsError): # this must be a race condition diff --git a/bin/validate.py b/bin/validate.py index 6ca13e3f..1c409122 100644 --- a/bin/validate.py +++ b/bin/validate.py @@ -185,7 +185,7 @@ def format_exec_code_map(returncode): if self.language == "viva": # Called as `viva validator.viva testcase.in`. result = self._exec_command( - self.run_command + [main_path.resolve()], + self.run_command + [main_path.absolute()], exec_code_map=format_exec_code_map, cwd=cwd, ) @@ -319,7 +319,7 @@ def run( if self.language in Validator.FORMAT_VALIDATOR_LANGUAGES: return Validator._run_format_validator(self, testcase, cwd) - invocation = self.run_command + [testcase.in_path.resolve()] + invocation = self.run_command + [testcase.in_path.absolute()] with testcase.ans_path.open("rb") as ans_file: ret = self._exec_helper( @@ -377,8 +377,8 @@ def run( if mode == Mode.INPUT: raise ValueError("OutputValidator does not support Mode.INPUT") - in_path = testcase.in_path.resolve() - ans_path = testcase.ans_path.resolve() + in_path = testcase.in_path.absolute() + ans_path = testcase.ans_path.absolute() if mode == Mode.ANSWER: path = ans_path elif mode == Mode.INVALID: @@ -387,10 +387,10 @@ def run( "OutputValidator in Mode.INVALID should only be run for data/invalid_output" ) assert testcase.out_path is not None - path = testcase.out_path.resolve() + path = testcase.out_path.absolute() elif mode == Mode.VALID_OUTPUT: assert testcase.out_path is not None - path = testcase.out_path.resolve() + path = testcase.out_path.absolute() else: assert mode != Mode.INPUT # mode is actually a Run From 6a62527daffa1f60950a0ddbe518e21de14c45e6 Mon Sep 17 00:00:00 2001 From: Maarten Sijm <9739541+mpsijm@users.noreply.github.com> Date: Tue, 5 Aug 2025 15:07:15 +0200 Subject: [PATCH 3/3] Replace more occurrences of .resolve() with .absolute(), also in tests --- bin/run.py | 2 +- test/test_default_output_validator.py | 2 +- test/test_problem_yaml.py | 2 +- test/test_problems.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/run.py b/bin/run.py index 84932e73..d3aa49e4 100644 --- a/bin/run.py +++ b/bin/run.py @@ -239,7 +239,7 @@ def _visualize_output(self, bar: BAR_TYPE) -> Optional[ExecResult]: return None return output_visualizer.run( self.in_path, - self.testcase.ans_path.resolve(), + self.testcase.ans_path.absolute(), self.out_path if not self.problem.interactive else None, self.feedbackdir, args=self.testcase.testdata_yaml_args(output_visualizer, bar), diff --git a/test/test_default_output_validator.py b/test/test_default_output_validator.py index 220b12d9..c93722cd 100644 --- a/test/test_default_output_validator.py +++ b/test/test_default_output_validator.py @@ -11,7 +11,7 @@ import util import config -RUN_DIR = Path.cwd().resolve() +RUN_DIR = Path.cwd().absolute() # Note: the python version isn't tested by default, because it's quite slow. DEFAULT_OUTPUT_VALIDATOR = ["default_output_validator.cpp"] diff --git a/test/test_problem_yaml.py b/test/test_problem_yaml.py index 4f6b4117..8c0c18c1 100644 --- a/test/test_problem_yaml.py +++ b/test/test_problem_yaml.py @@ -7,7 +7,7 @@ import config import problem -RUN_DIR = Path.cwd().resolve() +RUN_DIR = Path.cwd().absolute() config.args.verbose = 2 config.args.error = True diff --git a/test/test_problems.py b/test/test_problems.py index 9be30362..4f0b7eee 100644 --- a/test/test_problems.py +++ b/test/test_problems.py @@ -23,7 +23,7 @@ "constants", ] + ["hellounix" if not util.is_mac() and not util.is_windows() else []] -RUN_DIR = Path.cwd().resolve() +RUN_DIR = Path.cwd().absolute() @pytest.fixture(scope="class", params=PROBLEMS)