I come from working with nodejs and serverless framework, where I can configure esbuild so that functions that require other functions are in a single bundle file.
Now I am working python with serverless framework, however, when I import an external function, and deploy. In the function bundle the whole project is uploaded. Clearly this would increase costs and delay the startup of the functions.
I have been reading about mock plugins serverless-python-individually, serverless-package-python-functions but i have not been able to package the function and its dependencies individually.
Is there any way to package the dependencies of the lambda functions individually?
example:
In nodejs I have the following structure:
api/
├─ v1/
│ ├─ handler/
│ │ ├─ fileHandler.js
│ ├─ anotherlambda/
│ │ ├─ index.js
│ ├─ s3Storage/
│ │ ├─ index.js
serverless.yml
When I deploy, it looks like this:
api/
├─ v1/
│ ├─ handler/
│ │ ├─ fileHandler.js
Where in fileHandler.js the code of the s3Storage/index.js dependency is inserted.
In python I have the following structure:
api/
├─ v1/
│ ├─ handler/
│ │ ├─ fileHandler.py
│ ├─ anotherlambda/
│ │ ├─ hello.py
│ ├─ s3Storage/
│ │ ├─ index.py
I would like to know if there is a way to package it in the same way as with nodejs esbuild.
Related
├─ alpha
|
├─ beta_folder
│ ├─ __init__.py
| ├─ main.py
│ └─ beta.py
├──── conftest.py
└────gamma_folder
├─ __init__.py
├─ main.py
└─ gamma.py
How can I, when testing gamma_folder module call a single test from beta_folder module using pytest?
I've tried injecting a function through hooks, but never successful.
Given the following project structure:
root
└── dir1
├─ setup.py
├─ script1.py
├── processor
│ ├─ preprocessor.py
│ └─ postprocessor.py
│
├──src_dir
│ ├─ predictor.py
│ └─ script2.py
│
I would like the custom package to ONLY contain the two scripts inside the processor folder and the predictor.pyscript. Moreover, the scripts should be accessible via from processor.preprocessor import ... while the predictor to be in the main root and therefore importable as from predictor import ....
I I should then run the following setup script: python setup.py sdist --formats=gztar:
from setuptools import setup
setup(name="processors",
version="0.1",
...
)
Is it possible to have a separate directory for Python nodes in ROS2 (foxy)?
python_pkg/
│
├─ python_pkg/
│ ├─ __init__.py
│ ├─ my_module.py
│ └─ hello_world.py
|
├─ nodes/
│ ├─ __init__.py
│ └─ simple_node.py
|
└─ ...
In setup.py I have tried adding:
setup(
name="python_pkg",
...
entry_points={
'console_scripts': [
'hello_world = python_pkg.hello_world:main',
'simple_node = nodes.simple_node:main',
],
},
)
If I source the workspace and run ros2 run python_pkg simple_node I get the error ModuleNotFoundError: No module named 'nodes'.
I was running flask app using app.run till now. But when I was trying to use flask-migrate, it throws an error when I am trying 'flask run'
File directory is like this:
project/
├─ project/
│ ├─ static/
│ │ ├─ app.js
│ ├─ templates/
│ │ ├─ base.html
│ ├─ routes.py
│ ├─ __init__.py
│ ├─ forms.py
│ ├─ models.py
├─ run.py
├─ setup.py
├─ MANIFEST.in
I was following documentation, but it did not work. 'python run.py' works but 'flask run' is not working.
export FLASK_APP=project
export FLASK_ENV=development
Error: While importing 'project', an ImportError was raised.
How can I solve this problem?
try, to change the FLASK_APP value
export FLASK_APP=run
...
As far as I understood from the Flask docs - the FLASK_APP value needs to be the same as the "main app" filename (just without the .py)
docs for ref: https://flask.palletsprojects.com/en/2.0.x/quickstart/#a-minimal-application3
I can run test_pkg1.py and test_pkg2.py
but when I run test.py
Error occurred at test_pkg1.py
Exception has occurred: ImportError
cannot import name 'a' from 'tools' (unknown location)
root
├─ pkg1
│ ├─ tools
│ │ ├─ __init__.py
│ │ └─ a.py
│ ├─ __init__.py.py
│ └─ test_pkg1.py
├─ pkg2
│ ├─ tools
│ │ ├─ __init__.py
│ │ └─ b.py
│ ├─ __init__.py.py
│ └─ test_pkg2.py
├─ test.py
└─ d.py
test_pkg1.py
from tools import a
test_pkg2.py
from tools import b
test.py
from pkg2 import test_pkg2
from pkg1 import test_pkg1
In Python, import paths are always relative to the directory where the main program is executed unless you explicitly use a relative import by preceding the package name with a dot, which then makes the interpreter look for the package in the same directory as the module where the import is made:
test_pkg1.py:
from .tools import a
You also need to create an __init__.py file in the directory where the main program runs in order for that directory to be considered a package under which relative imports can be made.