Skip to content

remove unreachable pkg_resources fallback from example tests - #153

Merged
mpounsett merged 2 commits into
mainfrom
t3/remove-pkg-resources-fallback
Nov 24, 2026
Merged

mpounsett merged 2 commits into
mainfrom
t3/remove-pkg-resources-fallback

Conversation

@mpounsett

Copy link
Copy Markdown
Owner

What

tests/test_examples.py imported importlib.resources.files inside a try/except ImportError that fell back to pkg_resources.resource_filename, and _run_example branched on a USING_IMPORTLIB flag. This removes the fallback and the flag, leaving a plain from importlib.resources import files and the single files('nagiosplugin.examples') / program form.

Why

  • The project requires Python >= 3.11 and importlib.resources.files has been in the standard library since 3.9, so the except ImportError branch cannot be reached on any supported interpreter.
  • pkg_resources was removed from setuptools in 82.0.0, so the fallback would not import on a current setuptools anyway.

This was the only use of pkg_resources in the repository; the only remaining mention is the historical 1.4.0 changelog entry (#50).

Verified locally (macOS)

  • uv run tox -e py311,py312,py313,py314,py315: all pass (140 passed, 1 skipped per environment).
  • uv run tox -e ruff: exits non-zero on the same 137 findings that main already has; this change adds none.
  • In the py311 and py315 tox environments, files('nagiosplugin.examples') / 'check_load.py' resolves to an existing file.
  • CodeRabbit CLI review of the diff: no findings.

Left to CI

test_check_load skips on non-Linux platforms, so the local runs did not execute check_load.py through _run_example. The Linux CI matrix on this PR is the real check for that test.

Not included

The same file has a second fallback, try: import unittest2 as unittest / except ImportError: import unittest. It is left untouched here and is a candidate for a separate cleanup.

@mpounsett
mpounsett merged commit bdf8217 into main Nov 24, 2026
12 checks passed
@mpounsett
mpounsett deleted the t3/remove-pkg-resources-fallback branch November 24, 2026 23:26
@mpounsett mpounsett added this to the 1.5.0 milestone Nov 24, 2026
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.

1 participant