cloudtools / troposphere

troposphere - Python library to create AWS CloudFormation descriptions
BSD 2-Clause "Simplified" License
4.93k stars 1.44k forks source link

Missing intellisense #1462

Open davidobrien1985 opened 5 years ago

davidobrien1985 commented 5 years ago

Hi,

If this is some sort of misconfiguration on my end, please tell me to go away and fix my setup, but really, it's only happening with troposphere.

I use VS Code on Ubuntu and over the years I have gotten used to tools helping me to write code. Unfortunately, troposphere seems to be making my job really, really difficult.

from troposphere import Template as t, ec2
template = t()
base_vpc = ec2.VPC("vpc")

If I now start typing base_vpc. I would expect to be able to see properties like CidrBlock be available to me via intellisense / tab completion, but nada, it's not.

Similarly, when typing the properties inline to the object, I'd expect to see more than just template, but the actual properties, again, something like CidrBlock. image

I either have to move my mouse now and hover over VPC with a pressed Ctrl key

image

or actually look at the source by clicking onto the class.

This feels super unproductive.

If someone could please let me know what I have to do to get proper intellisense for troposphere, that'd be great.

Thanks, David

jstarcher commented 4 years ago

Exact same experience on my end. I actually was looking at Troposphere specifically for this capability over CloudFormation directly. The CF plugins leave a lot to be desired that I was hoping this project would fill the gap.

markpeek commented 4 years ago

As part of deprecating Python 2 and switching to Python 3 only (hopefully that won't be too controversial given the Python 2 EOL), I am looking at various implementation strategies to support a intellisense. Just need those extra free cycles to work on it. :-)

ns-cweber commented 4 years ago

@markpeek Seems like a good opportunity to support Mypy as well. Mypy at least has a limited ability to follow metaclasses, and from my experience, VS Code's intellisense seems to behave pretty similarly to Mypy. If you support mypy, you might get intellisense for free?

lautjy commented 3 years ago

Might be a big rewrite (or not too big), but I've had Great experiences with Pydantic when it comes work like this. https://github.com/samuelcolvin/pydantic

The change is that all the classes inherit from pydantic.BaseModel. Big rewrite might come if there is lots of code that depend on something in the current props = {..} system. And rewrites would have to be there to catch what happens when Pydantic model validation fails.

MacHu-GWU commented 3 years ago

@lautjy I can think of either pydantic or attrs they are both very good integrated with Sublime, VSCode and PyCharm.

That's why I did a project troposphere_mate that using jinja2 template engine to recreate troposphere with attrs. It gives me a lot of auto-complete.

My point is, troposphere team should not use props = {...} to declare those properties, they should use crawler or something to get the schema and typing for all aws resource and properties. And then use template engine like jinja2 to generate those class declaration code in pydantic / attrs / data class / even the raw Python Class declaration. Maintain those troposphere feature in Parent Base Class. That would be future of troposphere 3.0. Otherwise I feel like troposphere will die if AWS CDK getting better and better. To be honest, there's still a lot of thing troposphere can do but AWS CDK cannot.