You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Problem with python 3.7 and "async" as parameter name #558
In python 3.7, async is a reserved keyword [1]. This module is using async as parameter name in different methods and it's failing with syntax errors like (excerpt):
File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/admissionregistration_api.py", line 120
async=params.get('async'),
^
SyntaxError: invalid syntax
byte-compiling /tmp/test/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/storage_v1alpha1_api.py to storage_v1alpha1_api.cpython-37.pyc
File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/storage_v1alpha1_api.py", line 132
async=params.get('async'),
^
SyntaxError: invalid syntax
byte-compiling /tmp/test/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/autoscaling_api.py to autoscaling_api.cpython-37.pyc
File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/autoscaling_api.py", line 120
async=params.get('async'),
^
SyntaxError: invalid syntax
Note that python 3.7 was released recently and some distros (as fedora) will be switching to it.
It appears that async is part of the API which makes things hard to fix just by renaming. I have a decorator that might be useful for this (consider it Public Domain or CC0):
fromfunctoolsimportwrapsdefdeprecated_async(func):
"""A decorator, that let's us keep our old API, but deprecate it"""@wraps(func)definner(*args, **kwargs):
if'async'inkwargs:
if'asynchronous'inkwargs:
raiseValueError('cannot use both async and asynchronous ''keyword arguments! the latter obsoletes the first.')
warnings.warn('async keyword argumnt is deprecated, ''use asynchronous instead', DeprecationWarning)
kwargs['asynchronous'] =kwargs.pop('async')
returnfunc(*args, **kwargs)
returninner@deprecated_asyncdefawesome_func(foo, bar, asynchronous=False):
"""People can pass async or asynchronous"""
...
Since Homebrew updated Python to 3.7, my workaround for the Ansible OpenShift and Kubernetes integration was to run this little sed command in the kubernetes/openshift python module directory:
cd /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kubernetes
find . -name "*.py" | xargs sed -i '' s/async=para/async_=para/g
cd /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openshift
find . -name "*.py" | xargs sed -i '' s/async=para/async_=para/g
Hope it helps someone until the issue is fixed properly
I ran into this after Homebrew updated Python to 3.7 this morning. @Chekov2k, how are you installing the Kubernetes python package to that directory? If I do a pip install it fails (due to this issue) and kubernetes isn't present in /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages.
find /usr/local/lib/python3.7/site-packages/kubernetes/ -name "*.py" | xargs sudo sed -i 's/async=/async_=/g'
sudo sed -i 's/if not async:/if not async_:/' /usr/local/lib/python3.7/site-packages/kubernetes/client/api_client.py
I opened PR in swagger-codegen and added a simple workaround to gen repository. Next release should support Python 3.7.
If you can't wait I suggest running
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/async=/async_req=/g' {} +
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/async bool/async_req bool/g' {} +
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i "s/'async'/'async_req'/g" {} +
sed -i "s/if not async/if not async_req/g" "${OUTPUT_DIR}/client/api_client.py"
where OUTPUT_DIR is the path to the library.
Reacted by Haowei Cai (Roy), wojss, Jared Mackey, Laurie Odgers, Oliver Ford, Arnaud, Dhawal Patel, Jakob Schmutz, Radu Iacobescu and Mahmoud Magdy Hegazi
@roycaihw could the re-generation be performed against the "old" releases?
We're using GCP and the most recent stable K8s is 1.10 - which is not compatible with the 8.0 branch (it's compatible with the 6.0 branch, which doesn't work with python 3.7)
Activity
hroncok commentedon Jun 28, 2018
Note that Fedora already is switching to Python 3.7.
hroncok commentedon Jun 28, 2018
It appears that async is part of the API which makes things hard to fix just by renaming. I have a decorator that might be useful for this (consider it Public Domain or CC0):
tomplus commentedon Jun 28, 2018
OMG, it looks like a breaking change, btw this part is generated by swagger-codegen.
What does it mean "fedora is switching to p37" ?
hroncok commentedon Jun 28, 2018
https://fedoraproject.org/wiki/Changes/Python3.7
tomplus commentedon Jun 28, 2018
Thanks @hroncok , so Fedora 29 will use it. I though that latest version was switched or something ;)
hroncok commentedon Jun 28, 2018
But Fedora 29 already needs to use it at this point. From user perspective, this is something form the future, but from ours, it's the current one.
Chekov2k commentedon Jul 2, 2018
Since Homebrew updated Python to 3.7, my workaround for the Ansible OpenShift and Kubernetes integration was to run this little sed command in the kubernetes/openshift python module directory:
Hope it helps someone until the issue is fixed properly
jbiel commentedon Jul 2, 2018
I ran into this after Homebrew updated Python to 3.7 this morning. @Chekov2k, how are you installing the Kubernetes python package to that directory? If I do a
pip installit fails (due to this issue) andkubernetesisn't present in/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages.Chekov2k commentedon Jul 2, 2018
@jbiel I just ran pip3 install kubernetes openshift with a clean install of python3 beforehand
jbiel commentedon Jul 3, 2018
Thanks @Chekov2k. I ended up using this:
tomplus commentedon Jul 8, 2018
I opened PR in swagger-codegen and added a simple workaround to gen repository. Next release should support Python 3.7.
If you can't wait I suggest running
where OUTPUT_DIR is the path to the library.
roycaihw commentedon Jul 27, 2018
Closing as new releases have been generated using kubernetes-client/gen#67
eastlondoner commentedon Nov 5, 2018
@roycaihw could the re-generation be performed against the "old" releases?
We're using GCP and the most recent stable K8s is 1.10 - which is not compatible with the 8.0 branch (it's compatible with the 6.0 branch, which doesn't work with python 3.7)
PR here: #682
kubernetes-client/python#558 - bumping kubernetes dependency to 7.0.0…
JccSanabria commentedon Nov 9, 2019
Fixed up replacing just the inputs and regular attributes named async (not the _async) within the null.py file.