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

Make it easier to debug functions in IDEs #29

Closed
yuri-sergiichuk opened this issue Apr 8, 2020 · 10 comments · Fixed by #31
Closed

Make it easier to debug functions in IDEs #29

yuri-sergiichuk opened this issue Apr 8, 2020 · 10 comments · Fixed by #31
Labels
enhancement New feature or request

Comments

@yuri-sergiichuk
Copy link

Currently, it is super hard to configure the local debug of the functions in PyCharm, moreover, I found it impossible without hacking the cli.py.

Here is a way to do it in PyCharm now:

  1. Add main function to the cli.py:
    if __name__ == '__main__':
        cli(sys.argv[1:])
  2. Create PyCharm Python config and choose functions_framework\cli.py as a script.
  3. Pass required params as Parameters in the configuration, e.g. --port 8088 --signature-type http, etc.
  4. Make sure to set the working directory to the project root (so that the functions framework is able to load the entry point function).
  5. Run the created configurations and use PyCharm debugger.

What we can to make life easier:

  1. Create __main__.py in the functions_framework module and allow running the module as the CLI. Or, add the main function to the cli.py itself, maybe worth having both.
  2. Create well-structured documentation about debugging functions locally with popular IDEs (PyCharm, VSCode, others?)
@di di added the enhancement New feature or request label Apr 8, 2020
@di
Copy link
Member

di commented Apr 8, 2020

Thanks for the report!

I'm not that familiar with PyCharm so bear with me: is it not possible to use a command like functions-framework --debug --port 8088 --signature-type http? It has to be some importable Python script?

I think it would be reasonable to add a __main__.py and support python -m functions_framework, just want to make sure I understand the issue here.

@yuri-sergiichuk
Copy link
Author

PyCharm has its own debugger that is injected as a sidecar to the module being run with lots of cool functions.

The --debug here enabled Flask's debug mode and Flask has its own debugger. I have not found a way to make them work together. That's why I need a way to run the functions_framework either as a module or as a script so that PyCharm can do its debug-related magic.

@di
Copy link
Member

di commented Apr 8, 2020

Hi @yuri-sergiichuk, can you try this branch and let me know if it works for you?

You should be able to install it with:

pip install git+https://github.com/googlecloudplatform/functions-framework-python.git@add-main

@yuri-sergiichuk
Copy link
Author

yuri-sergiichuk commented Apr 8, 2020

Hi @di. Yes, I can run it as a module now and for PyCharm that it enough.

Also, maybe it still worth having the __main__ in the cli.py? I'm not sure how debuggers work in other IDEs, but right now I still cannot run the cli.py directly.

Also, I use pipenv over pip to manage dependencies, so in case it'd be helpful for someone, with pipenv one can install a dependency from a specific branch with:

pipenv install -e git+https://github.com/googlecloudplatform/functions-framework-python.git@add-main#egg=functions-framework

@di
Copy link
Member

di commented Apr 8, 2020

Great!

Also, maybe it still worth having the __main__ in the cli.py? I'm not sure how debuggers work in other IDEs, but right now I still cannot run the cli.py directly.

This particular file is not meant to be run directly. I renamed it _cli in #31 to make this more clear.

@di di closed this as completed in #31 Apr 8, 2020
@di
Copy link
Member

di commented Apr 13, 2020

Released in functions-framework==1.3.0.

@yan-hic
Copy link

yan-hic commented Jun 9, 2020

Hi @di. Yes, I can run it as a module now and for PyCharm that it enough.

@yuri-sergiichuk can you share what you did in Pycharm to make it run in debug i.e. stop at breakpoints ?

@yan-hic
Copy link

yan-hic commented Jun 9, 2020

nvm - found it:
image

@dibusan
Copy link

dibusan commented Nov 22, 2021

nvm - found it: image

I got it running, but breakpoints are not stopping. Any ideas ?

@dibusan
Copy link

dibusan commented Nov 22, 2021

Update: removing --debug fixed it. It now stops at breakpoints.

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

Successfully merging a pull request may close this issue.

4 participants