Skip to content

Fix #70: stop calling logging.basicConfig() at import time#71

Merged
iskandr merged 3 commits into
masterfrom
fix/70-remove-basicconfig-at-import
Jul 8, 2026
Merged

Fix #70: stop calling logging.basicConfig() at import time#71
iskandr merged 3 commits into
masterfrom
fix/70-remove-basicconfig-at-import

Conversation

@iskandr

@iskandr iskandr commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #70. gtfparse called logging.basicConfig(level=logging.INFO) at module import time in three modules:

  • gtfparse/read_gtf.py
  • gtfparse/attribute_parsing.py
  • gtfparse/create_missing_features.py

For a library this is a well-known anti-pattern. basicConfig() configures the root logger on behalf of whatever application imports us — it attaches a StreamHandler and forces the level to INFO. Simply import gtfparse therefore hijacks the host application's logging setup (its handlers/level get overridden by whichever module happens to import first).

Fix

  • Remove all three logging.basicConfig(level=logging.INFO) calls.
  • Route the remaining log statements through the module-level logger (logging.getLogger(__name__)) instead of the root-logger convenience functions (logging.info(...)), which would otherwise implicitly re-trigger basicConfig() on first use.

Configuring handlers and levels is now left entirely to the application, per the stdlib logging guidance for libraries. The library only emits records through its named loggers.

Verification

  • New behavior check: import gtfparse no longer adds handlers to or changes the level of the root logger, and the package's named loggers stay at NOTSET.
  • Full test suite passes (59 passed), including the caplog-based log-capture tests in tests/test_gencode_gtf.py.
  • ruff check and ruff format --check clean.

https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS

gtfparse called logging.basicConfig(level=logging.INFO) at module import
in three modules (read_gtf, attribute_parsing, create_missing_features).
As a library this is an anti-pattern: it configures the root logger on
behalf of the importing application, adding a handler and forcing the
INFO level onto everyone's root logger — hijacking the host app's logging.

Remove the basicConfig() calls and route the remaining log statements
through the module-level `logger` (logging.getLogger(__name__)) instead
of the root-logger convenience functions logging.info(...), which would
otherwise implicitly re-trigger basicConfig().

Configuring handlers/levels is now left entirely to the application, per
the standard library logging guidance for libraries.

Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
@coveralls

coveralls commented Jul 8, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28968279719

Coverage decreased (-0.07%) to 95.146%

Details

  • Coverage decreased (-0.07%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 8 coverage regressions across 3 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

8 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
read_gtf.py 4 95.93%
create_missing_features.py 3 88.89%
attribute_parsing.py 1 97.44%

Coverage Stats

Coverage Status
Relevant Lines: 206
Covered Lines: 196
Line Coverage: 95.15%
Coverage Strength: 0.95 hits per line

💛 - Coveralls

@iskandr iskandr mentioned this pull request Jul 8, 2026
iskandr added 2 commits July 8, 2026 14:49
Pass log message arguments to logger.info(...) rather than pre-formatting
with the % operator, so the interpolation is skipped entirely when the
log level is disabled (the standard logging idiom, per pylint's
logging-not-lazy guidance).

Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
Patch release: gtfparse no longer calls logging.basicConfig() at import
time, so importing the library no longer reconfigures the host
application's root logger (#70).

Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
@iskandr iskandr merged commit 6b2e0c7 into master Jul 8, 2026
6 checks passed
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.

gtfparse calls logging.basicConfig() at import — hijacks root logging in downstream apps

2 participants