Skip to content

Pre-commit install fails on Windows network mount drive #1802

Closed

Description

@goroderickgo

Hi, I'm trying to help some team members set up pre-commit on a Windows network mount drive, and they're encountering an issue with paths. Seems related to this comment in #1610, which seems to be a different issue than the one the original issue, as we are on the most recent version of pre-commit and git, and the fix that was merged in #1727 for that doesn't seem to address this issue. I also tried other versions of Git for Windows <2.25, and the issue still seemed to persist.

I tested the solution that @christopherdoyle proposed, and that does seems to fix this issue with network mount drives, though I saw that @asottile would prefer not to use pathlib. I am not able to propose a fix right now, but I wanted to raise this as an issue that still exists.

Full error below:

    ### version information
    
    ```
    pre-commit version: 2.10.1
    sys.version:
        3.9.1 | packaged by conda-forge | (default, Jan 26 2021, 01:29:07) [MSC v.1916 64 bit (AMD64)]
    sys.executable: C:\Users\roderick\.conda\envs\nmt\python.exe
    os.name: nt
    sys.platform: win32
    ```
    
    ### error information
    
    ```
    An unexpected error has occurred: ValueError: path is on mount 'S:', start on mount '\\\\MyServer\Directory'
    ```
    
    ```
    Traceback (most recent call last):
      File "C:\Users\roderick\.conda\envs\nmt\lib\site-packages\pre_commit\error_handler.py", line 65, in error_handler
        yield
      File "C:\Users\roderick\.conda\envs\nmt\lib\site-packages\pre_commit\main.py", line 333, in main
        _adjust_args_and_chdir(args)
      File "C:\Users\roderick\.conda\envs\nmt\lib\site-packages\pre_commit\main.py", line 153, in _adjust_args_and_chdir
        args.config = os.path.relpath(args.config)
      File "C:\Users\roderick\.conda\envs\nmt\lib\ntpath.py", line 703, in relpath
        raise ValueError("path is on mount %r, start on mount %r" % (
    ValueError: path is on mount 'S:', start on mount '\\\\MyServer\Directory'

Activity

  1. asottile commented on Feb 17, 2021

    @asottile
    Member

    can you provide a reproduction and/or more information? might need to use the debugger a bit to see what git is telling us and why we can't deal with that

  2. igortg commented on Feb 20, 2021

    @igortg

    Same issue here using a substed drive. Here I use a substed drive W: pointing to a subfolder on D:

    An unexpected error has occurred: ValueError: path is on mount 'W:', start on mount 'D:'
    

    Output of git rev-parse --show-toplevel is the path to the original subfolder (not W:)

  3. asottile commented on Feb 20, 2021

    @asottile
    Member

    pre-commit no longer uses git rev-parse --show-toplevel, so I'm confused why you're still seeing these issues

  4. igortg commented on Feb 21, 2021

    @igortg

    Sorry, I did the comment based on old versions.

    Taking a look at the code I'd guess that the problem is caused by the os.path.realpath on git.get_root function. It converts a substed or mounted drive to its original path.

  5. asottile commented on Feb 21, 2021

    @asottile
    Member

    instead of guessing can you show me in a terminal? as far as I know realpath does not translate across mounts

  6. igortg commented on Feb 21, 2021

    @igortg

    Sorry. I'm sure realpath convert between substed drives. What I was saying is that I'm guessing that this is the root of the problem (I don't know that if it's just a case of replacing realpath by abspath).

    image

  7. goroderickgo commented on Feb 23, 2021

    @goroderickgo
    Author

    Hi @asottile, sorry I'm new to this and not exactly sure what you want me to do.

    I can reproduce this bug by running pre-commit run. I cloned the pre-commit repo and set up a test environment, and I can reproduce the error by running the main.py script as well, but I don't exactly how to see what git is saying, as you suggested. What I can see is that this block:

    try:

        root = os.path.realpath(
    
        cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
    
    )
    

    in the git.get_root() function returns the path as \\\\MyServer\Directory whereas args.config is located at S:\path\to\.pre-commit-config.yaml

  8. faph commented on Feb 23, 2021

    @faph

    Just to add that we're seeing the same error using Python 3.8.6

    With Python 3.6.8, all works as expected.

  9. faph commented on Feb 23, 2021

    @faph

    From the docs (https://docs.python.org/3/library/os.path.html#os.path.realpath):

    os.path.realpath(path)
    Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system).

    Note When symbolic link cycles occur, the returned path will be one member of the cycle, but no guarantee is made about which member that will be.
    Changed in version 3.6: Accepts a path-like object.

    Changed in version 3.8: Symbolic links and junctions are now resolved on Windows.

  10. asottile commented on Feb 24, 2021

    @asottile
    Member

    can you try out the branch in #1814 -- I tried using abspath instead of realpath -- that should probably fix this problem ?

  11. igortg commented on Feb 25, 2021

    @igortg

    That fixed for me. Many thanks

  12. goroderickgo commented on Feb 26, 2021

    @goroderickgo
    Author

    Yep, also works for me. Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions