I have a flask project with the following structure:
/27_shop_score
/app
/static
/tasks
/templates
__init__.py
routes.py
.flaskenv
Procfile
shop_score.py
Contents of the .flaskenv is FLASK_APP=shop_score.py
Contents of the shop_score.py is from app import app
The app is being initialized in /27_shop_score/app/__init__.py as app = Flask(__name__).
I'm getting the following error in heroku logs --tail:
2019-03-16T12:51:26.909725+00:00 app[web.1]: File "/app/shop_score.py", line 6, in <module>
2019-03-16T12:51:26.909726+00:00 app[web.1]: from app import app
2019-03-16T12:51:26.909730+00:00 app[web.1]: ImportError: cannot import name 'app'
Of course, locally this issue is absent.
The sys.path is ['/app/.heroku/python/bin', '/app', '/app/.heroku/python/lib/python36.zip', '/app/.heroku/python/lib/python3.6', '/app/.heroku/python/lib/python3.6/lib-dynload', '/app/.heroku/python/lib/python3.6/site-packages'].
os.listdir(sys.path[1]) is
['.profile.d', 'robots.txt', 'README.md', '.gitignore', '__pycache__', 'celeryconfig.py', 'requirements.txt', '.editorconfig', 'runtime.txt', '.flaskenv', 'shop_score.py', 'Procfile', 'app', '.heroku'].
The whole app is here: https://github.com/mxmaslin/27_shop_score
Can you please give me a clue of what am I doing wrong?
Related
I'm facing an issue in a ROS (Python 2.7) project.
Strucure
I'm working on a ROS project. The structure is the following:
probable-adventure
|
|-catkin_ws
|-src
|-ros_rover
|-include
|-launch
|-msg
|-__init__.py
|-Commands.msg
|-Teleoperation.msg
|-scripts
|-__init__.py
|-keyboard.py
|-test
|-__init__.py
|-testing.py
|-__init__.py
|-CMakeLists.txt
|-package.xml
Keyboard node (secondary problem)
keyboard.py starts as follows:
#!/usr/bin/env python
import rospy
from ros_rover.msg import Teleoperation
I describe it as a secondary problem because if I compile the project from catkin_ws directory using catkin_make command, everything works well and I can run the keyboard ROS node perfectly even though I get a pylint error in the from ros_rover.msg ... line.
Unable to import 'ros_rover.msg'
Main Problem
I just wrote the previous as context. The point is that I have to test the code within the scripts directory. I'm using unittest and I create python files in test directory.
I have create the following simple test (testing.py):
#!/usr/bin/env python
import unittest
from scripts.keyboard import GetKey
class TestBareBones(unittest.TestCase):
def test_one_equals_one(self):
self.assertEquals(1, 1, "1!=1")
if __name__ == '__main__':
unittest.main()
I think I have a problem with the imports because if I run the following python commands (from the ros_rover directory):
user#dubuntu:~/probable-adventure/catkin_ws/src/ros_rover$ python testing.py
user#dubuntu:~/probable-adventure/catkin_ws/src/ros_rover$ python -m testing
I get the following error:
File "/home/diego/Documents/probable-adventure/catkin_ws/src/ros_rover/test/prueba.py", line 5, in <module>
from scripts.keyboard import GetKey
File "scripts/keyboard.py", line 14, in <module>
from ros_rover.msg import Teleoperation
ImportError: No module named ros_rover.msg
My thought
I think the problem is related with imports because I have read that python imports depends on the directory from where you run the python command.
I run the test from ros_rover directory because the test's import is scripts.keyboard so it can found it (scripts is in ros_rover). But when the keyboard.py tries to import ros_rover.msg fails because I'm already in ros_rover directory and cannot find ros_rover.
I have read a lot here in StackOverflow and out of it but I didn't find a solution (I have added a empty __init__.py file to ros_rover, scripts and test directories).
I deployed a rails 6 app with webpacker on heroku.
The public/packs are sync to an s3 bucket, same as the public/assets.
Delivering assets from public/assets works. But when trying to open anything dependent on public/packs I get.
2020-06-04T05:33:03.622234+00:00 app[web.1]: [58f2d221-761b-44ec-807c-6b922342c10b] method=GET path=/teach/organizations format=html controller=OrganizationsController action=index status=500 error='ActionView::Template::Error: Webpacker can't find admin_unify_style.css in /app/public/packs/manifest.json. Possible causes:
2020-06-04T05:33:03.622242+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2020-06-04T05:33:03.622242+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2020-06-04T05:33:03.622243+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2020-06-04T05:33:03.622243+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2020-06-04T05:33:03.622244+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2020-06-04T05:33:03.622244+00:00 app[web.1]: Your manifest contains:
2020-06-04T05:33:03.622245+00:00 app[web.1]: {
2020-06-04T05:33:03.622245+00:00 app[web.1]: }
How is heroku expected to find about the manifest on heroku. The manifest contains
"entrypoints": {
"admin_unify_style": {
"css": [
"/packs/css/admin_unify_style-c2ad729a.css"
],
"js": [
"/packs/js/admin_unify_style-62270c86710162620f91.js"
],
"js.map": [
"/packs/js/admin_unify_style-62270c86710162620f91.js.map"
]
Update 1:
It is working in production env outside of heroku and without assets on cloudfront
Long story short - the manifest should be on heroku, while the assets could be on s3
Here is how I got it working - Heroku, S3, Cloudfront, Webpacker, Rails 6, Sprockets.
Assets are precompiled and uploaded to s3. public/assets and public/packs are ignored from the repo.
public/assets/*
!public/assets/.sprockets-manifest*
public/packs/*
!public/packs/manifest.json*
But as you could see the manifest are not.
Cloudfront is configured for production with
config.action_controller.asset_host = "https://blabla.cloudfront.net"
public/assets and public/fonts are synced on s3 with a s3cmd command. Custom script.
After the are synced to s3 we are commiting the manifests
if git ls-files -m | grep "public/assets/.sprockets-manifest\|public/packs/manifest.json*"; then
git add --all public/assets/.sprockets-manifest* -f
git add --all public/packs/manifest.json* -f
git commit -m "Autocompiling assets from jenkins"
git push
fi
In this way we only have the two manifests in the repo with all the assets on S3.
5. Push to heroku and it works. For now, like charm
I need to periodically delete files of an uploads folder on heroku in python.
I've tried the heroku scheduler but I am constantly getting a fileNotFound error which I am unable to fix.
from flask_script import Manager
from app import app
manager = Manager(app)
#manager.command
def hello():
folder_path = '/uploads/'
for file_object in os.listdir(folder_path):
file_object_path = os.path.join(folder_path, file_object)
if os.path.isfile(file_object_path):
os.unlink(file_object_path)
else:
shutil.rmtree(file_object_path)
Here is my test import I use in App.js
import {test} from './utils/configs';
Here is my ./utils/configs:
export const test = 'test-string'
App.js and Utils folder are in a same level. IDE finds import perfectly, but Xcode simulator throws error:
Unable to resolve module ./utils/configs from /Users/riku/Documents/StreamrLabs/streamr-ios-location-poc/App.js: The module ./utils/configs could not be found from /Users/riku/Documents/StreamrLabs/streamr-ios-location-poc/App.js. Indeed, none of these files exist:
/Users/User/Documents/Folder/projectname/utils/configs(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)
/Users/User/Documents/Folder/projectname/utils/configs/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)
It seems that importing new modules breaks Xcode/bundler. My app is detatched expo app.
Files should have an extension ! (configs.js in this case).
Xcode is trying to find .js files, and here, there is no extension !
(solution for record)
I've cloned this repo:
https://github.com/lvillani/quickstart-jekyll-zurb
I got it working locally no problem.
I added a Procfile with the following:
web: bundle exec jekyll serve -P $PORT
Heroku accepts the bundle no problem.
But the server crashes when trying to load a page.
The first problem I had was that it was trying to render a misformated vendor page.
I fixed that by adding this to _config.yml:
exclude:
- "vendor/bundle/ruby
But now my app.scss file can't #import "foundation/settings";.
Here is the relevant portion of the Heroku logs.
"2014-10-16T19:56:05.366451+00:00 app[web.1]: Generating...
2014-10-16T19:56:05.361060+00:00 app[web.1]: Configuration file: /app/_config.yml
2014-10-16T19:56:06.277480+00:00 app[web.1]: Conversion error: There was an error converting 'asset/app.scss'.
2014-10-16T19:56:06.277526+00:00 app[web.1]: jekyll 2.1.1 | Error: File to import not found or unreadable: foundation/settings.
2014-10-16T19:56:06.277529+00:00 app[web.1]: Load path: /app/_vendor/foundation/scss
Everything works fine locally, so I assume this is a Heroku configuration issue but I don't know enough about Heroku to begin to know where to look.
thanks!
Maybe you forgot to run a make setup.
Note that your jekyll is 2.1.1 and current version is 2.4.