Changeset 266:90591f3fc308
- Timestamp:
- 2007-08-25 13:28:05
(1 year ago)
- Author:
- Stefan Schwarzer <sschwarzer@sschwarzer.net>
- branch:
- default
- Message:
Don't consider the environment variable `WSB_DEVEL`. Instead use the
`PYTHONPATH` variable to control which modules are loaded.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r259 |
r266 |
|
| 23 | 23 | # SOFTWARE. |
|---|
| 24 | 24 | |
|---|
| 25 | | import os |
|---|
| 26 | | import sys |
|---|
| 27 | | |
|---|
| 28 | | |
|---|
| 29 | | # call this function before the first import specific to Websourcebrowser |
|---|
| 30 | | def maybe_use_devel_directory(): |
|---|
| 31 | | """ |
|---|
| 32 | | This function implements a trick for development of |
|---|
| 33 | | Websourcebrowser. Normally, |
|---|
| 34 | | |
|---|
| 35 | | from websourcebrowser import module |
|---|
| 36 | | |
|---|
| 37 | | will pick up `module` from the `site-packages` directory. |
|---|
| 38 | | |
|---|
| 39 | | However, by the trick, the import statement will use the module |
|---|
| 40 | | from the current directory (if it's named `websourcebrowser`!) if |
|---|
| 41 | | the environment variable `WSB_DEVEL` is set to "1" (without the |
|---|
| 42 | | quotes). |
|---|
| 43 | | """ |
|---|
| 44 | | in_development = os.environ.get("WSB_DEVEL", "0") |
|---|
| 45 | | if in_development == "1": |
|---|
| 46 | | # check the name of the current directory |
|---|
| 47 | | if os.path.basename(os.getcwd()) != "websourcebrowser": |
|---|
| 48 | | print "The current directory isn't the package directory - aborting" |
|---|
| 49 | | sys.exit() |
|---|
| 50 | | # assume the current directory contains the package's files |
|---|
| 51 | | development_dir = os.path.abspath(os.pardir) |
|---|
| 52 | | # modify $PYTHONPATH to find the development files before |
|---|
| 53 | | # those installed in the `site-packages` directory |
|---|
| 54 | | sys.path.insert(0, development_dir) |
|---|
| 55 | | print "Using the current directory as websourcebrowser package." |
|---|
| 56 | | print |
|---|
| 57 | | |
|---|
| 58 | | maybe_use_devel_directory() |
|---|
| 59 | | |
|---|
| 60 | | |
|---|
| 61 | 25 | from websourcebrowser import browser |
|---|
| 62 | 26 | |
|---|