Skip to content

Replace usage of sys.stdout.encoding with sys.getdefaultencoding() #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

t-kalinowski
Copy link
Contributor

@t-kalinowski t-kalinowski commented Jan 26, 2024

This fixes an error encountered when importing pymc in a rmarkdown document code chunk.

In that context, sys.stdout is replaced with a StringIO() object to capture all output, and sys.stdout.encoding returns None, raising an exception.

closes rstudio/reticulate#1508

Description

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

In some environments, `sys.stdout.encoding` may return `None`. 

This is encountered when knitting an rmarkdown document using the reticulate engine. In that context, `sys.stdout` is replaced with a `StringIO()` object to capture all output. `StringIO().encoding` returns `None`

closes rstudio/reticulate#1508
@ricardoV94 ricardoV94 requested a review from lucianopaz January 26, 2024 21:59
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (da471a8) 80.80% compared to head (67fa918) 80.80%.
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #617   +/-   ##
=======================================
  Coverage   80.80%   80.80%           
=======================================
  Files         162      162           
  Lines       46743    46743           
  Branches    11419    11419           
=======================================
  Hits        37770    37770           
  Misses       6731     6731           
  Partials     2242     2242           
Files Coverage Δ
pytensor/link/c/cmodule.py 55.74% <ø> (ø)

Copy link
Member

@lucianopaz lucianopaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @t-kalinowski! I had no idea that sys.stdout could end up being a StringIO outside of the scope of tests. This looks much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pymc issue when knitting a document
4 participants