From 5b6a34fad4a296e320a5dc69200392e0f947192a Mon Sep 17 00:00:00 2001 From: Ryosuke Ito Date: Mon, 8 Jan 2024 11:37:01 +0900 Subject: [PATCH] Add workaround to recognize escaped newlines --- Package/Tests/Fixtures/__init__.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Package/Tests/Fixtures/__init__.py b/Package/Tests/Fixtures/__init__.py index 46cb47d..163b07a 100644 --- a/Package/Tests/Fixtures/__init__.py +++ b/Package/Tests/Fixtures/__init__.py @@ -1,11 +1,23 @@ -try: - from sysconfig import _parse_makefile as parse_makefile -except ImportError: - from distutils.sysconfig import parse_makefile from functools import cached_property import pathlib import shlex +try: + from distutils.sysconfig import parse_makefile +except ImportError: + from sysconfig import _parse_makefile + from tempfile import NamedTemporaryFile + + # https://github.com/python/cpython/blob/v3.11.7/Lib/distutils/sysconfig.py#L72 + def parse_makefile(fn, g=None): + with open(fn, mode='rb') as src, NamedTemporaryFile() as dest: + data = src.read() + # `distutils.sysconfig.parse_makefile` understands escaped newlines + # but `sysconfig._parse_makefile` does not. + # The next line fills the gap by just replacing escaped newlines. + dest.write(data.replace(b'\\\n', b' ')) + dest.seek(0) + return _parse_makefile(dest.name, g) _script_path = pathlib.Path(__file__)