Conversation
Fixes: - Fix ResourceWarning from unclosed subprocess (fixes #84): Use Popen as context manager via new _run_process() and _run_process_output() helpers. All 17 bare Popen calls now properly use 'with' statements. - Extract common Popen kwargs into _popen_kwargs() to eliminate duplicated Windows startupinfo logic across every method. Python modernization: - Remove 'from __future__ import print_function' (Python 2 compat, unnecessary) - Replace 'class WhiteboxTools(object)' with 'class WhiteboxTools' (new-style) - Convert .format() to f-strings in core methods - Replace '== True' comparisons with idiomatic boolean checks - Fix mutable default argument: list_tools(keywords=[]) -> keywords=None - Fix incorrect docstring on set_max_procs (was copy of set_compress_rasters) README fixes: - Replace 5 broken gishub.org short links (all returning 404) with direct URLs - Update pepy.tech badge to current format setup.py: - Update Python version classifiers from 3.4-3.6 to 3.9-3.13 - Update development status from Pre-Alpha to Beta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses issue #84 (subprocess ResourceWarning) and includes several code quality improvements.
🐛 Bug Fix — Subprocess ResourceWarning (Fixes #84)
All
subprocess.Popencalls now use context managers (withstatements), which ensures proper cleanup and eliminatesResourceWarning: subprocess N is still runningwhen running withpytest -Werror.Before: 17 bare
Popen()calls acrossset_verbose_mode,set_compress_rasters,set_max_procs,run_tool,help,license,version,tool_help,tool_parameters,toolbox,view_code, andlist_tools.After: Two reusable helper methods handle all subprocess execution:
_run_process(args, callback)— streams output line-by-line with cancel support (used byrun_tool,set_verbose_mode, etc.)_run_process_output(args)— captures and returns full output as a string (used byhelp,version,license, etc.)_popen_kwargs()— consolidates common Popen arguments and Windowsstartupinfologic (was duplicated 8+ times)🔧 Python Modernization
from __future__ import print_function(Python 2 compatibility, unnecessary since Python 3 is required)class WhiteboxTools(object)→class WhiteboxTools(new-style class syntax).format()string formatting to f-strings in core methods== Truecomparisons with idiomatic boolean checks (if self.start_minimized)list_tools(keywords=[])→keywords=Noneset_max_procs(was a copy ofset_compress_rasters)📝 README Fixes
gishub.orgshort links (all returning HTTP 404) with direct URLs to mybinder.org and GitHub/badge/→/pepy/dt/)📦 setup.py Updates
Net Impact
240 lines of duplicated subprocess boilerplate removed.