question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pre-commit install silently fails when running in git-bash

See original GitHub issue

describe your issue

I am actually doing dev work on pyscaffold, which uses pre-commit. Problems there led me to track the problem back to pre-commit. Running on Windows 10 in git-bash the command precommit install produces no output, but has a return code of 1.

I tracked the problem to sys.stderr being used without checking that it is not None It happens at main.py line 335 - args = parser.parse_args(argv)

pre-commit --version

2.17.0

.pre-commit-config.yaml

just an empty file

~/.cache/pre-commit/pre-commit.log (if present)

I tracked it down and found the exception and printed it for you.

Traceback (most recent call last): File “C:\Users\julie\juliehome.venvs\pyscaffold\lib\site-packages\pre_commit\main.py”, line 342, in main args = parser.parse_args(argv) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 1825, in parse_args args, argv = self.parse_known_args(args, namespace) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 1858, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 2070, in _parse_known_args stop_index = consume_positionals(start_index) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 2026, in consume_positionals take_action(action, args) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 1935, in take_action action(self, namespace, argument_values, option_string) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 1213, in call subnamespace, arg_strings = parser.parse_known_args(arg_strings, None) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 1858, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 2092, in _parse_known_args self._get_value(action, action.default)) File “C:\Users\julie\AppData\Local\Programs\Python\Python310\lib\argparse.py”, line 2483, in _get_value result = type_func(arg_string) File “C:\Users\julie\juliehome.venvs\pyscaffold\lib\site-packages\pre_commit\color.py”, line 94, in use_color sys.stderr.isatty() and AttributeError: ‘NoneType’ object has no attribute ‘isatty’

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Feb 14, 2022

please do not, stderr should never be None. this is not “defensive programming” this is complexity against an impossible situation

0reactions
julie777commented, Feb 16, 2022

I’ve done much more research on this issue and in my case there is both the problem with pip22 and a problem with git-bash and others using mintty.

thanks for your help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git pre-commit hook is not running on Windows - Stack Overflow
For me, I tried to run a .bat file. I discovered that backslashes need to be escaped: For example: #!/bin/bash C:\\somefolder\\somefile.bat.
Read more >
pre-commit
Run pre -commit install to install pre-commit into your git hooks. pre-commit will now run on every commit. Every time you clone a...
Read more >
Git Hooks - Git SCM
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to...
Read more >
git-push Documentation - Git
The refs/heads/* namespace will only accept commit objects, and updates only if they can be ... Will fail unless you manually run git...
Read more >
git-checkout Documentation - Git
git -checkout - Switch branches or restore working tree files ... error stream by default when it is attached to a terminal, unless...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found