aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.59k stars 242 forks source link

Python pdb support? #4535

Open pd5rm opened 4 years ago

pd5rm commented 4 years ago

It would nice to be able to use built in 'pdb' Python debugger module to inspect/step through generation of template.

Use Case

This would allow us to use native breakpoints, instead of using print-log style debugging.

Proposed Solution

Other

Currently, when I use pdb, it fails with following trace:

(.env) username@sabu:~/git/PROJ-cdk-customer$ cdk diff
> /home/username/git/PROJ-cdk-customer/PROJ_cdk_customer/customer_stack.py(77)addVPNConnections()
-> for count,customer_gateway_id in enumerate(customer_gateway_ids):
(Pdb) 
Traceback (most recent call last):
  File "app.py", line 29, in <module>
    customerStack(app,"customerStack-%s" % region, PROJConfig, env=core.Environment(region=region))
  File "/home/username/git/PROJ-cdk-customer/.env/lib/python3.7/site-packages/jsii/_runtime.py", line 66, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/home/username/git/PROJ-cdk-customer/PROJ_cdk_customer/customer_stack.py", line 32, in __init__
    self.PROJvpc.addVPNConnections(config.shortname,config.get_resource_for(config.VPN_CUSTOMER_GATEWAY_KEY))
  File "/home/username/git/PROJ-cdk-customer/PROJ_cdk_customer/customer_stack.py", line 77, in addVPNConnections
    for count,customer_gateway_id in enumerate(customer_gateway_ids):
  File "/home/username/git/PROJ-cdk-customer/PROJ_cdk_customer/customer_stack.py", line 77, in addVPNConnections
    for count,customer_gateway_id in enumerate(customer_gateway_ids):
  File "/usr/lib/python3.7/bdb.py", line 88, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python3.7/bdb.py", line 113, in dispatch_line
    if self.quitting: raise BdbQuit

I think this results from CDK trying to dump stuff to stdout and pdb expecting to handle user input from stdin.


This is a :rocket: Feature Request

joekiller commented 4 years ago

You can debug via unit tests.

app=core.App()  # use constuctor to set context as needed. Also can set output directory of synthesized templates
stack = core.Stack(app) # put a breakpoint here
MyConstruct(stack, "customThing")
result = app.synth()
assert result.stacks[0] == expected_template
TheRealAmazonKendra commented 1 year ago

It appears that this is an issue that needs to be fixed in jsii. I'm going to move this issue over to that repository.

pahud commented 4 weeks ago

transferring to jsii