diff --git a/circup/__init__.py b/circup/__init__.py index 355330a..7b2f6e8 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -23,6 +23,7 @@ import findimports import pkg_resources import requests from semver import VersionInfo +import update_checker # Useful constants. @@ -811,6 +812,24 @@ def get_circuitpython_version(device_path): return (circuit_python, board_id) +def get_circup_version(): + """Return the version of circup that is running. If not available, return None. + + :return: Current version of circup, or None. + """ + try: + from importlib import metadata # pylint: disable=import-outside-toplevel + except ImportError: + try: + import importlib_metadata as metadata # pylint: disable=import-outside-toplevel + except ImportError: + return None + try: + return metadata.version("circup") + except metadata.PackageNotFoundError: + return None + + def get_dependencies(*requested_libraries, mod_names, to_install=()): """ Return a list of other CircuitPython libraries @@ -1128,6 +1147,13 @@ def main(ctx, verbose, path): # pragma: no cover logger.addHandler(verbose_handler) click.echo("Logging to {}\n".format(LOGFILE)) logger.info("### Started Circup ###") + + # If a newer version of circup is available, print a message. + logger.info("Checking for a newer version of circup") + version = get_circup_version() + if version: + update_checker.update_check("circup", version) + # stop early if the command is boardless if ctx.invoked_subcommand in BOARDLESS_COMMANDS: return diff --git a/requirements.txt b/requirements.txt index f1f060a..8fef472 100644 --- a/requirements.txt +++ b/requirements.txt @@ -50,6 +50,7 @@ sphinxcontrib-serializinghtml==1.1.3 toml==0.10.0 tqdm==4.35.0 twine==1.13.0 +update-checker==0.18.0 urllib3==1.26.5 wcwidth==0.1.7 webencodings==0.5.1 diff --git a/setup.py b/setup.py index 2e84e89..f002651 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,8 @@ install_requires = [ "appdirs>=1.4.3", "requests>=2.22.0", "findimports>=2.1.0", + # importlib_metadata is only available for 3.7, and is not needed for 3.8 and up. + "importlib_metadata; python_version == '3.7'", ] extras_require = {