-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simpl server #82
simpl server #82
Conversation
966f732
to
e773f61
Compare
a0e31e3
to
c4c48b9
Compare
26d8158
to
dbb4931
Compare
+1 from me! |
Nice! A couple of notes:
"""Project Awesome."""
from simpl import config
from simpl import log
from simpl import server
SIMPL_OPTIONS = log.OPTIONS + server.OPTIONS
OPTIONS = MY_OPTIONS + SIMPL_OPTIONS
if __name__ == "__main__":
conf = config.init(options=OPTIONS)
log.configure(conf)
conf.parse()
if conf.command == "server":
server.run(name="awesome", conf)
else:
do_something_else() So the command would be similar to what you have in the PR description, but would be the project entry point, no simpl's:
If that is possible, could you show an example of you recommend it be done? If not, can we explore making that possible? |
@ziadsawalha Thanks for the comments. Thinking/coding out loud... """Project Awesome."""
from simpl import config
from simpl import log
from simpl import server
from simpl.utils import cli as cli_utils
SIMPL_OPTIONS = log.OPTIONS + server.OPTIONS
OPTIONS = MY_OPTIONS + SIMPL_OPTIONS
# Where MY_OPTIONS have some server options
# with group='Server Options'
# Also, project awesome defines the `awesome`
# console_scripts entry_point which points to
# this file's main()
def main():
awesome_parser = cli_utils.HelpfulParser(prog='awesome')
server_parser = server.attach_parser(awesome_parser.add_subparsers())
server_parser.set_defaults(_func=server.run)
args = awesome_parser.parse_args()
conf = config.init(options=OPTIONS)
conf.parse()
args._func(conf)
if __name__ == "__main__":
main() Maybe we could improve on this? |
Is that needed if we provide |
@ziadsawalha it's not needed, but it would allow your app's options to be grouped with the server options provided by simpl in the help/usage output. |
0a46beb
to
4333d7f
Compare
group='Server Options', | ||
), | ||
config.Option( | ||
'--debug-server', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that you changed this from --debug\-d
to --debug-server
. Why not just have it enabled when --debug\-d
is supplied? I'm not sure I see the need/benefit for --debug\-d
and --debug-server
being separate.
--debug\-d
already generates gobs of data (as might be expected from a debug mode), so having it output traces in bottle also seems acceptable. Note: for the record, --verbose is how to log heavily but not dump gobs of data out.
I do recognize the challenge of addressing the duplicate --debug\-d
option in server.OPTIONS and log.OPTIONS if we did that. IMO, we should try to solve that and keep only one -d
flag.
b7240b8
to
26fa289
Compare
@ziadsawalha I am not sure how to handle the conflicting options. I believe I think |
To resolve the conflict,
So would we have |
Thanks for documenting "Attach simpl's server subcommand to your parser". Could you add that markdown to the code in the PR as well? Either in the server module docstrings or a readme? It should end up being the canonical "how to use this" text. |
def test_simpl_server(self): | ||
argv = ['server', '--quiet-server', '--port', str(get_free_port())] | ||
proc = multiprocessing.Process( | ||
target=simpl_cli.main, kwargs={'argv': argv}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggled with this in https://github.com/checkmate/simpl/blob/master/tests/test_server.py#L109. I think this might not get correctly reflected in in test coverage.
This allows simpl.config user to override the use of the default argparse.ArgumentParser
If options is not explicitly supplied to build_parser(), use self._options and some additional logic for suppressing defaults with a value of None.
--debug was an existing option in log.OPTIONS, so the debug flag for the server was changed to --debug-server. --quiet was an existing option in log.OPTIONS, so the quiet flag for the server was changed to --quiet-server
Using the utils.cli.kwargs argument type, you can pass a string like "hello=world new=toys for=sure"
Example: simpl server -s xeventlet -o keyfile=~/mykey ciphers=GOST94
In addition to configuring log format and log level, the use of --debug will also set the bottle server to debug mode, which will return tracebacks in the response body if an unexpected error occurs. If --quiet is used, in addition to configuring a minimal log format and WARNING log level, the routes and other startup text is not printed to stdout.
...unless quiet mode is on. This also changes the startup process to convert a string (e.g. mypackage.mywsgiapp) into a wsgi app identical to the method used by bottle.
Refactors server.py to add the build_app() function which can be used to get a wsgi-compliant app to be ran by something other than simpl or bottle.
In order for the pipes not to block, this needs to be run with eventlet or gevent monkey patching.
6cb58e4
to
245521a
Compare
This change installs a
simpl
command into your environment during package installation using theconsole_scripts
entry point. The first available subcommand isserver
. You can now usesimpl server
to quickly run your app.The interface is similar to that of bottle's "command line interface".
The simpl/server boilerplate and interface can be used a few different ways:
1. Point
simpl server
to your routesExample:
Run the command
test it...
Of course, this might not be how you choose to continue as your app matures
2. Attach simpl's
server
subcommand to your parserAdmittedly, this technique is a little strange, and the code must be in the exact order as written below. But it works.
3. Just use the server.OPTIONS, and run bottle however you want.
--help