-
Notifications
You must be signed in to change notification settings - Fork 28
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
server: get default port optionally form environment var #464
Conversation
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.
Really nice! Thanks for this feature. Only a very small change is required to merge it.
Could you add the prefix "server: " to the commit message as well?
lona/app.py
Outdated
host='localhost', | ||
port=8080, | ||
host=os.environ.get('LONA_DEFAULT_HOST', 'localhost'), | ||
port=int(os.environ.get('LONA_DEFAULT_PORT', 8080)), |
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.
We will need a check here if the value of LONA_DEFAULT_PORT
can be type casted to an int. This will crash into a cryptic traceback if not
f68bb6f
to
14c8565
Compare
had not realised that if you amend the title of the commit, that doesn't percolate through into the PR.
you'll get a message:
after which the system sys.exits with value 2 (same value as when using But if you have an incorrect LONA_DEFAULT_PORT setting, IMO that should be fixed, not suppressed by doing --port. |
I did some testing and found out the check is just not necessary (sorry). Argparse does exactly what you would expect and will handle Line 432 in 7f8ba4c
lona/lona/command_line/handle_command_line.py Line 119 in 7f8ba4c
|
I did this but cannot re-apply for a review, probably because there is already a review request pending. |
@AvdN: Yeah no worries, that's on me. |
If the default port 8080 is taken, you have to either change the app.run() or use --port <PORTNUM> on every invocation of the program. When trying out examples I don't want to do the first and forget the second. This patch allows you set the environment variables LONA_DEFAULT_HOST and LONA_DEFAULT_PORT in your shell. These override the built-in defaults ('localhost' resp. 8080), and are in turn overridden by arguments to ``app.run()`` and startup commandline parameters. Signed-off-by: Florian Scherf <mail@florianscherf.de>
Codecov ReportPatch coverage has no change and project coverage change:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## master #464 +/- ##
==========================================
- Coverage 71.81% 71.80% -0.02%
==========================================
Files 84 84
Lines 5745 5746 +1
Branches 1235 1235
==========================================
Hits 4126 4126
- Misses 1339 1340 +1
Partials 280 280
☔ View full report in Codecov by Sentry. |
@AvdN: Works like a charm! I added a small fix to your patch because |
I am not sure if I am supposed to be able to see the changes on github, at least I cannot find them. But go ahead, I'll see them at the latest when they are merged. |
@AvdN: Thanks for contributing! :) |
If the default port 8080 is taken, you have to either change the app.run() or use --port on every invocation of the program. When trying out examples I don't want to do the first and forget the second.
This patch allows you set the environment variables LONA_DEFAULT_HOST and LONA_DEFAULT_PORT in your shell. These override the built-in defaults ('localhost' resp. 8080), and are in turn overridden by arguments to
app.run()
and startup commandline parameters.