From 0868006a3cf3623c5b59549fd823d8d2844a37d7 Mon Sep 17 00:00:00 2001 From: Robert Trew Date: Tue, 16 Jun 2020 21:31:39 +0100 Subject: [PATCH] Using pathlib to handle Windows network mounts --- pre_commit/main.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pre_commit/main.py b/pre_commit/main.py index 874eb53a..4dccbabd 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -2,6 +2,7 @@ import argparse import logging import os import sys +from pathlib import Path from typing import Any from typing import Optional from typing import Sequence @@ -171,11 +172,17 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None: else: os.chdir(toplevel) - args.config = os.path.relpath(args.config) + args.config = os.path.relpath(unc_path(args.config)) if args.command in {'run', 'try-repo'}: - args.files = [os.path.relpath(filename) for filename in args.files] - if args.command == 'try-repo' and os.path.exists(args.repo): - args.repo = os.path.relpath(args.repo) + args.files = [ + os.path.relpath(unc_path(filename)) for filename in args.files + ] + if args.command == 'try-repo' and os.path.exists(unc_path(args.repo)): + args.repo = os.path.relpath(unc_path(args.repo)) + + +def unc_path(file_path: str) -> str: + return str(Path(file_path).resolve()) def main(argv: Optional[Sequence[str]] = None) -> int: