Sometimes we mgiht want to make our package update to latest version, let me show you how do I accomplish this.
We have to determine current installed package version.
Then detemine latest published version, if this is an internal package, you have to implement a custom method like bellow.
def get_latest_version(name, server='https://pypi.org'):
We will use pip to update the package, here is the implementation.
The update method leaves
*args is for internal package, you might want to parse in
Finally, we implement the auto update method.
Then, we place it in
__init__.py in root of package, every time the package be imported, it will run the auto checker.
OK, we have done the auto update.
In above example, we did not reload the module if there is an update, that depends on you.
Another thing can be improved is, we might not want to update the pacakge when there is an update, we just want to update it if there is a major / breaking update, the updator should be smarter.