jsii icon indicating copy to clipboard operation
jsii copied to clipboard

Python pdb support?

Open pd5rm opened this issue 6 years ago • 3 comments

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.

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

pd5rm avatar Oct 29 '19 21:10 pd5rm

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

joekiller avatar Nov 27 '19 15:11 joekiller

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.

TheRealAmazonKendra avatar Jan 27 '23 02:01 TheRealAmazonKendra

transferring to jsii

pahud avatar Jun 04 '24 15:06 pahud