Last active
September 12, 2018 03:56
-
-
Save ocavue/e0fce2d166eda1d0159763114ece5147 to your computer and use it in GitHub Desktop.
A simple bash script to test if a python syntax can work in different python versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f(arg: int) -> None: | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a: int = 1 | |
| b: str = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List | |
| def f(arg: List[str]) -> List: | |
| return arg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f( | |
| aaaaaaaaaaaaaaa, | |
| bbbbbbbbbbbbbbb, | |
| ccccccccccccccc, | |
| ddddddddddddddd, | |
| eeeeeeeeeeeeeee, | |
| fffffffffffffff, | |
| ): | |
| pass | |
| def g( | |
| aaaaaaaaaaaaaaa, | |
| bbbbbbbbbbbbbbb, | |
| ccccccccccccccc, | |
| *, | |
| ddddddddddddddd, | |
| eeeeeeeeeeeeeee, | |
| ): | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ bash syntax_cheker.sh annotation1.py | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.7.0b2/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.6.5/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.5.5/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.5.2/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.4.8/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.3.7/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.2.6/bin/python3 annotation1.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.1.5/bin/python3 annotation1.py | |
| OK | |
| $ bash syntax_cheker.sh annotation2.py | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.7.0b2/bin/python3 annotation2.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.6.5/bin/python3 annotation2.py | |
| OK | |
| ================================ | |
| ^[[A/Users/ocavue/.pyenv/versions/3.5.5/bin/python3 annotation2.py | |
| File "annotation2.py", line 1 | |
| a: int = 1 | |
| ^ | |
| SyntaxError: invalid syntax | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.5.2/bin/python3 annotation2.py | |
| File "annotation2.py", line 1 | |
| a: int = 1 | |
| ^ | |
| SyntaxError: invalid syntax | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.4.8/bin/python3 annotation2.py | |
| File "annotation2.py", line 1 | |
| a: int = 1 | |
| ^ | |
| SyntaxError: invalid syntax | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.3.7/bin/python3 annotation2.py | |
| File "annotation2.py", line 1 | |
| a: int = 1 | |
| ^ | |
| SyntaxError: invalid syntax | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.2.6/bin/python3 annotation2.py | |
| File "annotation2.py", line 1 | |
| a: int = 1 | |
| ^ | |
| SyntaxError: invalid syntax | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.1.5/bin/python3 annotation2.py | |
| File "annotation2.py", line 1 | |
| a: int = 1 | |
| ^ | |
| SyntaxError: invalid syntax | |
| $ bash syntax_cheker.sh annotation3.py | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.7.0b2/bin/python3 annotation3.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.6.5/bin/python3 annotation3.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.5.5/bin/python3 annotation3.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.5.2/bin/python3 annotation3.py | |
| OK | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.4.8/bin/python3 annotation3.py | |
| Traceback (most recent call last): | |
| File "annotation3.py", line 1, in <module> | |
| from typing import List | |
| ImportError: No module named 'typing' | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.3.7/bin/python3 annotation3.py | |
| Traceback (most recent call last): | |
| File "annotation3.py", line 1, in <module> | |
| from typing import List | |
| ImportError: No module named 'typing' | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.2.6/bin/python3 annotation3.py | |
| Traceback (most recent call last): | |
| File "annotation3.py", line 1, in <module> | |
| from typing import List | |
| ImportError: No module named typing | |
| ================================ | |
| /Users/ocavue/.pyenv/versions/3.1.5/bin/python3 annotation3.py | |
| Traceback (most recent call last): | |
| File "annotation3.py", line 1, in <module> | |
| from typing import List | |
| ImportError: No module named typing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A simple bash script to test if a python syntax can work in different python versions | |
| # example usage: bash synax_cheker.sh ./annotation2.py | |
| # install pyenv before run this script: https://github.com/pyenv/pyenv-installer | |
| # get all installed versions: pyenv versions | |
| # get all installable versions: pyenv install --list | |
| if [ -z "$1" ];then | |
| echo 'please enter .py file path' | |
| exit 1 | |
| fi | |
| py_file_path=$1 | |
| for version in 3.7.0b2 3.6.5 3.5.5 3.5.2 3.4.8 3.3.7 3.2.6 3.1.5 | |
| do | |
| echo '================================' | |
| pyenv install --skip-existing $version | |
| pyenv local $version | |
| full_python_path=$(pyenv which python) | |
| echo $full_python_path $py_file_path | |
| $full_python_path $py_file_path && echo "OK" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment