Skip to content

Commit

Permalink
Allow py4web to be run using "python -m py4web" (#935)
Browse files Browse the repository at this point in the history
* Allow py4web to be run using python -m py4web

* update debugging docs for __main__.py usage

* update vscode HTTPS launch.json for __main__.py usage

---------

Co-authored-by: Laurin Schmidt <l.schmidt@geosens.de>
  • Loading branch information
laundmo and Laurin Schmidt authored Oct 28, 2024
1 parent 69d932e commit 7ba62d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
24 changes: 9 additions & 15 deletions docs/chapter-02.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,19 @@ to the vscode ``launch.json`` configuration file. Note that if you're using Wind
forward slash only, like
"C:/Users/your_name/py4web/py4web.py".

If you have instead **installed py4web from pip,** you need to:

- open the ``apps`` folder with VScode
- copy the standard `py4web.py launcher <https://github.com/web2py/py4web/blob/master/py4web.py>`__ inside it, but rename it to ``py4web-start.py`` in
order to avoid import errors later:

.. code:: python
#!/usr/bin/env python3
from py4web.core import cli
cli()
- create / change the vscode ``launch.json`` configuration file:
If you have instead **installed py4web from pip,** you need to set the launch.json file to run py4web as a module

::

"args": ["run", "."],
"program": "your_full_path_to_py4web-start.py",
{
"name": "py4web apps",
"type": "debugpy",
"request": "launch",
"module": "py4web",
"args": ["run", "apps", "-D", "--watch", "lazy"]
}

Adjust the `args` to match your apps folder. For example, replace `apps` with `.` if you opened the apps folder itself in VSCode.

.. tip::

Expand Down
7 changes: 4 additions & 3 deletions docs/chapter-03.rst
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,15 @@ To use https with the build-in web server (Rocket3) these are the steps:

If you use VSCode to run py4web you may want to update the py4web launch.json file to contain:

.. code:: json
.. code:: json
"configurations": [
{
"name": "py4web",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/py4web.py",
"module": "py4web",
// or "program": "${workspaceFolder}/py4web.py", if you didn't install py4web as a package
"args": [
"run",
"apps",
Expand Down
5 changes: 5 additions & 0 deletions py4web/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# allow py4web to be run as a module
# this file is called when running "python -m py4web"
from py4web.core import cli

cli()

0 comments on commit 7ba62d7

Please sign in to comment.