The Wayback Machine - https://web.archive.org/web/20201126185912/https://github.com/TheAlgorithms/Python/issues/3887
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

Guiding people using contibuting.md so they do not fail pre-commit #3887

Open
xcodz-dot opened this issue Nov 13, 2020 · 26 comments
Open

Guiding people using contibuting.md so they do not fail pre-commit #3887

xcodz-dot opened this issue Nov 13, 2020 · 26 comments

Comments

@xcodz-dot
Copy link
Contributor

@xcodz-dot xcodz-dot commented Nov 13, 2020

I have a simple instruction which is good to be kept in CONTRIBUTION.md. Please add this wherever it looks good:

  • clone your forked repository locally
  • change directory to its root
  • run pip install pre-commit
  • run pre-commit run --all-files
  • commit and push the changes to your fork.
@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Nov 14, 2020

pre-commit is a plugin that runs automatically on git events. If you want you can open a PR to include the steps like so:

Pre-commit plugin

To forget about coding style and let pre-commit fix your flake8/isort/black issue.

  • Install pre-commit: $ python -m pip install pre-commit
  • And then: $ pre-commit install

That's it!

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 14, 2020

that seems to look good, almost 70% percent of pull request I see fails pre-commit which was hard to fix manually until i came to know we can use this locally to make changes

@Joe-Sin7h
Copy link

@Joe-Sin7h Joe-Sin7h commented Nov 15, 2020

hey , @dhruvmanila i would Love to work on this issue .
Pls assign this issue to me .

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 16, 2020

Well @Joe-Sin7h, You can start working and link this issue in your PR. No need to get assigned

@luperciomartine
Copy link

@luperciomartine luperciomartine commented Nov 21, 2020

1flake8/ isort/ black.

Instalar el compromiso previo: $ python -m pip install pre-commit
Y entonces: $ pre-commit installpip install pre-commit
correr pre-commit run --all-files

@luperciomartine
Copy link

@luperciomartine luperciomartine commented Nov 21, 2020

pre-commit --versiflake8/ isort/ black.

Instalar el compromiso previo: $ python -m pip install pre-commit
Y entonces: $ pre-commit installpyzarchivo de las versiones de github
correr python pre-commit-#.#.#.pyz ...en lugar depre-commit ...pre-commit --versi

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 22, 2020

Sorry, We understand english

@xcodz-dot xcodz-dot closed this Nov 22, 2020
@xcodz-dot xcodz-dot reopened this Nov 22, 2020
@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 24, 2020

Hello, I have made the necessary changes in CONTRIBUTING.md, and I am getting the following error when I try to commit the changes:
Check that executables have shebangs.....................................Passed Check Yaml...........................................(no files to check)Skipped Fix End of Files.....................................(no files to check)Skipped Trim Trailing Whitespace.................................................Passed Fix requirements.txt.................................(no files to check)Skipped black................................................(no files to check)Skipped isort................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped codespell................................................................Passed Validate filenames.......................................................An unexpected error has occurred: OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE' Check the log at C:\Users\Ashish Papanai\.cache\pre-commit\pre-commit.log
Could you please help me out?

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 25, 2020

Sure, You should try the steps yourself (Warning: they are steps for you only, complete steps have been mentioned above):

  • pip install pre-commit
  • pre-commit run -a
@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 25, 2020

Also, retry the whole procedure of commiting, and then upload the C:\Users\Ashish Papanai\.cache\pre-commit\pre-commit.log to this place

@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 25, 2020

Hello @xcodz-dot The last pre-commit test i.e. Validate filenames is failing with the following error:
Validate filenames.......................................................An unexpected error has occurred: OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE'

The pre-commit.log is mentioned below:
`### version information

pre-commit version: 2.9.0
sys.version:
    3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
sys.executable: c:\users\ashish papanai\anaconda3\python.exe
os.name: nt
sys.platform: win32

error information

An unexpected error has occurred: OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE'
Traceback (most recent call last):
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\error_handler.py", line 65, in error_handler
    yield
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\main.py", line 375, in main
    return run(args.config, store, args)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\commands\run.py", line 400, in run
    return _run_hooks(config, hooks, args, environ)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\commands\run.py", line 282, in _run_hooks
    current_retval, prior_diff = _run_single_hook(
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\commands\run.py", line 190, in _run_single_hook
    retcode, out = language.run_hook(hook, filenames, use_color)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\languages\script.py", line 19, in run_hook
    return helpers.run_xargs(hook, cmd, file_args, color=color)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\languages\helpers.py", line 136, in run_xargs
    return xargs(cmd, file_args, **kwargs)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\xargs.py", line 163, in xargs
    for proc_retcode, proc_out, _ in results:
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\xargs.py", line 155, in run_cmd_partition
    return cmd_fn(
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\util.py", line 141, in cmd_output_b
    cmd = parse_shebang.normalize_cmd(cmd)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\parse_shebang.py", line 79, in normalize_cmd
    cmd = parse_filename(exe) + (exe,) + cmd[1:]
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\parse_shebang.py", line 22, in parse_filename
    return parse_shebang_from_file(filename)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\identify\identify.py", line 195, in parse_shebang_from_file
    with open(path, 'rb') as f:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE'

`

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 25, 2020

It seems something is trying to open the python executable

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 25, 2020

I recommend for you to try the official python setup instead of windows app.
https://www.python.org

@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 26, 2020

Tried everything, The final step is still failing. @xcodz-dot

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

Try running this command in root of repo instead of old one, also post your command line and log again after this:

  • pre-commit clean
  • pre-commit gc
  • pre-commit run -a -v --show-diff-on-failure
@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 26, 2020

It is the root of the repository. i.e. E:/Git Contributions/Python

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

Ok try the commands

@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 26, 2020

@xcodz-dot The following lines are from cmd after running the commands mentioned by you:

E:\Git Contributions\Python>pre-commit clean
Cleaned C:\Users\Ashish Papanai\.cache\pre-commit.

E:\Git Contributions\Python>pre-commit gc
0 repo(s) removed.

E:\Git Contributions\Python>pre-commit run -a -v --show-diff-on-failure
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/PyCQA/isort.
[INFO] Initializing environment for https://gitlab.com/pycqa/flake8.
[INFO] Initializing environment for https://github.com/codespell-project/codespell.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://gitlab.com/pycqa/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/codespell-project/codespell.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Check that executables have shebangs.....................................Passed
- hook id: check-executables-have-shebangs
- duration: 0.39s
Check Yaml...............................................................Passed
- hook id: check-yaml
- duration: 0.34s
Fix End of Files.........................................................Passed
- hook id: end-of-file-fixer
- duration: 0.32s
Trim Trailing Whitespace.................................................Passed
- hook id: trailing-whitespace
- duration: 0.5s
Fix requirements.txt.....................................................Passed
- hook id: requirements-txt-fixer
- duration: 0.15s
black....................................................................Passed
- hook id: black
- duration: 0.88s

All done! \u2728 \U0001f370 \u2728
855 files left unchanged.

isort....................................................................Passed
- hook id: isort
- duration: 2.03s
flake8...................................................................Passed
- hook id: flake8
- duration: 11.15s
codespell................................................................Passed
- hook id: codespell
- duration: 0.68s
Validate filenames.......................................................An unexpected error has occurred: OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE'
Check the log at C:\Users\Ashish Papanai\.cache\pre-commit\pre-commit.log

E:\Git Contributions\Python>
@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

Now please post me the log

@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 26, 2020

The log is mentioned below:

version information

pre-commit version: 2.9.0
sys.version:
    3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
sys.executable: c:\users\ashish papanai\anaconda3\python.exe
os.name: nt
sys.platform: win32

error information

An unexpected error has occurred: OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE'
Traceback (most recent call last):
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\error_handler.py", line 65, in error_handler
    yield
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\main.py", line 375, in main
    return run(args.config, store, args)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\commands\run.py", line 400, in run
    return _run_hooks(config, hooks, args, environ)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\commands\run.py", line 282, in _run_hooks
    current_retval, prior_diff = _run_single_hook(
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\commands\run.py", line 190, in _run_single_hook
    retcode, out = language.run_hook(hook, filenames, use_color)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\languages\script.py", line 19, in run_hook
    return helpers.run_xargs(hook, cmd, file_args, color=color)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\languages\helpers.py", line 136, in run_xargs
    return xargs(cmd, file_args, **kwargs)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\xargs.py", line 163, in xargs
    for proc_retcode, proc_out, _ in results:
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\xargs.py", line 155, in run_cmd_partition
    return cmd_fn(
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\util.py", line 141, in cmd_output_b
    cmd = parse_shebang.normalize_cmd(cmd)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\parse_shebang.py", line 79, in normalize_cmd
    cmd = parse_filename(exe) + (exe,) + cmd[1:]
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\pre_commit\parse_shebang.py", line 22, in parse_filename
    return parse_shebang_from_file(filename)
  File "c:\users\ashish papanai\anaconda3\lib\site-packages\identify\identify.py", line 195, in parse_shebang_from_file
    with open(path, 'rb') as f:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Ashish Papanai\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE'
@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

try:
pip uninstall pre-commmit
pip install pre-commit
pre-commit uninstall
pre-commit install
pre-commit clean
pre-commit run -a -v

I can't help much cause the issue is with internal working

@ashishpapanai
Copy link

@ashishpapanai ashishpapanai commented Nov 26, 2020

@xcodz-dot I tried to commit using WSL, any idea that why is it looking for shebang and how to fix that?

ashishpapanai@ashishpapanai:/mnt/e/Git Contributions/Python$ chmod -x CONTRIBUTING.md
ashishpapanai@ashishpapanai:/mnt/e/Git Contributions/Python$ git commit -m "Fixes Issue#3887 Guiding people using contibuting.md"
Check that executables have shebangs.....................................Failed
- hook id: check-executables-have-shebangs
- exit code: 1

CONTRIBUTING.md: marked executable but has no (or invalid) shebang!
  If it isn't supposed to be executable, try: `chmod -x CONTRIBUTING.md`
  If it is supposed to be executable, double-check its shebang.

Check Yaml...........................................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
Trim Trailing Whitespace.................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
black................................................(no files to check)Skipped
isort................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
codespell................................................................Passed
Validate filenames.......................................................Passed

I tried to remove the executable permissions of contributing.md by chmod -x CONTRIBUTING.md But it didn't help.

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

how about trying pre-commit run -a here

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

Also, which editor are you using?

@xcodz-dot
Copy link
Contributor Author

@xcodz-dot xcodz-dot commented Nov 26, 2020

You can try raising this issue in pre-commit repo, they might help you out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.