Debug Flask with complicated project structure

I'm new to debugging flask with pycharm, so hopefully nothing I ask is too trivial.

I have two files

code/__init__.py and code/runserver.py

In the __init__ file is the where my Flask app is initialized meaning that is where the statement :

app = Flask(__name__) 

prettyPrint();
occurs.

In the runserver.py file is where I have the statement

if __name__ == '__main__':
    main()

prettyPrint();


The runserver imports the app in the following manner :

from code import app, __app_name__, __version__
prettyPrint();

Inside of the main function are a number of parser.addoption commands and then ultimately

def main():
parser = OptionParser()
    parser.add_option("-d","--debug",action="store_true",default=app.config.get('DEBUG',True),dest="debug",help="Turn on debugging")

(options,args) = parser.parse_args()

app.run(debug=options.debug,host=options.address,port=options.port)
prettyPrint();


In this case what would my entry point for debugging the application be?
I assumed it would be runserver.py but when I attempt to debug this I get the response of

ImportError: No module named code

If however I run it like

   python ${BASE}/code/runserver.py
prettyPrint();

I don't have any issue.
2 comments
You need to upgrade to PyCharm 2.7.2 EAP (http://blog.jetbrains.com/pycharm/2013/03/pycharm-2-7-2-eap/) and turn off the options for adding content roots and source roots to PYTHONPATH in the settings of the run configuration that you use to start your app. Alternatively, rename your project directory from "code" to something that does not match the name of a standard library module (http://docs.python.org/2/library/code.html)
0
Thanks for your reply.


First my project directory was not actually named 'code' I had just listed it as that for sanitization purposes.

I'd prefer not too download the EAP for stability purposes.

One piece of information I forgot to include in my initial report was that I am running in a virtualenv. My issue seems to be identical to the one posted here : http://stackoverflow.com/questions/10437661/importerror-no-module-named-test-data-but-test-data-py-in-same-directory-as-te

I chose to add my 'code' directory as source in my project interpreter settings and that resolved my issue.

If I run across anything else I'll download the EAP
0

Please sign in to leave a comment.