Skip to content

Conversation

mart-r
Copy link
Collaborator

@mart-r mart-r commented Oct 10, 2025

This PR adds a PyPI callback to MedCAT.

The idea is that if there's sufficiently many (3) newer minor or patch releases, the user is notified.
And if the users is using a yanked verison, they are notified at a higher log level.

There's a number of environmental variables that govern the above so sys admins can decide whether / what users get notified for:

Variable Default Description
MEDCAT_DISABLE_VERSION_CHECK (unset) When set to true, yes or disable, disables the version update check entirely. Useful for CI environments, offline setups, or deployments where external network access is restricted.
MEDCAT_PYPI_URL https://pypi.org/pypi Base URL used to query package metadata. Can be changed to a PyPI mirror or internal repository that exposes the /pypi/{pkg}/json API.
MEDCAT_MINOR_UPDATE_THRESHOLD 3 Number of newer minor versions (e.g. 1.4.x, 1.5.x) that must exist before MedCAT emits a “newer version available” log message.
MEDCAT_PATCH_UPDATE_THRESHOLD 3 Number of newer patch versions (e.g. 1.3.1, 1.3.2, 1.3.3) on the same minor line required before emitting an informational update message.
MEDCAT_VERSION_UPDATE_LOG_LEVEL INFO Logging level used when reporting available newer versions (minor/patch thresholds). Accepts any valid logging level string (DEBUG, INFO, WARNING, ERROR, CRITICAL).
MEDCAT_VERSION_UPDATE_YANKED_LOG_LEVEL WARNING Logging level used when reporting that the current version has been yanked on PyPI. Accepts the same values as above.

A few additional Notes

  • The update check is performed at most once per week and cached in ~/.cache/medcat_version.json.
  • Yanked versions are detected via the PyPI JSON API ("yanked": true flag).
  • The check runs silently if the network request fails, or if the cache indicates a recent check.
  • Log messages are emitted via the standard logging framework — users can silence or redirect them as desired.

@tomolopolis
Copy link
Member

DEFAULT_VERSION_INFO_LEVEL, DEFAULT_VERSION_INFO_YANKED_LEVEL)


DEFAULT_CACHE_PATH = Path.home() / ".cache" / "medcat_version.json"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally - I'd rather make a medcat (cogstack?) folder in .cache, just the folder has so much use

AVOID_LEGACY_CONVERSION_ENVIRON = "MEDCAT_AVOID_LECACY_CONVERSION"

# version check
MEDCAT_DISABLE_VERSION_CHECK_ENVIRON = "MEDCAT_DISABLE_VERSION_CHECK"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to the docs as well?

The whole .md table in this PR would be great to add there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it to the README.

However, there's a separate docs/main.md that seems to be (again) limping behind the README, but (mostly) mirrors it.
I think we should find a way to have it just automatically mirror the README.

AVOID_LEGACY_CONVERSION_ENVIRON = "MEDCAT_AVOID_LECACY_CONVERSION"

# version check
MEDCAT_DISABLE_VERSION_CHECK_ENVIRON = "MEDCAT_DISABLE_VERSION_CHECK"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty pedantic - but can you enforce true/false here instead? Just feels like it will save the question "I set it to False but it is somehow disabled"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd make it the same as AVOID_LEGACY_CONVERSION_ENVIRON just above

Copy link
Collaborator

@alhendrickson alhendrickson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@mart-r mart-r merged commit f4a4be3 into main Oct 14, 2025
20 checks passed
@mart-r mart-r deleted the feat/medcat/CU-869ary4dq-add-pypi-callback branch October 14, 2025 12:53
tomolopolis pushed a commit that referenced this pull request Oct 15, 2025
* CU-869ary4dq: Add code to check for updates

* CU-869ary4dq: Add option to change log level with environmental variables

* CU-869ary4dq: Use option to change log level with environmental variables

* CU-869ary4dq: Remove debug print output

* CU-869ary4dq: Add separate log level for YANKED releases

* CU-869ary4dq: Add tests for update checker

* CU-869ary4dq: Move cache to subfolder

* CU-869ary4dq: Check the value of version check enabling environmental value

* CU-869ary4dq: Unify environmental value getting

* CU-869ary4dq: Add section regarding version and update checks to README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants