summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-11-29 18:48:55 +0300
committerMax Romanov <max.romanov@nginx.com>2017-11-29 18:48:55 +0300
commit3781950badda9a937fdfaac25013006d9e106c67 (patch)
tree1f0109218ecfcb1dd9affc65b3fa8ee904e067c3 /src
parentec4ad8780e0afd7416c7ba7c32a1936e646cc286 (diff)
downloadunit-3781950badda9a937fdfaac25013006d9e106c67.tar.gz
unit-3781950badda9a937fdfaac25013006d9e106c67.tar.bz2
Introducing python virtualenv configuration.
New parameter 'home' for python application allows to configure application-specific virtualenv path. This closes #15 issue on GitHub.
Diffstat (limited to 'src')
-rw-r--r--src/nxt_application.h1
-rw-r--r--src/nxt_conf_validation.c7
-rw-r--r--src/nxt_main_process.c6
-rw-r--r--src/nxt_python_wsgi.c30
4 files changed, 44 insertions, 0 deletions
diff --git a/src/nxt_application.h b/src/nxt_application.h
index 00659a28..615efc37 100644
--- a/src/nxt_application.h
+++ b/src/nxt_application.h
@@ -34,6 +34,7 @@ typedef struct nxt_common_app_conf_s nxt_common_app_conf_t;
typedef struct {
+ char *home;
nxt_str_t path;
nxt_str_t module;
} nxt_python_app_conf_t;
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 80bfa885..cc2ce5ef 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -118,6 +118,11 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_python_members[] = {
NULL,
NULL },
+ { nxt_string("home"),
+ NXT_CONF_STRING,
+ NULL,
+ NULL },
+
{ nxt_string("path"),
NXT_CONF_STRING,
NULL,
@@ -545,3 +550,5 @@ nxt_conf_vldt_group(nxt_conf_validation_t *vldt, char *group)
return NXT_ERROR;
}
+
+
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index 767d6063..68d50aa1 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -121,6 +121,12 @@ static nxt_conf_map_t nxt_common_app_conf[] = {
},
{
+ nxt_string("home"),
+ NXT_CONF_MAP_CSTRZ,
+ offsetof(nxt_common_app_conf_t, u.python.home),
+ },
+
+ {
nxt_string("path"),
NXT_CONF_MAP_STR,
offsetof(nxt_common_app_conf_t, u.python.path),
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
index 51d9d800..36cd8e14 100644
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -177,6 +177,12 @@ static PyObject *nxt_py_application;
static PyObject *nxt_py_start_resp_obj;
static PyObject *nxt_py_environ_ptyp;
+#if PY_MAJOR_VERSION == 3
+static wchar_t *nxt_py_home;
+#else
+static char *nxt_py_home;
+#endif
+
static nxt_python_run_ctx_t *nxt_python_run_ctx;
@@ -194,6 +200,26 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
return NXT_ERROR;
}
+ if (c->home != NULL) {
+ size_t len;
+
+ len = nxt_strlen(c->home);
+
+ nxt_py_home = nxt_malloc(sizeof(*nxt_py_home) * (len + 1));
+ if (nxt_slow_path(nxt_py_home == NULL)) {
+ nxt_log_emerg(task->log, "Failed to allocate buffer for home path");
+ return NXT_ERROR;
+ }
+
+#if PY_MAJOR_VERSION == 3
+ mbstowcs(nxt_py_home, c->home, len + 1);
+#else
+ nxt_memcpy(nxt_py_home, c->home, len + 1);
+#endif
+
+ Py_SetPythonHome(nxt_py_home);
+ }
+
Py_InitializeEx(0);
obj = NULL;
@@ -301,6 +327,10 @@ fail:
Py_XDECREF(obj);
Py_XDECREF(module);
+ if (nxt_py_home != NULL) {
+ nxt_free(nxt_py_home);
+ }
+
return NXT_ERROR;
}