You cannot run a python module directly as a script (I don't really know the reason why).
EDIT : The reason is explained in the PEP338 which is the spec for the "-m"
option.
The release of 2.5b1 showed a surprising (although obvious in retrospect) interaction between this PEP and PEP 328 - explicit relative imports don't work from a main module. This is due to the fact that relative imports rely on
__name__
to determine the current module's position in the package hierarchy. In a main module, the value of__name__
is always__main__
, so explicit relative imports will always fail (as they only work for a module inside a package).For the 2.5 release, the recommendation is to always use absolute imports in any module that is intended to be used as a main module
To test your application, encapsulate api_main in a function and create a top-level main.py file which will run the main loop :
cclogger/api_main.py :
import re
import os
from .bottle import run, default_app, debug, get
from .common_util import date_str_to_datetime, UTCOffset, date_filter
#app = Bottle()
def main():
default_app().router.add_filter('date', date_filter)
from . import api, dev
@get('/index')
def index():
return "CCLogger API main live and kicking."
if dev:
debug(True)
run(reloader=True, port=9000)
else:
os.chdir(os.path.dirname(__file__))
application = default_app()
And /main.py :
from cclogger import api_main
if __name__ == '__main__':
api_main.main()
You can run your application by typing python main.py
, python -m main
or python -c "import cclogger.api_main; api_main.main()"
.
PS : thanks for linking the complete source, it's always much more helpful than the stubs provided with the question.