Skip to content

Commit

Permalink
Merge branch 'rel_sa_gunicorn' of https://github.com/ali96343/py4web
Browse files Browse the repository at this point in the history
…into rel_sa_gunicorn
  • Loading branch information
ali96343 committed Nov 26, 2023
2 parents b3a7278 + ab649f5 commit 002ce4f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 81 deletions.
35 changes: 15 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean venv docs clean-assets assets test setup run build deploy
.PHONY: clean docs clean-assets assets test setup run build deploy
asset-apps := _dashboard _default _scaffold _minimal _documentation showcase
asset-zips := $(asset-apps:%=py4web/assets/py4web.app.%.zip)
clean:
Expand All @@ -14,30 +14,25 @@ py4web/assets/py4web.app.%.zip: apps/%
cd $< && find . | \
egrep "\.(py|html|css|js|png|jpg|gif|json|yaml|md|txt|mm|ico)$$" | \
zip -@ $(addprefix ../../, $@)
venv:
python -m venv venv
venv/bin/pip install -U pip
venv/bin/pip install -U -r requirements.txt
venv/bin/pip install ./
docs: venv
venv/bin/pip install -U -r docs/requirements.txt
cd docs; . ../venv/bin/activate && ./updateDocs.sh html
test: venv
venv/bin/pip install -U -r test-requirements.txt
venv/bin/python -m pytest --cov=py4web --cov-report html:cov.html -v tests/
docs:
.venv/bin/pip install -U -r docs/requirements.txt
cd docs; ./updateDocs.sh html
test:
.venv/bin/pip install -U -r test-requirements.txt
.venv/bin/python -m pytest --cov=py4web --cov-report html:cov.html -v tests/
setup:
venv/bin/python py4web.py setup apps
venv/bin/python py4web.py set_password
.venv/bin/python py4web.py setup apps
.venv/bin/python py4web.py set_password
run:
venv/bin/python py4web.py run -p password.txt apps
.venv/bin/python py4web.py run -p password.txt apps
upgrade-utils:
find apps -name "utils.js" -exec cp apps/_dashboard/static/js/utils.js {} \;
upgrade-vue:
curl -L https://unpkg.com/vue/dist/vue.min.js > apps/_dashboard/static/js/vue.min.js
find apps -name "vue.min.js" -exec cp apps/_dashboard/static/js/vue.min.js {} \;
build: clean assets venv
venv/bin/pip install --upgrade build
venv/bin/pip install --upgrade twine
venv/bin/python -m build
build: clean assets
.venv/bin/pip install --upgrade build
.venv/bin/pip install --upgrade twine
.venv/bin/python -m build
deploy: build
venv/bin/python -m twine upload dist/*
.venv/bin/python -m twine upload dist/*
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Editing a database in the Dashboard
Installation
############

PY4WEB runs fine on Windows, MacOS and Linux. There are many installation procedures (see the official documentation for details) but only two of them are summarized here.
PY4WEB runs fine on Windows, MacOS and Linux. There are many installation procedures `(see the official documentation for details) <https://py4web.com/_documentation/static/en/chapter-03.html>`__ but only two of them are summarized here.

The **simplest way** to install py4web is using binaries, but it's only available for Windows and MacOS. It's meant especially for newbies or students, because it does not require Python pre-installed on your system nor administrative rights. You just need to download the latest Windows or MacOS ZIP file from `this external repository <https://github.com/nicozanf/py4web-pyinstaller>`__. Unzip it on a local folder and open a command line there. Finally run the commands (omit './' if you're using Windows)

Expand Down
129 changes: 76 additions & 53 deletions docs/chapter-03.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Before everything else it is important to understand that unlike other web frame
is not only a python module that can be imported by apps. It is also a program that
is in charge of starting some apps. For this reason you need two things:

- the py4web module (which you download from our web site, from pypi, from github)
- one or more folders containing collections of apps you want to run.
- The py4web module (which you download from our web site, from pypi or from github)
- One or more folders containing collections of apps you want to run.

py4web has command line options to create a folder with some example apps,
to initialize an existing folder, and to add scaffolding apps to that folder.
Expand All @@ -28,41 +28,62 @@ Python 3.7+, which must be installed in advance (except if you use binaries).
Setup procedures
----------------

There are four alternative ways of installing py4web, with different level
of difficulty and flexibility. Let’s look at the pros and cons.
There are four alternative ways of installing py4web, we will guide
you trought each of them and if you get stuck, reach
`out to us. <https://py4web.com/_documentation/static/en/chapter-02.html>`__

Installing from binaries
~~~~~~~~~~~~~~~~~~~~~~~~

This is not a real installation, because you just copy a bunch of files
on your system without modifying it anyhow. Hence this is the simplest
solution, especially for newbies or students, because it does not
require Python pre-installed on your system nor administrative rights.
On the other hand, it’s experimental, it could contain an old py4web
release and it is quite difficult to add other functionalities to it.
Installing from pip, using a virtual environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to use it you just need to download the latest Windows or MacOS
ZIP file from
`this external repository <https://github.com/nicozanf/py4web-pyinstaller>`__.
Unzip it on a local folder and open a command line there. Finally run
A full installation of any complex python application like py4web will
surely modify the python environment of your system. In order to prevent
any unwanted change, it’s a good habit to use a python virtual
environment (also called **virtualenv**, see
`here <https://docs.python.org/3.7/tutorial/venv.html>`__ for an
introduction). This is a standard python feature; if you still don’t
know virtualenv it’s a good time to start its discovery!

::
Here are the instructions for creating the virtual environment, activating it,
and installing py4web in it:

py4web-start set_password
py4web-start run apps
.. tabs::

With this type of installation, remember to always use **py4web-start**
instead of ‘py4web’ or ‘py4web.py’ in the following documentation.
.. group-tab:: Linux and MacOS

Notice the binaries many not correspond to the latest master
or the latest stable branch of py4web although we do our best to
keep them up to date.
::

python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade py4web --no-cache-dir
python py4web setup apps
python py4web set_password
python py4web run apps

Starting py4web is same with or without a virtual environment
python py4web run apps

Installing from pip
.. group-tab:: Windows

::

run cmd.exe
In e.g. folder c:\py4web
python3 -m venv venv
"C:\py4web\venv\Scripts\activate.bat"
python -m pip install --upgrade py4web --no-cache-dir
cd venv\scripts
py4web.exe setup apps
py4web.exe set_password
py4web.exe run apps
You can also find power shell scripts in the same folder. Starting py4web is same with or without a virtual environment
python py4web run apps

Installing from pip, wihtout virtual environment
~~~~~~~~~~~~~~~~~~~

Using *pip* is the standard installation procedure for py4web, since it will
*pip* is the basic installation procedure for py4web, it will
quickly install the latest stable release of py4web.

From the command line
Expand Down Expand Up @@ -96,28 +117,6 @@ be created by *pip* on the system’s path, but not if you type the
python3 py4web.py run apps


Installing using a virtual environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A full installation of any complex python application like py4web will
surely modify the python environment of your system. In order to prevent
any unwanted change, it’s a good habit to use a python virtual
environment (also called **virtualenv**, see
`here <https://docs.python.org/3.7/tutorial/venv.html>`__ for an
introduction). This is a standard python feature; if you still don’t
know virtualenv it’s a good time to start its discovery!

Here are the instructions for creating the virtual environment, activating it,
and installing py4web in it:

::

python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade py4web --no-cache-dir

The instructions for starting and running py4web are the same with or without a virtual environment.


Installing from source (globally)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -135,6 +134,8 @@ folder
make assets
make test
make install
py4web setup apps
py4web set_password
py4web run apps

Also notice that when installing in this way the content of
Expand Down Expand Up @@ -192,7 +193,32 @@ Once installed, you should always start it from there with:
But running .py files directly it’s not usual and you’ll need an explicit
python3/python command.


Installing from binaries
~~~~~~~~~~~~~~~~~~~~~~~~

This is not a real installation, because you just copy a bunch of files
on your system without modifying it anyhow. Hence this is the simplest
solution, especially for beginners or students, because it does not
require Python pre-installed on your system nor administrative rights.
On the other hand, it’s experimental, it could contain an old py4web
release, DAL support is limited and it is quite difficult to add other functionalities to it.

In order to use it you just need to download the latest Windows or MacOS
ZIP file from
`this external repository <https://github.com/nicozanf/py4web-pyinstaller>`__.
Unzip it on a local folder and open a command line there. Finally run

::

py4web-start set_password
py4web-start run apps

With this type of installation, remember to always use **py4web-start**
instead of ‘py4web’ or ‘py4web.py’ in the following documentation.

Notice the binaries many not correspond to the latest master
or the latest stable branch of py4web although we do our best to
keep them up to date.

Upgrading
---------
Expand Down Expand Up @@ -226,10 +252,7 @@ First run

Running py4web using any of the previous procedure should produce an
output like this:

::

py4web run apps


.. image:: images/first_run.png
:class: with-shadow
Expand Down
2 changes: 1 addition & 1 deletion py4web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Massimo Di Pierro <[email protected]>"
__license__ = "BSD-3-Clause"
__version__ = "1.20231114.2"
__version__ = "1.20231115.1"


def _maybe_gevent():
Expand Down
7 changes: 3 additions & 4 deletions py4web/server_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def check_port(host="127.0.0.1", port=8000):

# ---------------------- servers -----------------------------------------------


def gunicorn():
from gevent import local # pip install gevent gunicorn setproctitle
import threading
Expand Down Expand Up @@ -214,7 +213,7 @@ def check_kv(kx, vx):
vx = None
return kx, vx
return None, None

if os.path.isfile(gu_default):
return {"use_python_config": gu_default, "config": gu_default}

Expand Down Expand Up @@ -247,7 +246,7 @@ def check_kv(kx, vx):

except (IOError, OSError) as ex:
sys.exit(f"{ex}\nError: {env_file}")

for k, v in os.environ.items():
if k.startswith(env_key):
k = k.split("_", 1)[1].lower()
Expand Down Expand Up @@ -279,7 +278,7 @@ def load_config(self):
break

def load(self):
return app_handler
return py4web_apps_handler

GunicornApplication().run()

Expand Down
2 changes: 1 addition & 1 deletion py4web/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def request_reset_password(self, email, send=True, next="", route=None):
field = (
db.auth_user.email
if "@" in value or not self.use_username
else self.auth_user.username
else db.auth_user.username
)
user = db(field == value).select().first()
if user and user.action_token != "account-blocked":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "py4web"
version = "1.20231114.2"
version = "1.20231115.1"
authors = [{ name="Massimo Di Pierro", email="[email protected]" },]
description = "A fast, stable, comprehensive web framework"
readme = "README.rst"
Expand Down
56 changes: 56 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let
nixpkgs-src = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/tarball/nixos-22.11";
};

pkgs = import nixpkgs-src {
config = {
allowUnfree = true;
};
};

# This is the Python version that will be used.
myPython = pkgs.python310;

pythonWithPkgs = myPython.withPackages (pythonPkgs: with pythonPkgs; [
pip
setuptools
wheel
]);

lib-path = with pkgs; lib.makeLibraryPath [
libffi
openssl
];

shell = pkgs.mkShell {
buildInputs = [
# my python and packages
pythonWithPkgs
pkgs.memcached

# other packages needed for compiling python libs
pkgs.readline
pkgs.libffi
pkgs.openssl
];

shellHook = ''
# Allow the use of wheels.
SOURCE_DATE_EPOCH=$(date +%s)
# Augment the dynamic linker path
export "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib-path}"
# Setup the virtual environment if it doesn't already exist.
if test ! -d .venv; then
python -m venv .venv
fi
.venv/bin/pip install -U -r requirements.txt
source .venv/bin/activate
export PYTHONPATH=`pwd`.venv/${myPython.sitePackages}/:$PYTHONPATH
'';
};
in

shell

0 comments on commit 002ce4f

Please sign in to comment.