Skip to content

Enable webpy to be used within another package #51

Merged
merged 3 commits into from Mar 25, 2011

3 participants

@serverhorror

Removing the import test from web/__init__.py allows webpy to be placed inside another package.

It's nice to be able to "package" webpy apps for environments where webpy isn't installed in the system and I don't have shell access. This way I can still deploy the applications in a self contained manner. git submodules FTW!

All relevant tests seem OK. (3 failing but those are because I don't have psycopg2 in this environment)

python test/alltests.py
Unable to import psycopg2 (ignoring PostgresTest)
Unable to import pysqlite2.dbapi2 (ignoring SqliteTest_pysqlite2)
No module named MySQLdb (ignoring MySQLTest)
Unable to import psycopg (ignoring PostgresTest_psycopg)
Unable to import pgdb (ignoring PostgresTest_pgdb)
No module named DBUtils(ignoring testPooling)
......................................................................................................................EEE...

Example Before:

mkdir myapp
cd myapp/
mkdir myapp
touch myapp/__init__.py
git clone git://github.com/webpy/webpy.git
Cloning into webpy...
remote: Counting objects: 2620, done.
remote: Compressing objects: 100% (911/911), done.
remote: Total 2620 (delta 1818), reused 2411 (delta 1640)
Receiving objects: 100% (2620/2620), 436.76 KiB | 355 KiB/s, done.
Resolving deltas: 100% (1818/1818), done.
$(cd myapp && ln -s ../webpy/web)
python -c"import myapp; import myapp.web"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "myapp/web/__init__.py", line 29, in <module>
    import test
  File "myapp/web/test.py", line 6, in <module>
    import web
ImportError: No module named web
echo $?
1

Example After:

mkdir myapp
cd myapp/
mkdir myapp
touch myapp/__init__.py
git clone git://github.com/serverhorror/webpy.git
Cloning into webpy...
remote: Counting objects: 2632, done.
remote: Compressing objects: 100% (923/923), done.
remote: Total 2632 (delta 1827), reused 2411 (delta 1640)
Receiving objects: 100% (2632/2632), 437.93 KiB | 328 KiB/s, done.
Resolving deltas: 100% (1827/1827), done.
$(cd webpy/ && git checkout tp-embeddable)
Branch tp-embeddable set up to track remote branch tp-embeddable from origin.
Switched to a new branch 'tp-embeddable'
$(cd myapp && ln -s ../webpy/web)
python -c"import myapp; import myapp.web"
echo $? # see: no error :)
0
serverhorror added some commits Mar 8, 2011
@serverhorror serverhorror create all dirs if root doesn't exist
* Use os.makedirs instead of os.mkdir
* Use os.path.abspath to get rid of eventual '..' elements
87a142d
@serverhorror serverhorror listen on 127.0.0.1 by default instead of 0.0.0.0
There shouldn't be any worries about opening up an
unsecured application just because it is run with
the defaults.
f89041c
@serverhorror serverhorror Make webpy embeddable in another package
Don't `import test` at the package level of `web`.
`test` imports `web` and that isn't available if
webpy is placed within another package
10e01ff
@aaronsw
aaronsw commented Mar 17, 2011

This makes sense to me.

@aaronsw aaronsw merged commit 10e01ff into webpy:master Mar 25, 2011
@aaronsw
aaronsw commented Mar 25, 2011

Seeing no objection, I've merged these.

@anandology

This won't change the default bind address. The app.request method is used for testing stuff, not for starting the dev server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.