Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

adding pre-commit hooks for the repository #190

Merged
merged 4 commits into from
Feb 16, 2023

Conversation

jiaulislam
Copy link
Contributor

@jiaulislam jiaulislam commented Feb 10, 2023

adding pre-commit support for #187

  • black for uncompromised style and indentations
  • flake8 for style guidance
  • autoflake for unused import remove
  • isort for sorting the python imports
  • pycln A formatter for finding and removing unused import statements

Copy link
Owner

@nidhaloff nidhaloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work!
If you can make it work with python3.7 (which should be straightforward), I would approve it, ;) I want the package to support 3.7 as well.
Also, what is the difference between autoflake and pycln? Maybe only use one if they are doing the same thing.

Can you integrate the pre-commit checks on GitHub actions/workflow as well?

Other than that, the PR looks very good. Maybe you used python3.8 for autoflake or pycln, I'm not sure because I never used these, but for black and flake8 should work with 3.7

pyproject.toml Outdated Show resolved Hide resolved
@nidhaloff nidhaloff added the enhancement New feature or request label Feb 10, 2023
@nidhaloff nidhaloff linked an issue Feb 10, 2023 that may be closed by this pull request
@jiaulislam
Copy link
Contributor Author

Thanks for the great work! If you can make it work with python3.7 (which should be straightforward), I would approve it, ;) I want the package to support 3.7 as well. Also, what is the difference between autoflake and pycln? Maybe only use one if they are doing the same thing.

Can you integrate the pre-commit checks on GitHub actions/workflow as well?

Other than that, the PR looks very good. Maybe you used python3.8 for autoflake or pycln, I'm not sure because I never used these, but for black and flake8 should work with 3.7

Not sure about github actions/workflow but will try to integrate in different commit. Other than that I hope pre-commit is working. Ran tests all ran successfully so far.

@nidhaloff nidhaloff merged commit a795cd8 into nidhaloff:master Feb 16, 2023
@nidhaloff
Copy link
Owner

nidhaloff commented Feb 16, 2023

@jiaulislam Thanks for the PR. Did you test your implementation with python3.7 and 3.8? Because it seems there is a problem. Shouldn't it work for both versions of python or rather regarding of the version.
Can you please take a look?

An unexpected error has occurred: CalledProcessError: command: ('/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/bin/python', '-mvirtualenv', '/home/nidhal/.cache/pre-commit/repok91dmzvi/py_env-python3.7', '-p', 'python3.7')
return code: 1
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)
Traceback (most recent call last):
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/main.py", line 394, in main
    return run(args.config, store, args)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/commands/run.py", line 428, in run
    install_hook_envs(to_install, store)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/repository.py", line 79, in _hook_install
    lang.install_environment(
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/languages/python.py", line 219, in install_environment
    cmd_output_b(*venv_cmd, cwd='/')
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/util.py", line 143, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/bin/python', '-mvirtualenv', '/home/nidhal/.cache/pre-commit/repok91dmzvi/py_env-python3.7', '-p', 'python3.7')
return code: 1
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)

@jiaulislam
Copy link
Contributor Author

@jiaulislam Thanks for the PR. Did you test your implementation with python3.7 and 3.8? Because it seems there is a problem. Shouldn't it work for both versions of python or rather regarding of the version. Can you please take a look?

An unexpected error has occurred: CalledProcessError: command: ('/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/bin/python', '-mvirtualenv', '/home/nidhal/.cache/pre-commit/repok91dmzvi/py_env-python3.7', '-p', 'python3.7')
return code: 1
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)
Traceback (most recent call last):
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/main.py", line 394, in main
    return run(args.config, store, args)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/commands/run.py", line 428, in run
    install_hook_envs(to_install, store)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/repository.py", line 79, in _hook_install
    lang.install_environment(
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/languages/python.py", line 219, in install_environment
    cmd_output_b(*venv_cmd, cwd='/')
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/util.py", line 143, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/bin/python', '-mvirtualenv', '/home/nidhal/.cache/pre-commit/repok91dmzvi/py_env-python3.7', '-p', 'python3.7')
return code: 1
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)

As I remembered I have used python 3.11 without any issue. But again let me get back to you with the issue after check I will update

@jiaulislam
Copy link
Contributor Author

@jiaulislam Thanks for the PR. Did you test your implementation with python3.7 and 3.8? Because it seems there is a problem. Shouldn't it work for both versions of python or rather regarding of the version. Can you please take a look?

An unexpected error has occurred: CalledProcessError: command: ('/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/bin/python', '-mvirtualenv', '/home/nidhal/.cache/pre-commit/repok91dmzvi/py_env-python3.7', '-p', 'python3.7')
return code: 1
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)
Traceback (most recent call last):
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/main.py", line 394, in main
    return run(args.config, store, args)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/commands/run.py", line 428, in run
    install_hook_envs(to_install, store)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/repository.py", line 79, in _hook_install
    lang.install_environment(
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/languages/python.py", line 219, in install_environment
    cmd_output_b(*venv_cmd, cwd='/')
  File "/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/lib/python3.8/site-packages/pre_commit/util.py", line 143, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/home/nidhal/.cache/pypoetry/virtualenvs/deep-translator-BSnzTc3Z-py3.8/bin/python', '-mvirtualenv', '/home/nidhal/.cache/pre-commit/repok91dmzvi/py_env-python3.7', '-p', 'python3.7')
return code: 1
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)

@nidhaloff , I have checked with python 3.7, 3.8. 3.11 but didn't faced any issue.

Python:         3.8.16
Implementation: CPython
Path:           /home/ubuntu/.cache/pypoetry/virtualenvs/deep-translator-bDH0m58B-py3.8
Executable:     /home/ubuntu/.cache/pypoetry/virtualenvs/deep-translator-bDH0m58B-py3.8/bin/python
Valid:          True

System
Platform:   linux
OS:         posix
Python:     3.8.16
Path:       /home/ubuntu/.pyenv/versions/3.8.16
Executable: /home/ubuntu/.pyenv/versions/3.8.16/bin/python3.8

Tests Ran on Python3.8

(deep-translator-py3.8) ubuntu@Jibon:~/devspace/deep-translator$ pytest
=============================================================== test session starts ===============================================================
platform linux -- Python 3.8.16, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/ubuntu/devspace/deep-translator
collected 28 items                                                                                                                                

tests/test_cli.py ..                                                                                                                        [  7%]
tests/test_deepl.py ..                                                                                                                      [ 14%]
tests/test_google.py ......                                                                                                                 [ 35%]
tests/test_libre.py ...                                                                                                                     [ 46%]
tests/test_linguee.py ...                                                                                                                   [ 57%]
tests/test_microsoft_trans.py ..ssss                                                                                                        [ 78%]
tests/test_mymemory.py ...                                                                                                                  [ 89%]
tests/test_pons.py ...                                                                                                                      [100%]

========================================================== 24 passed, 4 skipped in 9.62s ==========================================================
(deep-translator-py3.8) ubuntu@Jibon:~/devspace/deep-translator$ 

Pre-Commit Working

(deep-translator-py3.8) ubuntu@Jibon:~/devspace/deep-translator$ pre-commit run --all-files
black....................................................................Passed
flake8...................................................................Passed
pycln....................................................................Passed
isort....................................................................Passed

@jiaulislam jiaulislam deleted the add-pre-commit-hooks branch February 17, 2023 12:47
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pre-commit hook integration to check style and license
2 participants