Handle case when CONSERVANCY_REPOSITORY isn't set at all

This commit is contained in:
Ben Sturmfels 2025-07-12 13:20:05 +10:00
parent 5a8da108b9
commit cc4be8b010
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0

View file

@ -702,9 +702,10 @@ def parse_repo_relative_path(path: str) -> str:
if not os.path.exists(path): if not os.path.exists(path):
raise argparse.ArgumentTypeError(f'File {path} does not exist.') raise argparse.ArgumentTypeError(f'File {path} does not exist.')
real_path = os.path.realpath(path) real_path = os.path.realpath(path)
repo = os.path.realpath(os.getenv('CONSERVANCY_REPOSITORY')) try:
if not repo: repo = os.path.realpath(os.environ['CONSERVANCY_REPOSITORY'])
raise argparse.ArgumentTypeError('$CONSERVANCY_REPOSITORY is not set.') except KeyError:
raise argparse.ArgumentTypeError('$CONSERVANCY_REPOSITORY environment variable is not set.')
if not real_path.startswith(repo): if not real_path.startswith(repo):
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
f'File {real_path} does not share a common prefix with $CONSERVANCY_REPOSITORY {repo}.' f'File {real_path} does not share a common prefix with $CONSERVANCY_REPOSITORY {repo}.'