Skip to content

Commit

Permalink
Introduced pyuwsgi compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Jul 14, 2019
1 parent 8c4bb48 commit 07de1c8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ uwsgiconf changelog
===================


Unreleased
----------
+ Introduced pyuwsgi compatibility.


v0.15.3
-------
* Django contrib compatibility improved.
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ There are so many subsystems and options_ (800+) it is difficult to even try to
* It offers **runtime** package, similar to **uwsgidecorators**, but with more abstractions;
* It features integration with Django Framework;
* It is able to generate configuration files for Systemd, Upstart.
* It can use ``pyuwsgi``.


*Consider using IDE with autocompletion and docstings support to be more productive with uwsgiconf.*
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ There are so many subsystems and options_ (800+) it is difficult to even try to
* It offers **runtime** package, similar to **uwsgidecorators**, but with more abstractions;
* It features integration with Django Framework;
* It is able to generate configuration files for Systemd, Upstart.
* It can use ``pyuwsgi``.

*Consider using IDE with autocompletion and docstings support to be more productive with uwsgiconf.*

Expand Down
9 changes: 6 additions & 3 deletions uwsgiconf/contrib/django/uwsgify/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ def run_uwsgi(config_section, compile_only=False):

from uwsgiconf.utils import UwsgiRunner

UwsgiRunner.prepare_env() # Use uwsgi command from venv if any.

config_path = config.tofile()
os.execvp('uwsgi', ['uwsgi', '--ini=%s' % config_path])

runner = UwsgiRunner()
runner.spawn(
filepath=config_path,
configuration_alias=config.alias,
replace=True)
33 changes: 29 additions & 4 deletions uwsgiconf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from io import StringIO

from .settings import CONFIGS_MODULE_ATTR
from .exceptions import UwsgiconfException

if False: # pragma: nocover
from uwsgiconf.config import Configuration
Expand Down Expand Up @@ -398,12 +399,36 @@ def spawn(self, filepath, configuration_alias, replace=False):
:param bool replace: Whether a new process should replace current one.
"""
# Pass --conf as an argument to have a chance to use
# touch reloading form .py configuration file change.
args = ['uwsgi', '--ini', 'exec://%s %s --conf %s' % (self.binary_python, filepath, configuration_alias)]
args = ['uwsgi', '--ini']

if os.path.splitext(os.path.basename(filepath))[1] == '.ini':
args.append(filepath)

else:
# Consider it a python script (uwsgicfg.py).
# Pass --conf as an argument to have a chance to use
# touch reloading form .py configuration file change.
args.append('exec://%s %s --conf %s' % (self.binary_python, filepath, configuration_alias))

if replace:
return os.execvp('uwsgi', args)

try:

import pyuwsgi

args = args[1:]
pyuwsgi.run(args)

except ImportError:

try:
return os.execvp('uwsgi', args)

except FileNotFoundError:

raise UwsgiconfException(
'uWSGI executable not found. '
'Please make sure it is installed and available.')

return os.spawnvp(os.P_NOWAIT, 'uwsgi', args)

Expand Down

0 comments on commit 07de1c8

Please sign in to comment.