Skip to content

Instantly share code, notes, and snippets.

@ocavue
Last active September 12, 2018 03:56
Show Gist options
  • Select an option

  • Save ocavue/e0fce2d166eda1d0159763114ece5147 to your computer and use it in GitHub Desktop.

Select an option

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
def f(arg: int) -> None:
pass
a: int = 1
b: str = ""
from typing import List
def f(arg: List[str]) -> List:
return arg
def f(
aaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbb,
ccccccccccccccc,
ddddddddddddddd,
eeeeeeeeeeeeeee,
fffffffffffffff,
):
pass
def g(
aaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbb,
ccccccccccccccc,
*,
ddddddddddddddd,
eeeeeeeeeeeeeee,
):
pass
$ 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
# 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