-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Automatic release update warnings. #1336
Conversation
d37eafd
to
f533b4c
Compare
6bbe4bf
to
fd66070
Compare
This is blocked by #1330 |
f44b62d
to
be59d98
Compare
Codecov Report
@@ Coverage Diff @@
## master #1336 +/- ##
==========================================
- Coverage 97.28% 95.17% -2.11%
==========================================
Files 67 109 +42
Lines 4235 7633 +3398
==========================================
+ Hits 4120 7265 +3145
- Misses 115 368 +253
Continue to review full report at Codecov.
|
61df919
to
6476ed9
Compare
6476ed9
to
210a9df
Compare
f698663
to
34175e2
Compare
httpie/internal/_build_channel.py
Outdated
# Represents the packaging method. This file should | ||
# be overridden by every build system we support on | ||
# the packaging step. | ||
|
||
BUILD_CHANNEL = 'unknown' |
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.
Why is the package called internal
?
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.
What do you think about calling this module __build_channel__.py
to indicate it’s very special?
httpie/internal/daemons.py
Outdated
# This module provides an interface to spawn a detached task to be | ||
# runned with httpie.internal.daemon_runner on a separate process. It is | ||
# based on DVC's daemon system. | ||
# https://github.com/iterative/dvc/blob/main/dvc/daemon.py |
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.
"""Looks like a good docstring candidate"""
There’re a few other comment-to-docstring opportunities in this PR.
@@ -149,6 +149,24 @@ def __init__(self, directory: Union[str, Path] = DEFAULT_CONFIG_DIR): | |||
def default_options(self) -> list: | |||
return self['default_options'] | |||
|
|||
def _configured_path(self, config_option: str, default: str) -> None: |
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.
It’d prefix the name with get_
httpie/internal/daemons.py
Outdated
os.path.dirname(os.path.dirname(file_path)) | ||
) | ||
|
||
if os.name == 'nt': |
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.
Could we use httpie.compat.is_windows
here?
httpie/internal/daemons.py
Outdated
if os.name == 'nt': | ||
# Windows lacks os.fork(), so we need to | ||
# handle it separately. | ||
_spawn_windows(args, process_context) | ||
else: | ||
_spawn_posix(args, process_context) |
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.
This might be asking for a new _spawn(args, process_context)
that would encapsulate the OS check.
* Hide pretty help * Automatic release update warnings. * `httpie cli check-updates` * adapt to the new loglevel construct * Don't make the pie-colors the bold * Apply review feedback. Co-authored-by: Jakub Roztocil <[email protected]>
This PR embeds an automatic update warning system into the HTTPie. What this means is that, on some configurable thresholds (once a week) HTTPie will check whether a new release is available and if it there is it will give user a warning.
Here is an example:
This problem consists of two dimensions, which each need to be handled separately:
Update detection
Since HTTPie is distributed on many different channels (from Homebrew to Snap, PyPI to Chocolatey) we need to be careful to show these warnings to only users whom can upgrade at that moment. So for that, we have a new file called
httpie/internal/_build_channel.py
. This file has no runtime purpose, other than contain theBUILD_CHANNEL
constant.The default for that constant is
unknown
, and each build system will overwrite it with the value pointing to their name. E.g on Homebrew, during the build process, we'll writeBUILD_CHANNEL = 'brew'
into that file. This way, we can detect whether the build is from Homebrew or not.Once we know what build channel the user is using, we need to determine whether we have a new release for that channel. That is where
packages.httpie.io/latest.json
comes into place. It is an automatically updated (in a daily basis) registry of build channels and the HTTPie versions in them.We compare the current version of HTTPie with the latest version for the build channel by looking to the
latest.json
. If there is a new release, we show the warning.Startup penalty
For reducing the overhead of this process as much as we can, we do it in two steps.
latest.json
into a local file (~/.config/httpie/version_info.json
) (done in a separate process, takes a long time)For the first task, this PR introduces a daemon system where we can start tasks in the background and detach them from the main process. So even if you run a short HTTPie command (e.g
http --version
), you exit immediately and the actual task still works to finish up its objective without blocking you.This part is implemented by using double-forking on POSIX, and creating a subprocess on Windows.
Baseline
Master:
This branch:
It seems like once the
version_info
file is created, there is no penalty. When the file does not exist, there is a very small cost of forking the process which is ~15 ms (you will pay this cost twice a month, so if you ran HTTPie 1000 times that month this will cost ~30 ms in overall overhead).