Skip to content

Commit 17f9a91

Browse files
committed
Allow adding the work dir to the search path
Also add some clarifying documentation.
1 parent 2e12e25 commit 17f9a91

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

docs/appdev.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ This will create a directory ``WorkDir`` that will contain a directory structure
6262
``-c Context``:
6363
Use ``Context`` as the name for the application default context. A subdirectory with the same name will be created in the work dir (you can change that with the ``-d`` option). If you do not use the ``-c`` option, the context name will be ``MyContext``. You may simply want to call it ``App`` or ``Context``, particularly if you are using only one context. If you want to add more than one context, you need to create a subdirectory and a corresponding ``Contexts`` dictionary entry in the ``Application.config`` file manually.
6464
``-l Lib``:
65-
Create a ``Lib`` directory in the work dir which will be added to the Python path. You can use the ``-l`` option multiple times; and you can also add already existent library directories outside of the work dir.
65+
Create a ``Lib`` directory in the work dir which will be added to the Python module search path. You can use the ``-l`` option multiple times; and you can also add already existent library directories outside of the work dir. If you want to add the work dir itself to the Python path, pass ``-l .``. In that case, you can import from any Python package placed directly in the working, including the Webware contexts. Note that the webware package will always be added to the Python module search path, so that you can and should import any Webware modules and sub packages directly from the top level.
6666
``WorkDir``:
67-
The files will be put here. Name if after your application, place it where it is convenient for you. It makes sense to put the working directory together with the virtual environment where you installed Webware for Python inside the same distinct base directory. Install any other requirements either into the virtual environment or provide them in the ``Lib`` directory.
67+
The files will be put here. Name if after your application, place it where it is convenient for you. It makes sense to put the working directory together with the virtual environment where you installed Webware for Python inside the same distinct base directory. Install any other requirements either into the virtual environment or provide them in one of the directories specified with the ``-l`` option.
6868

6969
You can see all available options if you run ``webware make --help``.
7070

webware/Scripts/WSGIScript.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@
55
import os
66
import sys
77

8+
import webware
9+
810
libDirs = []
911
workDir = None
1012
development = None
1113
settings = {}
1214

13-
for libDir in libDirs:
14-
if libDir not in sys.path:
15-
sys.path.append(libDir)
15+
webware.addToSearchPath()
16+
17+
for libDir in reversed(libDirs):
18+
if libDir != '.' and libDir not in sys.path:
19+
sys.path.insert(0, libDir)
1620

1721
if workDir is None:
1822
workDir = os.path.dirname(os.path.dirname(__file__))
1923

2024
if workDir:
2125
os.chdir(workDir)
2226

23-
import webware
24-
webware.addToSearchPath()
27+
if '.' in libDirs:
28+
sys.path.insert(0, workDir)
2529

2630
from Application import Application
2731

0 commit comments

Comments
 (0)