Skip to content

Commit 19989e4

Browse files
Add the --python-path option to mod_wsgi-express to allow Python module search path directories to be specified to mod_wsgi-express as command line options.
1 parent 1dc587e commit 19989e4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docs/release-notes/version-4.3.3.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,11 @@ then coverage analysis is enabled. When the server is exited, then the
267267
profiler data will be output to the ``pstats.dat`` file under the server
268268
working directory, or the file specified using the ``profiler-output-file``
269269
option.
270+
271+
12. Added the ``--python-path`` option to ``mod_wsgi-express`` to specify
272+
additional directories that should be added to the Python module search path.
273+
274+
Note that these directories will not be processed for ``.pth`` files. If
275+
processing of ``.pth`` files is required, then the ``PYTHONPATH`` environment
276+
variable should be set and exported in a script file referred to using the
277+
``--envvars-script`` option.

src/server/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,8 @@ def __call__(self, environ, start_response):
10281028
import mod_wsgi.server
10291029
10301030
working_directory = '%(working_directory)s'
1031+
python_paths = %(python_paths)s
1032+
10311033
entry_point = '%(entry_point)s'
10321034
application_type = '%(application_type)s'
10331035
callable_object = '%(callable_object)s'
@@ -1044,6 +1046,9 @@ def __call__(self, environ, start_response):
10441046
enable_profiler = %(enable_profiler)s
10451047
profiler_output_file = '%(profiler_output_file)s'
10461048
1049+
if python_paths:
1050+
sys.path.extend(python_paths)
1051+
10471052
if debug_mode:
10481053
# We need to fiddle sys.path as we are not using daemon mode and so
10491054
# the working directory will not be added to sys.path by virtue of
@@ -1689,6 +1694,14 @@ def check_percentage(option, opt_str, value, parser):
16891694
default=apxs_config.ROTATELOGS, metavar='FILE-PATH',
16901695
help='Override the path to the rotatelogs executable.'),
16911696

1697+
optparse.make_option('--python-path', action='append',
1698+
dest='python_paths', metavar='DIRECTORY-PATH', help='Specify '
1699+
'the path to any additional directory that should be added to '
1700+
'the Python module search path. Note that these directories will '
1701+
'not be processed for \'.pth\' files. If processing of \'.pth\' '
1702+
'files is required, set the \'PYTHONPATH\' environment variable '
1703+
'in a script specified by the \'--envvars-script\' option.'),
1704+
16921705
optparse.make_option('--python-eggs', metavar='DIRECTORY-PATH',
16931706
help='Specify an alternate directory which should be used for '
16941707
'unpacking of Python eggs. Defaults to a sub directory of '

0 commit comments

Comments
 (0)