From: WALDEMAR KOZACZUK <[email protected]>
Committer: GitHub <[email protected]>
Branch: master
Merge pull request #61 from pshem/patch-1
Add a way to include extra python3 modules
---
diff --git a/python3x/GET b/python3x/GET
--- a/python3x/GET
+++ b/python3x/GET
@@ -8,6 +8,8 @@ PYTHON_PREFIX_DIR=`python3 -c 'import sys;
print(sys.prefix)'`
PYTHON_MAJOR_VERSION=`python3 -c 'import sys;
print(sys.version_info.major)'`
PYTHON_MINOR_VERSION=`python3 -c 'import sys;
print(sys.version_info.minor)'`
PYTHON_VERSION="${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}"
+PYTHON_MODULES="" #put additional modules here. Example: "django mysql
mysql.connector"
+
install_shlibs() {
SHLIBS=""
@@ -25,6 +27,32 @@ ldd $SHLIBS | grep -Po '(?<=> )/[^ ]+' | sort | uniq |
grep -Pv 'lib(c|gcc|dl|m|
echo "$SHLIBS_COUNT"
}
+get_paths() {
+python3 - <<'EOF' "$1"
+import sys
+
+unique_paths = set([])
+
+#import all additional modules
+for mod in sys.argv[1].split():
+ try:
+ exec('import ' + mod)
+ if str(eval(mod + '.__file__')[-12:]) != '/__init__.py':
+ unique_paths.add(eval(mod + '.__file__'))
+ else:
+ unique_paths.add(eval(mod + '.__path__[0]'))
+
+ except NameError: #module not imported. Try to import
+ raise Exception("You misspelled the module name")
+ except AttributeError:
+ pass #built-in modules don't have __file__
+
+print(" ".join(unique_paths))
+
+EOF
+}
+
+
main() {
mkdir -p build/
gcc -o build/python.so python.c -fPIC -shared -lpython${PYTHON_VERSION}m
@@ -41,6 +69,12 @@ do
--exclude '*.pyc' --exclude '*.pyo' --exclude '*.egg-info'
--exclude 'site-packages' --exclude 'dist-packages'
done
+for i in $(get_paths "${PYTHON_MODULES}")
+do
+ rsync -a "$i" $ROOTFS/lib/python${PYTHON_VERSION}/ --safe-links \
+ --exclude '*.pyc' --exclude '*.pyo' --exclude '*.egg-info'
+done
+
SHLIBS_COUNT4=`install_shlibs`
echo "Python SHLIBS_COUNT4=$SHLIBS_COUNT4"
SHLIBS_COUNT3=`install_shlibs`
diff --git a/python3x/README b/python3x/README
--- a/python3x/README
+++ b/python3x/README
@@ -9,9 +9,11 @@ sudo dnf install python3-devel # On Fedora
The python home directory is assumed to be installed under
<sys.prefix>/lib/python<sys.version_info.major>.<sys.version_info.minor>/
-where sys is Python package this script reads the sys.* values from. Please
-note that any extra modules found under site-packages or dist-packages
-directories are filtered out from the image.
+where sys is Python package this script reads the sys.* values from.
+
+Please note that any extra modules found under site-packages or
dist-packages
+directories are filtered out from the image. You can add extra modules by
editing
+the PYTHON_MODULES variable in the GET script.
Example usage:
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.