Skip to content

Absolute2 #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: draft
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions bin/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,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
Expand Down
8 changes: 4 additions & 4 deletions bin/skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def problem_source_dir(problem: Problem):
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()
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")):
Expand Down
4 changes: 2 additions & 2 deletions bin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions bin/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
Loading