Skip to content

Commit 0c72bb3

Browse files
Add special support for using mod_wsgi-express with shiv variant of a zipapp.
1 parent df1eda8 commit 0c72bb3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

docs/release-notes/version-4.6.5.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ Bugs Fixed
1313
document root, and the WSGI application was mounted at a sub URL using
1414
``--mount-point``, the static files in the document root outside of the
1515
mount point for the WSGI application would no longer be accessible.
16+
17+
New Features
18+
------------
19+
20+
* Now possible to use ``mod_wsgi-express`` in an a ``zipapp`` created using
21+
``shiv``. This entailed a special workaround to detect when ``shiv`` was
22+
used, so that the unpacked ``site-packages`` directory could be added to
23+
the Python module search path for ``mod_wsgi-express``.

src/server/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import time
1616
import traceback
1717
import locale
18+
import inspect
1819

1920
try:
2021
import Queue as queue
@@ -2871,6 +2872,28 @@ def _cmd_setup_server(command, args, options):
28712872
if options['python_paths'] is None:
28722873
options['python_paths'] = []
28732874

2875+
# Special case to check for when being executed from shiv variant
2876+
# of a zipapp application bundle. We need to work out where the
2877+
# site packages directory is and pass it with Python module search
2878+
# path so is known about by the Apache sub process when executed.
2879+
2880+
site_packages = []
2881+
2882+
if '_bootstrap' in sys.modules:
2883+
bootstrap = sys.modules['_bootstrap']
2884+
if 'bootstrap' in dir(bootstrap):
2885+
frame = inspect.currentframe()
2886+
while frame is not None:
2887+
code = frame.f_code
2888+
if (code and code.co_filename == bootstrap.__file__ and
2889+
code.co_name == 'bootstrap' and
2890+
'site_packages' in frame.f_locals):
2891+
site_packages.append(str(frame.f_locals['site_packages']))
2892+
break
2893+
frame = frame.f_back
2894+
2895+
options['python_paths'].extend(site_packages)
2896+
28742897
options['python_path'] = ':'.join(options['python_paths'])
28752898

28762899
options['multiprocess'] = options['processes'] is not None

0 commit comments

Comments
 (0)