troposphere icon indicating copy to clipboard operation
troposphere copied to clipboard

Missing intellisense

Open davidobrien1985 opened this issue 5 years ago • 5 comments

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

davidobrien1985 avatar Jul 23 '19 04:07 davidobrien1985

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.

jstarcher avatar Dec 19 '19 00:12 jstarcher

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. :-)

markpeek avatar Dec 19 '19 01:12 markpeek

@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?

ns-cweber avatar Jan 09 '20 20:01 ns-cweber

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.

lautjy avatar Apr 06 '21 07:04 lautjy

@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.

MacHu-GWU avatar Jun 22 '21 01:06 MacHu-GWU