Skip to content

Revert fdopen mode from 'a' to 'w'#3640

Merged
mrmundt merged 1 commit intoPyomo:mainfrom
jsiirola:revert-fdopen-mode
Jun 24, 2025
Merged

Revert fdopen mode from 'a' to 'w'#3640
mrmundt merged 1 commit intoPyomo:mainfrom
jsiirola:revert-fdopen-mode

Conversation

@jsiirola
Copy link
Copy Markdown
Member

Fixes # .

Summary/Motivation:

This reverts part of #3633. @avdudchenko reported that the use of "a" was leading to errors on Windows when running

pytest -s pyomo\contrib\pynumero\examples\tests\test_cyipopt_examples.py

or

python pyomo\contrib\pynumero\examples\external_grey_box\react_example\maximize_cb_outputs.py

Giving errors like:

ERROR: Exception encountered during cyipopt solve:
Traceback (most recent call last):
  File "d:\github\pyomo\pyomo\contrib\pynumero\algorithms\solvers\cyipopt_solver.py", line 386, in solve
    with capture_output(sys.stdout if config.tee else None, capture_fd=True):
  File "d:\github\pyomo\pyomo\common\tee.py", line 305, in __enter__
    return self._enter_impl()
           ^^^^^^^^^^^^^^^^^^
  File "d:\github\pyomo\pyomo\common\tee.py", line 350, in _enter_impl
    os.fdopen(
  File "<frozen os>", line 1031, in fdopen
ValueError: Must have exactly one of read or write mode
Traceback (most recent call last):
  File "D:\github\pyomo\pyomo\contrib\pynumero\examples\external_grey_box\react_example\maximize_cb_outputs.py", line 47, in <module>
    m = maximize_cb_outputs(show_solver_log=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\github\pyomo\pyomo\contrib\pynumero\examples\external_grey_box\react_example\maximize_cb_outputs.py", line 41, in maximize_cb_outputs
    results = solver.solve(m, tee=show_solver_log)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\github\pyomo\pyomo\contrib\pynumero\algorithms\solvers\cyipopt_solver.py", line 386, in solve
    with capture_output(sys.stdout if config.tee else None, capture_fd=True):
  File "d:\github\pyomo\pyomo\common\tee.py", line 305, in __enter__
    return self._enter_impl()
           ^^^^^^^^^^^^^^^^^^
  File "d:\github\pyomo\pyomo\common\tee.py", line 350, in _enter_impl
    os.fdopen(
  File "<frozen os>", line 1031, in fdopen
ValueError: Must have exactly one of read or write mode

It was not clear how to reproduce / test this error in GHA. These examples are currently being tested without error. It might be that we would have to change how the examples were being run by pytest (i.e., adding -s)?

Changes proposed in this PR:

  • Open file descriptors in "w" mode for Windows compatibility

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.99%. Comparing base (ca33341) to head (2df6e99).
⚠️ Report is 1164 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3640      +/-   ##
==========================================
+ Coverage   88.93%   88.99%   +0.05%     
==========================================
  Files         888      888              
  Lines      102406   103349     +943     
==========================================
+ Hits        91079    91972     +893     
- Misses      11327    11377      +50     
Flag Coverage Δ
builders 26.69% <33.33%> (+<0.01%) ⬆️
default 85.52% <100.00%> (?)
expensive 34.05% <33.33%> (?)
linux 86.75% <100.00%> (-1.95%) ⬇️
linux_other 86.75% <100.00%> (+<0.01%) ⬆️
osx 83.05% <100.00%> (+<0.01%) ⬆️
win 84.97% <100.00%> (+<0.01%) ⬆️
win_other 84.97% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-project-automation github-project-automation bot moved this from Todo to Reviewer Approved in August 2025 Release Jun 24, 2025
@mrmundt mrmundt merged commit 56521be into Pyomo:main Jun 24, 2025
62 of 63 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer Approved to Done in August 2025 Release Jun 24, 2025
@jsiirola jsiirola deleted the revert-fdopen-mode branch August 1, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

3 participants