From 80d101eea16a6fc72759e193882ef60451f51d98 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 8 Mar 2024 17:21:56 -0500 Subject: [PATCH 01/16] Update `pytest.ini` for `EncodingWarning` from external libraries + avoid getpreferredencoding when possible --- pytest.ini | 27 ++++++++++++++------------- setuptools/command/editable_wheel.py | 3 ++- setuptools/tests/__init__.py | 9 +++++++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pytest.ini b/pytest.ini index e7c96274a3..40a64b5cd4 100644 --- a/pytest.ini +++ b/pytest.ini @@ -10,6 +10,18 @@ filterwarnings= # Fail on warnings error + # Workarounds for pypa/setuptools#3810 + # Can't use EncodingWarning as it doesn't exist on Python 3.9. + # These warnings only appear on Python 3.10+ + default:'encoding' argument not specified + + # pypa/distutils#236 + ignore:'encoding' argument not specified::distutils + ignore:'encoding' argument not specified::setuptools._distutils + + # subprocess.check_output still warns with EncodingWarning even with encoding set + ignore:'encoding' argument not specified::setuptools.tests.environment + ## upstream # Ensure ResourceWarnings are emitted @@ -18,14 +30,8 @@ filterwarnings= # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy - # python/cpython#100750 - ignore:'encoding' argument not specified::platform - - # pypa/build#615 - ignore:'encoding' argument not specified::build.env - - # dateutil/dateutil#1284 - ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:dateutil.tz.tz + # pytest-dev/pytest # TODO: Raise issue upstream + ignore:'encoding' argument not specified::_pytest ## end upstream @@ -69,11 +75,6 @@ filterwarnings= # https://github.com/pypa/setuptools/issues/3655 ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning - # Workarounds for pypa/setuptools#3810 - # Can't use EncodingWarning as it doesn't exist on Python 3.9 - default:'encoding' argument not specified - default:UTF-8 Mode affects locale.getpreferredencoding(). - # Avoid errors when testing pkg_resources.declare_namespace ignore:.*pkg_resources\.declare_namespace.*:DeprecationWarning diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 1722817f82..b8ed84750a 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -565,7 +565,8 @@ def _encode_pth(content: str) -> bytes: This function tries to simulate this behaviour without having to create an actual file, in a way that supports a range of active Python versions. (There seems to be some variety in the way different version of Python handle - ``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``). + ``encoding=None``, not all of them use ``locale.getpreferredencoding(False)`` + or ``locale.getencoding()``). """ with io.BytesIO() as buffer: wrapper = io.TextIOWrapper(buffer, encoding=py39.LOCALE_ENCODING) diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py index 564adf2b0a..738ebf43be 100644 --- a/setuptools/tests/__init__.py +++ b/setuptools/tests/__init__.py @@ -1,10 +1,15 @@ import locale +import sys import pytest __all__ = ['fail_on_ascii'] - -is_ascii = locale.getpreferredencoding() == 'ANSI_X3.4-1968' +locale_encoding = ( + locale.getencoding() + if sys.version_info >= (3, 11) + else locale.getpreferredencoding(False) +) +is_ascii = locale_encoding == 'ANSI_X3.4-1968' fail_on_ascii = pytest.mark.xfail(is_ascii, reason="Test fails in this locale") From 9acea31d0e8c3f94db7dca3fedaa256d0f8a2250 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 21 Apr 2024 16:18:38 -0400 Subject: [PATCH 02/16] Remove distutils EncodingWarning exclusion in pytest.ini Vendored distutils was updated with fixes --- pytest.ini | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pytest.ini b/pytest.ini index 40a64b5cd4..2ce6e3e1e7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -15,10 +15,6 @@ filterwarnings= # These warnings only appear on Python 3.10+ default:'encoding' argument not specified - # pypa/distutils#236 - ignore:'encoding' argument not specified::distutils - ignore:'encoding' argument not specified::setuptools._distutils - # subprocess.check_output still warns with EncodingWarning even with encoding set ignore:'encoding' argument not specified::setuptools.tests.environment From 27f5e0ae4ba6fae8a30bc7b7aa674f8be2afc22f Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 22 Apr 2024 16:34:43 +0100 Subject: [PATCH 03/16] Ignore encoding warnings bu only in in stdlib's distutils --- pytest.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pytest.ini b/pytest.ini index 2ce6e3e1e7..648b145b69 100644 --- a/pytest.ini +++ b/pytest.ini @@ -29,6 +29,9 @@ filterwarnings= # pytest-dev/pytest # TODO: Raise issue upstream ignore:'encoding' argument not specified::_pytest + # Already fixed in pypa/distutils, but present in stdlib + ignore:'encoding' argument not specified::distutils + ## end upstream # https://github.com/pypa/setuptools/issues/1823 From ef7d2590ec6b4e4a410b7e4f983386ae07f13f64 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 22 Apr 2024 14:36:08 +0100 Subject: [PATCH 04/16] Remove EncodingWarning workarounds for setuptools from pytest.ini --- pytest.ini | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pytest.ini b/pytest.ini index 648b145b69..1b565222e2 100644 --- a/pytest.ini +++ b/pytest.ini @@ -10,14 +10,6 @@ filterwarnings= # Fail on warnings error - # Workarounds for pypa/setuptools#3810 - # Can't use EncodingWarning as it doesn't exist on Python 3.9. - # These warnings only appear on Python 3.10+ - default:'encoding' argument not specified - - # subprocess.check_output still warns with EncodingWarning even with encoding set - ignore:'encoding' argument not specified::setuptools.tests.environment - ## upstream # Ensure ResourceWarnings are emitted From 4fc0b15d424ae97663d48a34ee7bd586b3aade69 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 22 Apr 2024 15:56:28 +0100 Subject: [PATCH 05/16] Fix EncodingWarning in test_build_meta --- setuptools/tests/test_build_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index 43830feb77..cc996b4255 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -160,7 +160,7 @@ def run(): # to obtain a distribution object first, and then run the distutils # commands later, because these files will be removed in the meantime. - with open('world.py', 'w') as f: + with open('world.py', 'w', encoding="utf-8") as f: f.write('x = 42') try: From d7ac06f0d5892183c9ac9ce5501d785348b4bbde Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 22 Apr 2024 21:48:32 +0100 Subject: [PATCH 06/16] Return comment to pytest.ini that got lost in changes --- pytest.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pytest.ini b/pytest.ini index 1b565222e2..2aceea2d58 100644 --- a/pytest.ini +++ b/pytest.ini @@ -10,6 +10,9 @@ filterwarnings= # Fail on warnings error + # Workarounds for pypa/setuptools#3810 + # Can't use EncodingWarning as it doesn't exist on Python 3.9. + # These warnings only appear on Python 3.10+ ## upstream # Ensure ResourceWarnings are emitted From 969f00b16d190567ce27d9788e90ab4806a32443 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 22 Apr 2024 22:54:45 +0100 Subject: [PATCH 07/16] Re-enable warning filter for distutils.text_file inside test_excluded_subpackages --- setuptools/tests/test_build_py.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setuptools/tests/test_build_py.py b/setuptools/tests/test_build_py.py index 4aa1fe68fa..db2052a586 100644 --- a/setuptools/tests/test_build_py.py +++ b/setuptools/tests/test_build_py.py @@ -1,6 +1,7 @@ import os import stat import shutil +import warnings from pathlib import Path from unittest.mock import Mock @@ -162,11 +163,23 @@ def test_excluded_subpackages(tmpdir_cwd): dist.parse_config_files() build_py = dist.get_command_obj("build_py") + msg = r"Python recognizes 'mypkg\.tests' as an importable package" with pytest.warns(SetuptoolsDeprecationWarning, match=msg): # TODO: To fix #3260 we need some transition period to deprecate the # existing behavior of `include_package_data`. After the transition, we # should remove the warning and fix the behaviour. + + if os.getenv("SETUPTOOLS_USE_DISTUTILS") == "stdlib": + # pytest.warns reset the warning filter temporarily + # https://github.com/pytest-dev/pytest/issues/4011#issuecomment-423494810 + warnings.filterwarnings( + "ignore", + "'encoding' argument not specified", + module="distutils.text_file", + # This warning is already fixed in pypa/distutils but not in stdlib + ) + build_py.finalize_options() build_py.run() From 919e3934c9e7a8085bd4ee72d3259be76fe0186b Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 23 Apr 2024 00:02:06 +0100 Subject: [PATCH 08/16] Attempt to fix errors in mypy for PyPy (test of hypothesis) --- pytest.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pytest.ini b/pytest.ini index 2aceea2d58..4bebae0fd9 100644 --- a/pytest.ini +++ b/pytest.ini @@ -18,6 +18,12 @@ filterwarnings= # Ensure ResourceWarnings are emitted default::ResourceWarning + # python/mypy#17057 + ignore:'encoding' argument not specified::mypy.config_parser + ignore:'encoding' argument not specified::mypy.build + ignore:'encoding' argument not specified::mypy.modulefinder + ignore:'encoding' argument not specified::mypy.metastore + # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy From 57ea91b448ca3852c33a2b164b5d6bdc3551a3a6 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 24 Apr 2024 16:34:19 +0100 Subject: [PATCH 09/16] Attempt to solve the problem in PyPy --- pytest.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pytest.ini b/pytest.ini index 4bebae0fd9..8ab6d5ebf1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -19,10 +19,10 @@ filterwarnings= default::ResourceWarning # python/mypy#17057 - ignore:'encoding' argument not specified::mypy.config_parser - ignore:'encoding' argument not specified::mypy.build - ignore:'encoding' argument not specified::mypy.modulefinder - ignore:'encoding' argument not specified::mypy.metastore + ignore:'encoding' argument not specified::mypy + ignore:'encoding' argument not specified::configparser + # ^-- ConfigParser is called by mypy, + # but ignoring the warning in `mypy` is not enough on PyPy # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy From 1316a611f2faf5828f3d10a1bb4df7a2475ebeef Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 24 Apr 2024 16:35:03 +0100 Subject: [PATCH 10/16] Better wording for comment in pytest.ini --- pytest.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index 8ab6d5ebf1..000e663471 100644 --- a/pytest.ini +++ b/pytest.ini @@ -22,7 +22,8 @@ filterwarnings= ignore:'encoding' argument not specified::mypy ignore:'encoding' argument not specified::configparser # ^-- ConfigParser is called by mypy, - # but ignoring the warning in `mypy` is not enough on PyPy + # but ignoring the warning in `mypy` is not enough + # to make it work on PyPy # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy From 8dc50ccc2fe55a3c6b2c99f5c95597242c61572d Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 24 Apr 2024 14:02:04 -0400 Subject: [PATCH 11/16] Add newsfragment --- newsfragments/4255.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/4255.misc.rst diff --git a/newsfragments/4255.misc.rst b/newsfragments/4255.misc.rst new file mode 100644 index 0000000000..1f9fde768b --- /dev/null +++ b/newsfragments/4255.misc.rst @@ -0,0 +1 @@ +Treat `EncodingWarning`s as an errors in tests. -- by :user:`Avasam` From b69c0de234a9b648828e5f3a180639f5ea0e24fa Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 24 Apr 2024 14:05:12 -0400 Subject: [PATCH 12/16] Update comment --- pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index 000e663471..87e3d9aae3 100644 --- a/pytest.ini +++ b/pytest.ini @@ -28,7 +28,7 @@ filterwarnings= # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy - # pytest-dev/pytest # TODO: Raise issue upstream + # TODO: Set encoding when openning tmpdir files with pytest's LocalPath.open ignore:'encoding' argument not specified::_pytest # Already fixed in pypa/distutils, but present in stdlib From b341011f3b8be7e10d933831750aed48b381f382 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 24 Apr 2024 14:38:00 -0400 Subject: [PATCH 13/16] Fix Windows issue --- setuptools/tests/test_windows_wrappers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/setuptools/tests/test_windows_wrappers.py b/setuptools/tests/test_windows_wrappers.py index 3f321386f1..b272689351 100644 --- a/setuptools/tests/test_windows_wrappers.py +++ b/setuptools/tests/test_windows_wrappers.py @@ -110,7 +110,11 @@ def test_basic(self, tmpdir): 'arg5 a\\\\b', ] proc = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, text=True + cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + text=True, + encoding="utf-8", ) stdout, stderr = proc.communicate('hello\nworld\n') actual = stdout.replace('\r\n', '\n') @@ -143,7 +147,11 @@ def test_symlink(self, tmpdir): 'arg5 a\\\\b', ] proc = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, text=True + cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + text=True, + encoding="utf-8", ) stdout, stderr = proc.communicate('hello\nworld\n') actual = stdout.replace('\r\n', '\n') @@ -191,6 +199,7 @@ def test_with_options(self, tmpdir): stdin=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, + encoding="utf-8", ) stdout, stderr = proc.communicate() actual = stdout.replace('\r\n', '\n') @@ -240,6 +249,7 @@ def test_basic(self, tmpdir): stdin=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, + encoding="utf-8", ) stdout, stderr = proc.communicate() assert not stdout From 22ca7e5ba90cce639e241428226279b0c7be2242 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 25 Apr 2024 12:29:09 +0100 Subject: [PATCH 14/16] Update comment in pytest.ini --- pytest.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index 87e3d9aae3..0c9651d96f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -13,6 +13,7 @@ filterwarnings= # Workarounds for pypa/setuptools#3810 # Can't use EncodingWarning as it doesn't exist on Python 3.9. # These warnings only appear on Python 3.10+ + ## upstream # Ensure ResourceWarnings are emitted @@ -28,7 +29,8 @@ filterwarnings= # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy - # TODO: Set encoding when openning tmpdir files with pytest's LocalPath.open + # TODO: Set encoding when openning/writing tmpdir files with pytest's LocalPath.open + # see pypa/setuptools#4326 ignore:'encoding' argument not specified::_pytest # Already fixed in pypa/distutils, but present in stdlib From 3ea4aa933ba140cb1c19ce44dfef4564563a79ac Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 25 Apr 2024 14:40:49 +0100 Subject: [PATCH 15/16] Improve RST syntax on news fragment. --- newsfragments/4255.misc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newsfragments/4255.misc.rst b/newsfragments/4255.misc.rst index 1f9fde768b..e5e5728d70 100644 --- a/newsfragments/4255.misc.rst +++ b/newsfragments/4255.misc.rst @@ -1 +1 @@ -Treat `EncodingWarning`s as an errors in tests. -- by :user:`Avasam` +Treat ``EncodingWarning``s as an errors in tests. -- by :user:`Avasam` From 0faba5086564eab2feb2fa94f2e4592c50589952 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 25 Apr 2024 10:05:44 -0400 Subject: [PATCH 16/16] Fix typo --- newsfragments/4255.misc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newsfragments/4255.misc.rst b/newsfragments/4255.misc.rst index e5e5728d70..50a0a3d195 100644 --- a/newsfragments/4255.misc.rst +++ b/newsfragments/4255.misc.rst @@ -1 +1 @@ -Treat ``EncodingWarning``s as an errors in tests. -- by :user:`Avasam` +Treat ``EncodingWarning``s as errors in tests. -- by :user:`Avasam`