Skip to content
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

EncodingWarnings raised (3) when using pyfakefs #957

Closed
jaraco opened this issue Mar 2, 2024 · 7 comments · Fixed by #958
Closed

EncodingWarnings raised (3) when using pyfakefs #957

jaraco opened this issue Mar 2, 2024 · 7 comments · Fixed by #958

Comments

@jaraco
Copy link

jaraco commented Mar 2, 2024

When running the distutils test suite, I see the following warnings:

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/fake_file.py:266: EncodingWarning: UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.
    self.encoding or locale.getpreferredencoding(False),

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/fake_file.py:748: EncodingWarning: UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.
    self._encoding = encoding or locale.getpreferredencoding(False)

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/helpers.py:409: EncodingWarning: 'encoding' argument not specified
    super().__init__(self._bytestream, encoding, errors, newline)
@mrbean-bremen
Copy link
Member

mrbean-bremen commented Mar 3, 2024

The first 2 warnings are trivial to fix, but as far as I can see, the third warning:

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/helpers.py:409: EncodingWarning: 'encoding' argument not specified
    super().__init__(self._bytestream, encoding, errors, newline)

comes from the client code:

 fake_home.joinpath(pydistutils_cfg).write_text('')

write_text misses the encoding argument.

@jaraco - can you confirm this?

@jaraco
Copy link
Author

jaraco commented Mar 3, 2024

Yes, that's right (confirmed in pypa/distutils@38b58a5b). I thought it might be something like that. I was unsure because the warning only gives the one location. I wonder if it's possible to alter the stacklevel or otherwise manipulate the warning in the __init__ wrapper, but I can't think of a way to do it. I also asked Gemini, and it also couldn't devise a general solution.

I guess one solution could be to capture the warning in the init wrapper and then emit a new warning. Not sure it's worth it except to improve the discoverability for other users.

Out of curiosity, how did you track it down?

@mrbean-bremen
Copy link
Member

Thanks for the fast response!

I guess one solution could be to capture the warning in the init wrapper and then emit a new warning

Well, that would be a possibility, but I'm reluctant to go that way. It would make the code more complicated for a questionable improvement.

Out of curiosity, how did you track it down?

That was easy - the warning message says where it comes from, and I just checked the respective code in disutils.
Oh, and I also made sure to get the same warning in the real fs.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 3, 2024
- from Python 3.11 on, this is the preferred version
- fixes pytest-dev#957
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 3, 2024
- from Python 3.11 on, this is the preferred version
- fixes pytest-dev#957
mrbean-bremen added a commit that referenced this issue Mar 3, 2024
- from Python 3.11 on, this is the preferred version
- fixes #957
@mrbean-bremen
Copy link
Member

Should be fixed in main now. Do you need a patch release?

@jaraco
Copy link
Author

jaraco commented Mar 3, 2024

Out of curiosity, how did you track it down?

That was easy - the warning message says where it comes from, and I just checked the respective code in disutils. Oh, and I also made sure to get the same warning in the real fs.

Oh! True. The output does mention the test that was being run. I didn't investigate it because I knew that in general the warning could have been triggered anywhere within that test (as part of setup/teardown or deep in the exercised behavior), but as it turns out, it was right there, so that makes sense.

Agreed, probably not worth the hassle to try to surface those - but you may decide to revisit when these warnings surface for all users and not just those opting into the warnings early.

I don't need a patch release. More important will be to have a notice here when the release is made so I can know to remove the warning exclusion.

@mrbean-bremen
Copy link
Member

you may decide to revisit when these warnings surface for all users and not just those opting into the warnings early

Sure, if this pops up again, I will remember that ;)

More important will be to have a notice here when the release is made so I can know to remove the warning exclusion.

Sure, I'll let you know.

@mrbean-bremen
Copy link
Member

FYI: A new release is out.

jaraco added a commit to pypa/distutils that referenced this issue Apr 7, 2024
clrpackages pushed a commit to clearlinux-pkgs/pypi-setuptools that referenced this issue Apr 15, 2024
…version 69.5.0

Anderson Bravalheri (3):
      Improve test_rfc822_escape, capturing interoperability requirements
      Improve TestMetadata, capturing interoperability requirements
      Fix interoperability of rfc822_escape with stblib's email library

Avasam (1):
      Allow mypy on PyPy (jaraco/skeleton#111)

Bartosz Sławecki (1):
      Add link to blog entry from jaraco/skeleton#115 above CI build matrix.

DWesl (2):
      CI: Install git on Cygwin CI runner
      CI: Try to fix Cygwin tox configuration.

Dimitri Papadopoulos (1):
      Update URLs in documentation: http:// → https://

Dustin Ingram (6):
      Support PEP 625
      Add news fragment
      Revert changes to distutils
      Try monkeypatching right before we use it instead
      Linting
      Fix canonicalization

Harmen Stoppels (1):
      GNU: use -Wl,-rpath,<dir> instead of -Wl,-R<dir>

Jason R. Coombs (96):
      Copy 'missing_compiler_executable from Python 3.12 and customize it for compatibility with distutils.
      Remove build and dist from excludes. It appears they are not needed and their presence blocks the names of packages like 'builder' and 'distutils'. Ref pypa/distutils#224.
      Mark this function as uncovered.
      Also disable the check
      Remove pin on inflect as it's insufficient to avoid the Rust dependency.
      Remove Sphinx pin. Ref sphinx-doc/sphinx#11662.
      👹 Feed the hobgoblins (delint).
      Extracted method for resolving python lib dir.
      👹 Feed the hobgoblins (delint).
      Update more tests to match the new expectation.
      Rely on always_iterable to conditionally extend the lib_opts.
      Restore integration test with Setuptools
      Include deps from the base config in diffcov.
      Enable complexity check and pycodestyle warnings. Closes jaraco/skeleton#110.
      Extract a method for customizing the compiler for macOS.
      Convert comment to docstring; update wording.
      Create a fixture to patch-out compiler customization on macOS.
      Utilize the fixture for disabling compiler customization on macOS for cxx test. Closes #231.
      Limit mutating global state and simply rely on functools.lru_cache to limit the behavior to a single invocation.
      Use 'extend-select' to avoid disabling the default config. Ref jaraco/skeleton#110.
      In test_build_ext, expose Path objects and use a path builder to build content. Fixes some EncodingWarnings. Ref pypa/distutils#232.
      In support, specify encoding. Ref pypa/distutils#232.
      In test_build_py, rely on tree builder to build trees. Ref pypa/distutils#232.
      Specify encoding in util.byte_compile. Ref pypa/distutils#232.
      Rely on tree builder in test_build_scripts. Ref pypa/distutils#232.
      Rely on Path object to replace the suffix, open the file, and count the lines. Ref pypa/distutils#232.
      Fix EncodingWarnings in test_core. Ref pypa/distutils#232.
      Ran pyupgrade for Python 3.8+ followed by ruff format.
      Rely on tree builder in test_dir_util. Ref pypa/distutils#232.
      Rely on tree builder and path objects. Ref pypa/distutils#232.
      Remove reliance on TempdirManager in test_file_util.
      Rely on tmp_path fixture directly.
      👹 Feed the hobgoblins (delint).
      Rely on tree builder. Ref pypa/distutils#232.
      Specify encoding in test_install. Ref pypa/distutils#232.
      Re-use write_sample_scripts in test_install_scripts. Ref pypa/distutils#232.
      Use Path objects in test_register. Ref pypa/distutils#232.
      Specify encoding in test_sdist. Ref pypa/distutils#232.
      Fix EncodingWarning in test_spawn. Ref pypa/distutils#232.
      Fix EncodingWarnings in test_sdist. Ref pypa/distutils#232.
      Rely on tree builder. Ref pypa/distutils#232.
      Ran pyupgrade for Python 3.8+ followed by ruff format.
      Suppress diffcov error.
      Suppress more diffcov errors.
      Address EncodingWarning in ccompiler. Ref pypa/distutils#232.
      Fix EncodingWarnings in distutils/command/config.py. Ref pypa/distutils#232.
      Fix EncodingWarnings in distutils/config.py. Ref pypa/distutils#232.
      Fix EncodingWarnings in sdist.py. Ref pypa/distutils#232.
      Fix EncodingWarnings in text_file.py. Ref pypa/distutils#232.
      Fix EncodingWarnings in dist.py. Ref pypa/distutils#232.
      Fix EncodingWarning in cygwinccompiler. Ref pypa/distutils#232.
      Fix EncodingWarning in file_util. Ref pypa/distutils#232.
      Suppress EncodingWarnings in pyfakefs. Ref pypa/distutils#232. Workaround for pytest-dev/pyfakefs#957.
      Replaced deprecated cgi module with email module. Ref pypa/distutils#232.
      Fix exception reference in missing_compiler_executable. Ref pypa/distutils#225. Closes pypa/distutils#238.
      Satisfy EncodingWarning by passing the encoding.
      Re-enable ignoring of temporary merge queue branches. Closes jaraco/skeleton#103.
      Fetch unshallow clones in readthedocs. Closes jaraco/skeleton#114.
      Move Python 3.11 out of the test matrix.
      Configure pytest to support namespace packages. Ref pytest-dev/pytest#12112.
      Revert "Suppress EncodingWarnings in pyfakefs. Ref pypa/distutils#232. Workaround for pytest-dev/pyfakefs#957."
      🧎‍♀️ Genuflect to the types.
      Fix ruff.toml syntax and suppress emergent failure.
      Move implementation to monkey.patch.
      Update readme to reflect current state.
      Apply ruff --select UP safe fixes.
      Apply ruff --select UP unsafe fixes.
      👹 Feed the hobgoblins (delint).
      👹 Feed the hobgoblins (delint).
      👹 Feed the hobgoblins (delint).
      Remove unreachable branch
      Extract method for comparing prerelease. Satisfies complexity check.
      Re-organize for brevity.
      Rely on None==None and handle two cases together.
      Refresh RangeMap from jaraco.collections 5.0.1.
      Ruff fixes B007.
      👹 Feed the hobgoblins (delint).
      Fix B026 by moving star arg ahead of keyword arg.
      Extract 'make_iterable' for upload and register commands, avoiding masking loop input variable (B020).
      Fix pointless comparison (B015).
      Remove Python 3.7 compatibility from build_ext
      Remove Python 3.7 compatibility from test_sysconfig.
      Move comment nearer the skip directive. Update wording.
      Add news fragment.
      Omit distutils from coverage checks.
      Fix EncodingWarnings in tools.finalize.
      Bump version: 69.2.0 → 69.3.0
      Refresh unpinned vendored dependencies.
      Ensure that 'backports' is included on older Pythons
      Exclude vendored packages and tools from coverage checks.
      Bump version: 69.3.0 → 69.4.0
      Update to packaging 24
      Remove attempt to canonicalize the version. It's already canonical enough.
      Bump version: 69.3.0 → 69.3.1
      Bump version: 69.4.0 → 69.4.1
      Bump version: 69.4.1 → 69.5.0

Lisandro Dalcin (1):
      Fix accumulating flags after compile/link

Marcel Telka (1):
      Add mypy.ini to MANIFEST.in

Steve Dower (2):
      Fixes pypa/distutils#219 Use sysconfig.get_config_h_filename() to locate pyconfig.h
      Also use sysconfig.get_config_h_filename() to implement distutils.sysconfig version

Steven Pitman (1):
      Add support for z/OS compilers; Fixes pypa/distutils#215
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 a pull request may close this issue.

2 participants