Script Development / Uploading User Python Modules
In some cases, the required Python modules by users are not published to the PyPi platform but exist directly in file form.
At this time, these files can be uploaded to the "user-python-packages/" directory of DataFlux Func's resource catalog and referenced directly in scripts.
1. Uploading Python Modules
Users can choose the upload method based on actual situations; there is no difference in the results.
Direct Upload to Host Machine
If the user has access permissions to the host machine, they can directly use familiar SSH tools to upload Python files/directories to the {installation directory}/data/resources/user-python-packages/
directory.
The default installation directory is /usr/local/dataflux-func. If unsure, you can check using cat /etc/dataflux-func
.
Using "File Management" to Upload
If the user does not have access permissions to the host machine, they can enable "Management / Experimental Features / Enable File Management" and then upload through "Management / File Management."
To prevent zip archives uploaded by users from disrupting the directory structure upon extraction, a directory will always be forcibly created during extraction in "File Management."
Therefore, if the uploaded zip archive already contains one layer of directories, an additional layer of directory structure will be added after extraction.
Based on actual conditions, move the Python module directory to user-python-packages/xxxxx
.
Go to the user-python-packages/
directory and confirm the Python package directory that needs to be uploaded.
2. Using the Uploaded Python Modules
Assume the uploaded Python module is as follows:
my_pkg/__init__.py | |
---|---|
1 |
|
my_pkg/hello_world.py | |
---|---|
1 2 |
|
Then, it can be imported directly in the script and used as follows:
Python | |
---|---|
1 2 3 4 5 |
|
3. Precautions
Uploaded Python modules should avoid name conflicts with other Python modules, and do not delete or rename directories that originally exist in extra-python-packages
.