Lexpedite / blawx

A user-friendly web-based tool for Rules as Code.
MIT License
96 stars 9 forks source link

WSGI invocation fails #585

Open handshape opened 4 months ago

handshape commented 4 months ago

Hi there - I have need to deploy blawx at a URL offset from the root of the server. The usual way to do this in django is to run it in a WSGI container with an offset, but when I invoke the existing wsgi.py using such a mapping, (after installing all the requirements) I get the following:

[Thu Mar 07 15:35:20.608652 2024] [wsgi:error] [REDACTED] mod_wsgi (pid=7225): Failed to exec Python script file '/var/www/html/blawx/blawx/wsgi.py'.
[Thu Mar 07 15:35:20.608720 2024] [wsgi:error] [REDACTED] mod_wsgi (pid=7225): Exception occurred processing WSGI script '/var/www/html/blawx/blawx/wsgi.py'.
[Thu Mar 07 15:35:20.609204 2024] [wsgi:error] [REDACTED] Traceback (most recent call last):
[Thu Mar 07 15:35:20.609276 2024] [wsgi:error] [REDACTED]   File "/var/www/html/blawx/blawx/wsgi.py", line 16, in <module>
[Thu Mar 07 15:35:20.609290 2024] [wsgi:error] [REDACTED]     application = get_wsgi_application()
[Thu Mar 07 15:35:20.609301 2024] [wsgi:error] [REDACTED]   File "/usr/local/lib/python3.10/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Thu Mar 07 15:35:20.609308 2024] [wsgi:error] [REDACTED]     django.setup(set_prefix=False)
[Thu Mar 07 15:35:20.609317 2024] [wsgi:error] [REDACTED]   File "/usr/local/lib/python3.10/dist-packages/django/__init__.py", line 19, in setup
[Thu Mar 07 15:35:20.609324 2024] [wsgi:error] [REDACTED]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Mar 07 15:35:20.609331 2024] [wsgi:error] [REDACTED]   File "/usr/local/lib/python3.10/dist-packages/django/conf/__init__.py", line 89, in __getattr__
[Thu Mar 07 15:35:20.609337 2024] [wsgi:error] [REDACTED]     self._setup(name)
[Thu Mar 07 15:35:20.609345 2024] [wsgi:error] [REDACTED]   File "/usr/local/lib/python3.10/dist-packages/django/conf/__init__.py", line 76, in _setup
[Thu Mar 07 15:35:20.609351 2024] [wsgi:error] [REDACTED]     self._wrapped = Settings(settings_module)
[Thu Mar 07 15:35:20.609358 2024] [wsgi:error] [REDACTED]   File "/usr/local/lib/python3.10/dist-packages/django/conf/__init__.py", line 190, in __init__
[Thu Mar 07 15:35:20.609364 2024] [wsgi:error] [REDACTED]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Mar 07 15:35:20.609371 2024] [wsgi:error] [REDACTED]   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
[Thu Mar 07 15:35:20.609377 2024] [wsgi:error] [REDACTED]     return _bootstrap._gcd_import(name[level:], package, level)
[Thu Mar 07 15:35:20.609384 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Thu Mar 07 15:35:20.609392 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Thu Mar 07 15:35:20.609399 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
[Thu Mar 07 15:35:20.609427 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[Thu Mar 07 15:35:20.609435 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Thu Mar 07 15:35:20.609443 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Thu Mar 07 15:35:20.609451 2024] [wsgi:error] [REDACTED]   File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
[Thu Mar 07 15:35:20.609470 2024] [wsgi:error] [REDACTED] ModuleNotFoundError: No module named 'blawx'
Gauntlet173 commented 4 months ago

That's not a use that I've experimented with. I've also never tried to deploy it with apache, so take this with a grain of salt.

The Blawx source code doesn't package the code as a module for use by other Python code on the same system. I suspect that the problem is that Blawx is not "installed" as a Python module, so the namespace is only available to Python scripts running in the root folder of the project.

Blawx doesn't have a setup.py file to facilitate installing it, or anything along those lines, and it's beyond my current capacity to build one at the moment. You could create one and install it that way, or use any of the other methods like moving the code into site packages for the python interpreter, or adding the location of the Blawx code to the python search path.

I presume you are doing this inside a revised docker container based on the existing Dockerfile. Otherwise Blawx will not have access to the Prolog dependencies even if you manage to import it into your code.

I can't promise that there aren't other issues that arise when using Blawx as a Python module. Off the top of my head, it wouldn't surprise me if you needed to change how some of the imports are written. But I'd be happy to look at a PR for whatever you get working.

handshape commented 4 months ago

I've had to dive deep on this; there are references to absolute paths all through both the server and client-side code.

I've brute-forced my immediate need, but hope to be able to post a PR for this eventually.