Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added generic Python asyncio generator script. #68

Merged

Conversation

olitheolix
Copy link
Contributor

This is similar to the existing python-asyncio.sh script but does not hard code the name of the client library (kubernetes_asyncio). Instead, it uses the PACKAGE_NAME variable from the settings file as explained in the Readme to this repository.

This will allow others to create their own client libraries more easily.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 8, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 8, 2018
@olitheolix
Copy link
Contributor Author

@k8s-ci-robot

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 8, 2018
@tomplus
Copy link
Member

tomplus commented Jul 9, 2018

I'm not sure if it's place for "generic" clients. This special repo gen is dedicated to client libraries which are part of https://github.com/kubernetes-client/. I hope kubernetes_asyncio will be here soon.

@olitheolix
Copy link
Contributor Author

olitheolix commented Jul 9, 2018

I hope kubernetes_asyncio will be here soon.

And I hope aiokubernetes will be too. Shall I rename the file to python-aiokubernetes.sh?

@brendandburns
Copy link
Contributor

Can we just modify the existing script rather than introduce a new one?

I don't mind having scripts that are used for non kubernetes-client libraries as long as they don't make this repo harder to maintain, and in this case, making this script a little more generic (with appropriate defaults) seems fine with me.

@olitheolix
Copy link
Contributor Author

I did not modify python-asyncio.sh because it is customised for kubernetes_asyncio and might break it.

Instead, I copied it and:

  • changed the SWAGGER_CODEGEN_COMMIT to an official version tag,
  • replaced the hard coded kubernetes_asyncio with the shell variable from the settings scripts,
  • removed the (also custom made for kubernetes_asyncio) patches.

This is as generic as I can think of making it right now. It also produces a working client.

All my aiokubernetes specific patches and modifications happen downstream where I can maintain them myself without having to bother anyone in this gen repository.

I can modify the PR to change python-asyncio.sh and delete python-asyncio-rest.py.patch but that may cause problems for kubernetes_asyncio. Can we keep both versions, at least for now, to reduce the risk of breaking anything for anyone?

@brendandburns
Copy link
Contributor

I don't want lots of slightly different scripts. I think you can add conditionalization to make this work correctly with a single python-asyncio.sh script.

@olitheolix
Copy link
Contributor Author

Done.

@brendandburns
Copy link
Contributor

Sorry, this isn't quite what I hoped, the if/else should minimize the differences between the files, rather than just have a giant if/else across the two blocks.

There are many environment variables (e.g. CLEANUP_DIRS) which are shared in the two blocks and shouldn't be duplicated.

Please refactor to minimize differences.

Thanks (and apologies for not being clear before)

@olitheolix
Copy link
Contributor Author

Is this what you had in mind?

@brendandburns
Copy link
Contributor

Yep, that looks much better, thanks!

@tomplus can you validate that python_asyncio generates ok with this PR?

Thanks!

CLIENT_LANGUAGE=python-asyncio; \
CLEANUP_DIRS=(client/apis client/models docs test); \
# Client specific Swagger branch to use.
if [ ${PACKAGE_NAME} == "kubernetes_asyncio" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

PACKAGE_NAME is "client" in my case and it's the same as in the standard python client. Please take a look: https://github.com/kubernetes-client/python/blob/master/scripts/update-client.sh#L49

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes_asyncio.client./g' {} +
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client/from kubernetes_asyncio.client/g' {} +
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/getattr(client\.models/getattr(kubernetes_asyncio.client.models/g' {} +
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
Copy link
Member

Choose a reason for hiding this comment

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

There is the same situation with PACKAGE_NAME here and below too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you want me to change here because this line is a verbatim copy of the one in master.

Copy link
Member

Choose a reason for hiding this comment

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

The current version does s/\bclient/kubernetes_asyncio.client/g but this wants to do s/\\bclient/client.client/g (because PACKAGE_NAME=client).

@brendandburns
Copy link
Contributor

@tomplus can we get a glance here to see if this does the right things?

Thanks!

@tomplus
Copy link
Member

tomplus commented Aug 29, 2018

@brendandburns Thanks for asking. I tested it and it works for me.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 29, 2018
@brendandburns
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, olitheolix

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 5, 2018
@brendandburns
Copy link
Contributor

@olitheolix this is finally merging :) thanks for your patience.

@k8s-ci-robot k8s-ci-robot merged commit 64959e2 into kubernetes-client:master Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants