Skip to content

Commit

Permalink
In test_build_ext, expose Path objects and use a path builder to buil…
Browse files Browse the repository at this point in the history
…d content. Fixes some EncodingWarnings. Ref #232.
  • Loading branch information
jaraco committed Mar 2, 2024
1 parent f60cd62 commit 4f2fec7
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import textwrap
import site
import contextlib
import pathlib
import platform
import tempfile
import importlib
Expand All @@ -12,6 +13,7 @@

import path
import pytest
import jaraco.path

from distutils.core import Distribution
from distutils.command.build_ext import build_ext
Expand All @@ -38,6 +40,7 @@
def user_site_dir(request):
self = request.instance
self.tmp_dir = self.mkdtemp()
self.tmp_path = path.Path(self.tmp_dir)
from distutils.command import build_ext

orig_user_base = site.USER_BASE
Expand All @@ -48,7 +51,7 @@ def user_site_dir(request):
# bpo-30132: On Windows, a .pdb file may be created in the current
# working directory. Create a temporary working directory to cleanup
# everything at the end of the test.
with path.Path(self.tmp_dir):
with self.tmp_path:
yield

site.USER_BASE = orig_user_base
Expand Down Expand Up @@ -496,25 +499,22 @@ def _try_compile_deployment_target(self, operator, target):
else:
os.environ['MACOSX_DEPLOYMENT_TARGET'] = target

deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
jaraco.path.build(
{
'deptargetmodule.c': textwrap.dedent(f"""\
#include <AvailabilityMacros.h>
with open(deptarget_c, 'w') as fp:
fp.write(
textwrap.dedent(
"""\
#include <AvailabilityMacros.h>
int dummy;
int dummy;
#if TARGET {operator} MAC_OS_X_VERSION_MIN_REQUIRED
#else
#error "Unexpected target"
#endif
#if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED
#else
#error "Unexpected target"
#endif
"""
% operator
)
)
"""),
},
self.tmp_path,
)

# get the deployment target that the interpreter was built with
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
Expand All @@ -534,7 +534,7 @@ def _try_compile_deployment_target(self, operator, target):
target = '%02d0000' % target
deptarget_ext = Extension(
'deptarget',
[deptarget_c],
[self.tmp_path / 'deptargetmodule.c'],
extra_compile_args=['-DTARGET={}'.format(target)],
)
dist = Distribution({'name': 'deptarget', 'ext_modules': [deptarget_ext]})
Expand Down

0 comments on commit 4f2fec7

Please sign in to comment.