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

Add python client generation to /example #27

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sethcenterbar
Copy link

@sethcenterbar sethcenterbar commented Nov 21, 2020

1. Add python client to /example
image

2. [WIP] Generate python classes from def.Objects
Requires:

  • (Probably) Adding a Python mapping for (*Parser).parseFieldType ✅
  • Creating classes for def.Objects ✅
  • Create Constructor from object.Fields ✅
  • Adding type hints via field.type 🚧
  • ???

@sethcenterbar sethcenterbar marked this pull request as draft November 21, 2020 18:02
@sethcenterbar
Copy link
Author

sethcenterbar commented Nov 21, 2020

This statement seems pretty generic. I'm throwing in int for now, but should we look at breaking this into a few different cases (int, double, float)?

// (*Parser).parseFieldType()
                ...
		case "int", "int16", "int32", "int64",
			"uint", "uint16", "uint32", "uint64",
			"float32", "float64":
			ftype.JSType = "number"
			ftype.SwiftType = "Double"
			ftype.PythonType = "int"
		}

@sethcenterbar
Copy link
Author

We may need to name the generated file differently for python, as you can't import python files with periods in the name.

for example, I cannot import the following
from .client.gen import GreetRequest

but I can import
from .clientgen import GreetRequest.

This is likely because it's parsing for .py.

@sethcenterbar
Copy link
Author

Docstring generation is coming along. It's pretty verbose, but it does make the cliengen more discoverable.
image

I'm still not super happy with the ide help here, it's just not super pretty.
image

@matryer
Copy link
Contributor

matryer commented Mar 14, 2021

@sethcenterbar What was the status on this in the end? Did you get it working?

@sethcenterbar
Copy link
Author

Hey @matryer, I think it was working. I'm pretty sure I was looking for feedback here. Honestly, I'd have to open this back up and poke around. If you're happy with the basic implementation, I'll take some time this week to finish it up.

We may need to name the generated file differently for python, as you can't import python files with periods in the name.

for example, I cannot import the following
from .client.gen import GreetRequest

but I can import
from .clientgen import GreetRequest.

This is likely because it's parsing for .py.

@matryer matryer marked this pull request as ready for review March 28, 2021 12:07
parser/parser.go Outdated
case "int", "int16", "int32", "int64",
"uint", "uint16", "uint32", "uint64",
"float32", "float64":
ftype.JSType = "number"
ftype.SwiftType = "Double"
ftype.PythonType = "int"
Copy link
Contributor

Choose a reason for hiding this comment

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

will this type also handle floating point numbers?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. I believe that should be a float. Will update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants