Skip to content
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

Cannot run --files on Windows #1476

Closed
harrybiddle opened this issue May 29, 2020 · 7 comments · Fixed by #1494
Closed

Cannot run --files on Windows #1476

harrybiddle opened this issue May 29, 2020 · 7 comments · Fixed by #1494
Labels

Comments

@harrybiddle
Copy link

(pre-commit version 2.4.0) We're running in to an odd issue on Windows

$ pre-commit run --files my_file.py
black................................................(no files to check)Skipped

However, running pre-commit run --all-files will correctly format the file. Equally, running pre-commit run --files my_file.py in the same repository on a Mac works fine.

It's like the file is somehow not being read in Windows... Has anybody else encountered this?

@asottile
Copy link
Member

please share your configuration -- I suspect you've got an exclude: or types: which is causing that file to be skipped

@harrybiddle
Copy link
Author

Hey @asottile ,

Here are the configuration files. The file we were trying to format was ./trase/supplychain/test/test_supplychain.py.

However, I thought that we had ruled out this being a configuration issue, for two reasons:

  1. Running pre-commit run --all-files does format the file, so it must be correct in the configuration
  2. Running the same command on a Mac works

Thank you for any help!

  • .pre-commit-config.yaml:

    exclude: '^(?!trase/).*$'
    repos:
    -   repo: https://github.com/ambv/black
        rev: 19.10b0
        hooks:
        - id: black
          language_version: python3.6
    -   repo: https://github.com/timothycrosley/isort
        rev: 4.3.21
        hooks:
        -   id: isort
  • .gitignore:

    __pycache__/
    .ipynb_checkpoints/
    .vscode/
    .venv/
    ORI/
    IN/
    PRE/
    OUT/
    POST/
    *.pyc
    *.mps
    *.lp
    *.txt
    .DS_Store
    poetry.toml
    .pytest_cache
    Tutorial_1/
    Tutorial_2/
    Tutorial_3/
    result.log
    main.py
    **/*.idea*
    .idea/*
    **/*~
    **/*#
    **/.#*
    

@asottile
Copy link
Member

asottile commented Jun 8, 2020

can you show the exact command you ran?

@harrybiddle
Copy link
Author

On Windows:

$ pre-commit run --files trase/supplychain/test/test_supplychain.py
black................................................(no files to check)Skipped
isort................................................(no files to check)Skipped

On Mac:

$ pre-commit run --files trase/supplychain/test/test_supplychain.py
black....................................................................Passed
isort....................................................................Passed

I'm wondering if it is something odd about passing the file path on Windows. I've noticed that I get "skipped" on a Mac with pre-commit run --files this-file-does-not-exist. We did try changing to a backslash but still no joy...

@asottile
Copy link
Member

asottile commented Jun 8, 2020

ok, I can now reproduce this, it seems that when I switched everything to use forward slashes for the regexes, I forgot to handle global files / exclude (by the way, your configuration can be a little bit simpler by doing files: ^trase/ (this still doesn't work until I fix this bug though!))

thanks for the report! (I'm working on this on stream right now https://twitch.tv/anthonywritescode)

@harrybiddle
Copy link
Author

Amazing - I love the twitch livestream. Thank you for the fix!

By the way, Python's stdlib has a great module for converting the a file path to posix-style, maybe it will catch some odd edge cases that aren't covered in your f.replace(os.sep, os.altsep) code?

https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.as_posix

@asottile
Copy link
Member

asottile commented Jun 9, 2020

yeah it's literally the same thing:

    def as_posix(self):
        """Return the string representation of the path with forward (/)
        slashes."""
        f = self._flavour
        return str(self).replace(f.sep, '/')

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

Successfully merging a pull request may close this issue.

2 participants