Skip to content

Fix three statements that could cause problems on Windows#525

Merged
martinholmer merged 2 commits into
masterfrom
fix-windows-bugs
Jun 10, 2026
Merged

Fix three statements that could cause problems on Windows#525
martinholmer merged 2 commits into
masterfrom
fix-windows-bugs

Conversation

@martinholmer

@martinholmer martinholmer commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

These changes have no effect on non-Windows platforms: all the tests pass and the three generated national TMD data files are the same as before these changes.

Commit f20d1f1 fixes this issue:

  A temp-file reopened while open (fails on Windows)

  tests/test_solve_weights.py:172-177
  with tempfile.NamedTemporaryFile(mode="w", suffix=".log", delete=False) as f:
      f.write(log_content)
      f.flush()
      result = parse_log(Path(f.name))   # reopens f.name while f is still open

  On Linux/macOS a file can be opened by a second handle while the first is
  open. On Windows the file is locked, so parse_log()'s open() raises
  PermissionError. The fix is to close the temp file before reopening — move the
  parse_log call outside the with block.

Commit 0ec32bc fixes this issue:

  Console-encoding crash on Windows — non-ASCII in print()

  tmd/national_targets/extract_irs_to_csv.py:230 and
  tmd/national_targets/potential_targets_to_soi.py:436 both print() a →
  (U+2192).

  On Windows, when stdout is redirected to a file or pipe, Python encodes using
  the locale code page (cp1252), which has no → → UnicodeEncodeError. (Other
  non-ASCII output like —, ±, × is in cp1252, so those are safe; →, ←, Σ, ✓ are
  not.) Note the log files written with explicit encoding="utf-8" and the
  io.StringIO capture in batch_weights.py are all safe — only direct console
  prints are at risk.

@martinholmer martinholmer requested a review from donboyd5 June 9, 2026 19:36
@martinholmer martinholmer marked this pull request as draft June 9, 2026 19:37
@martinholmer martinholmer marked this pull request as ready for review June 9, 2026 19:43
@martinholmer martinholmer changed the title Fix three bugs that would cause problems on Windows Fix three statements that could cause problems on Windows Jun 10, 2026
@martinholmer

Copy link
Copy Markdown
Collaborator Author

@donboyd5 approved this PR in a private email.

@martinholmer martinholmer merged commit 2fae90c into master Jun 10, 2026
1 check passed
@martinholmer martinholmer deleted the fix-windows-bugs branch June 10, 2026 18:07
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