Run App Engine development server with modules in PyCharm - python

Since the latest release of the Google App Engine Python SDK, it's possible to use modules. I have a Python application with a default module and another module. To start the module in the development server, the development server has to be run like this:
dev_appserver.py app.yaml othermodule.yaml
When I add app.yaml othermodule.yaml to "Additional options" in the Run/Debug configuration of PyCharm and then run the development server, I get the following error message:
google.appengine.tools.devappserver2.errors.InvalidAppConfigError: "."
is a directory and a yaml configuration file is required
This is because PyCharm adds a dot at the end of the command to run the development server, like this:
dev_appserver.py app.yaml othermodule.yaml .
Is it possible to remove the dot, or do I have to wait until this is fixed in PyCharm? Before there were modules, there was no need for this.

You can go around this for the time being by just creating a new Run Configuration.
Chose Python configuration, then fill like this:
script: /path/to/your/dev_appserver.py
script parameters: dispatch.yaml module1.yaml module2.yaml
working directory: /path/to/your/appengine/project
It works just fine like this for me. The dispatcher is launching properly and I've got all the logs like before in PyCharm.

Related

No module named <FILENAME> when Flask and Pycharm are both in Debug mode

Recently I have updated Pycharm from 2020 to 2022.2.1 version.
In older version, using Flask debug mode
app.run_server(debug=True)
While debugging with Pycharm used to work.
But after updating, If I want to debug I must use debug=False in Flask.
This is very inconvenient as now I must re-run every instance of the application, where before it would rerun the every time a file has been changed.
Attached the error itself, and the run configuration.
This is only related to Flask as running a regular python file in the same directory works.
Any solutions?
I couldn't find anything related to this.

How to run python apps on a shared host with no bash or console command prompt privileges?

I want to run a python app called Flask on shared hosting but I don't have access to bash or command prompt or ssh but I am provided with:
Well, that's okay! Let me explain what I see in case the image cant be seen
Configuration files: A button that says RUN PIP INSTALL
A text field that says: Enter another file and press enter
Environment variables and an ADD button.
I know how to do this on my local machine
pip install flask
But how do I do it on the shared hosting?
I have a virtual environment that is just a folder but I can't access it since no ssh but it looks like
Well, I have figured it out and I want to share my experience here.
step 1.
on the cpanel, scroll and find python under software and click it.
step 2.
creat application
select python version
application root is where you will upload your data
Application startup file is and should be: init.py
Application Entry point will be: application
Passenger log file: blog.log
click create
step 3
open passenger_wsgi.py and type:
import os
import sys
from init import app as application
sys.path.insert(0, os.path.dirname(file))
save
step 4
creat you app on your lacal machine and pip freeze all requirement
copy the requirement.txt files and upload it to your application root folder and
click python again from your cpanel software and click edit your application
on Configuration files, type your requirement .txt and click add
then keep building your app on your lacal machine and upload your files they will run
This video was the best tutorial I could find on how to properly configure a shared host (cPanel/Phusion Passenger) to work with Flask.
The only other thing I do to avoid the importlib nagging warning
DeprecationWarning: the imp module is deprecated in favour of
importlib; see the module's documentation for alternative uses
is to change the default passenger_wsgi.py contents to
from app import app as application
Beware that this file might be rewritten when changing the application through the cPanel page.

Pycharm multiple modules Run server

I'm trying to use multiple modules in google app engine.
i try using this source code:
https://github.com/GoogleCloudPlatform/appengine-modules-helloworld-python
but i cant seem to find a way to run from pycharm with all the .yaml loaded, so only the app.yaml seem to load.
also when trying to upload the code to the appengine (using pycharm) i cant seem to upload all.
is there a way to solve it?
i saw similar question :
Run App Engine development server with modules in PyCharm
but no answer i could figure +
he didnt talked about uploading it to the appengine.
this are the logs :
"C:\PyCharm 4.0.5\bin\runnerw.exe" C:\Python27\python.exe "C:/Program Files (x86)/Google/google_appengine/dev_appserver.py" --host 127.0.0.1 .
INFO 2015-04-24 17:14:31,730 sdk_update_checker.py:229] Checking for updates to the SDK.
WARNING 2015-04-24 17:14:33,382 simple_search_stub.py:1126] Could not read search indexes from c:\users\ishwartz\appdata\local\temp\appengine.pythonfortau\search_indexes
INFO 2015-04-24 17:14:33,401 api_server.py:172] Starting API server at: http://localhost:60656
INFO 2015-04-24 17:14:33,414 dispatcher.py:186] Starting module "default" running at: http://127.0.0.1:8080
INFO 2015-04-24 17:14:33,424 admin_server.py:118] Starting admin server at: http://localhost:8000
nothing strange, they just ignore the other modules.
thanks.
FWIW, I was able to run a multi-module project on the devserver after adding the location of each module's .yaml file relative to the project dir in the Additional options section of the Run -> Edit Configurations menu.
Note: I'm using PyCharm 4.0.6 which has the fix for
PY-10675 - the subject of the similar question you mentioned.
This line in your Run log indicates you don't have the .yaml files for your modules included in the run configurations, it's just running with the default settings:
... (x86)/Google/google_appengine/dev_appserver.py" --host 127.0.0.1 .
Add these to your run configurations:
app.yaml mobile_frontend.yaml static_backend.yaml
With these configs in place you should see something like this in the first line of the Run log:
... (x86)/Google/google_appengine/dev_appserver.py" --host 127.0.0.1 app.yaml mobile_frontend.yaml static_backend.yaml
I'm not 100% sure if dispatch.yaml should also be included (I didn't yet use a dispatcher file in my projects) - follow the messages displayed in the Run console and try to add it as well if needed.
But I am stuck as well at the upload stage as I can't find a place for similar upload configs.
Confirmed by JetBrains as an issue, tracked as PY-15686.
Manual uploads appear to be the only workaround for now.

use dev_appserver.py for specific file in a directory

In order to start Google app engine through the cmd i use: dev_appserver.py --port=8080, but i can't figure how does it pick a file to run from the current directory.
My question is, is there an argument specifying a file to run in the server from all possible files in the directory?
dev_appserver doesn't "run a file" at all. It launches the GAE dev environment, and routes requests using the paths defined in app.yaml just like the production version.
If you need to route your requests to a specific Python file, you should define that in app.yaml.

Can Sentry be run under passenger WSGI (dreamhost)

I am trying to get sentry running on my dreamhost server. Dreamhost uses passenger wsgi to serve python frameworks, like django. I am able to get django apps running.
I am using virtualenv and I install sentry using pip, so all the code for sentry sits under the virtualenv directory. The instructions given for sentry doesn't use the startproject to create a directory that you can place somewhere for the passenger_wsgi.py file to find.
The sentry website gives examples of the program running under Nginx and uWSGI, but I am limited to (in this case) to apache and passenger wsgi.
Is it possible to run sentry under dreamhost's configuration and if so how does one pass things in like the config file to get it working. I have been able to locally start and interact with sentry, using :
sentry --config=/home/user/.sentry/sentry.conf.py start
so I know that all the dependencies are present on the host system
OK it looks like I was over thinking it, I forgot from a python perspective the file wsgi.py (which is found in the sentry directory) is called as sentry.wsgi when imported as a module. I was confused by sentry being a module that was downloaded from pip and how to access it. This is the reduced solution that works:
passenger_wgsi.py
import sys, os
INTERP = "/home/user/.virtualenv/sentry2/bin/python"
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
os.environ['SENTRY_CONF'] = "/home/user/.virtualenv/sentry2/sentry.conf.py"
import sentry.wsgi
believe it or not, that's it. If you look at the wsgi file in the sentry directory under the virtualenv install you will see it does all the importing of the django.core.handlers.wsgi and kicks off the correct application.

Categories