Skip to content

Commit

Permalink
check for updates (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarlevin authored Nov 7, 2024
1 parent f02c37f commit 43352e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Instructions: Add a subsection under `[UNRELEASED]` for additions, fixes, change
### Added

- Support for generating prefigure graphics.
- Always checks whether there is a new version of the CLI available.

## [2.8.2] - 2024-11-05

Expand Down
10 changes: 9 additions & 1 deletion pretext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ def main(ctx: click.Context, targets: bool) -> None:
fh.setFormatter(file_log_format)
log.addHandler(fh)
# output info
log.info(f"PreTeXt-CLI version: {VERSION}\n")
latest_version = utils.latest_version()
if latest_version and latest_version != VERSION:
log.info(
f"Using PreTeXt-CLI version {VERSION}. The latest stable version available is {latest_version}. Run `pip install pretext --upgrade` to update.\n"
)
else:
log.info(
f"Using PreTeXt-CLI version: {VERSION}. This is the latest available version.\n"
)
log.info(f"PreTeXt project found in `{utils.project_path()}`.")
# permanently change working directory for rest of process
os.chdir(pp)
Expand Down
16 changes: 16 additions & 0 deletions pretext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,19 @@ def pelican_default_settings() -> t.Dict[str, t.Any]:
# for now, all PTX_ custom settings are strings (due to use of XML)
config["PTX_SHOW_TARGETS"] = "yes"
return config


def latest_version() -> t.Optional[str]:
"""
Get the latest version of the pretext package from PyPI.
"""
import requests

url = "https://pypi.org/pypi/pretext/json"
try:
response = requests.get(url)
return response.json()["info"]["version"]
except Exception as e:
log.debug("Could not determine latest version of pretext.")
log.debug(e, exc_info=True)
return None

0 comments on commit 43352e0

Please sign in to comment.