nidhaloff / deep-translator

A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.
https://deep-translator.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
1.61k stars 186 forks source link

adding pre-commit hooks for the repository #190

Closed jiaulislam closed 1 year ago

jiaulislam commented 1 year ago

adding pre-commit support for #187

jiaulislam commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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