Skip to content

Commit b93f5bd

Browse files
committed
build: hide extension to test other cores
1 parent 2229ae7 commit b93f5bd

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

igor.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,52 +52,50 @@ def do_show_env():
5252
print(f" {env} = {os.environ[env]!r}")
5353

5454

55-
def do_remove_extension(*args):
55+
def remove_extension(core):
5656
"""Remove the compiled C extension, no matter what its name."""
5757

58+
if core == "ctrace":
59+
return
60+
5861
so_patterns = """
5962
tracer.so
6063
tracer.*.so
6164
tracer.pyd
6265
tracer.*.pyd
6366
""".split()
6467

65-
if "--from-install" in args:
66-
# Get the install location using a subprocess to avoid
67-
# locking the file we are about to delete
68-
root = os.path.dirname(
69-
subprocess.check_output(
70-
[
71-
sys.executable,
72-
"-Xutf8",
73-
"-c",
74-
"import coverage; print(coverage.__file__)",
75-
],
76-
encoding="utf-8",
77-
).strip(),
78-
)
79-
roots = [root]
80-
else:
81-
roots = [
82-
"coverage",
83-
"build/*/coverage",
84-
".tox/*/[Ll]ib/*/site-packages/coverage",
85-
".tox/*/[Ll]ib/site-packages/coverage",
86-
]
68+
roots = [
69+
"coverage",
70+
"build/*/coverage",
71+
".tox/*/[Ll]ib/*/site-packages/coverage",
72+
".tox/*/[Ll]ib/site-packages/coverage",
73+
]
8774

75+
# On windows at least, we can't delete a loaded .pyd file. So move them
76+
# out of the way into the tmp/ directory.
77+
os.makedirs("tmp", exist_ok=True)
8878
for root, pattern in itertools.product(roots, so_patterns):
8979
pattern = os.path.join(root, pattern)
9080
if VERBOSITY > 1:
9181
print(f"Searching for {pattern} from {os.getcwd()}")
9282
for filename in glob.glob(pattern):
9383
if os.path.exists(filename):
84+
hidden = f"tmp/{os.path.basename(filename)}"
9485
if VERBOSITY > 1:
95-
print(f"Removing {os.path.abspath(filename)}")
86+
print(f"Moving {filename} to {hidden}")
9687
try:
97-
os.remove(filename)
88+
if os.path.exists(hidden):
89+
os.remove(hidden)
9890
except OSError as exc:
9991
if VERBOSITY > 1:
100-
print(f"Couldn't remove {os.path.abspath(filename)}: {exc}")
92+
print(f"Couldn't remove {hidden}: {exc}")
93+
else:
94+
try:
95+
os.rename(filename, hidden)
96+
except OSError as exc:
97+
if VERBOSITY > 1:
98+
print(f"Couldn't rename: {exc}")
10199

102100

103101
def label_for_core(core):
@@ -157,10 +155,10 @@ def make_env_id(core):
157155

158156
def run_tests(core, *runner_args):
159157
"""The actual running of tests."""
158+
remove_extension(core)
160159
if "COVERAGE_TESTING" not in os.environ:
161160
os.environ["COVERAGE_TESTING"] = "True"
162161
print_banner(label_for_core(core))
163-
164162
return pytest.main(list(runner_args))
165163

166164

@@ -209,6 +207,8 @@ def run_tests_with_coverage(core, *runner_args):
209207
if getattr(mod, "__file__", "??").startswith(covdir):
210208
covmods[name] = mod
211209
del sys.modules[name]
210+
remove_extension(core)
211+
212212
import coverage # pylint: disable=reimported
213213

214214
sys.modules.update(covmods)

tox.ini

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ commands =
4242
# Create tests/zipmods.zip
4343
python igor.py zip_mods
4444

45-
# Remove the C extension so that we can test the PyTracer
46-
python igor.py remove_extension
47-
48-
# Test with the PyTracer
49-
python igor.py test_with_core pytrace {posargs}
50-
5145
# Build the C extension and test with the CTracer
5246
python setup.py --quiet build_ext --inplace
5347
python -m pip install {env:COVERAGE_PIP_ARGS} -q -e .
5448
python igor.py test_with_core ctrace {posargs}
5549

50+
# Test with the PyTracer
51+
python igor.py test_with_core pytrace {posargs}
52+
53+
# Test with sys.monitoring
5654
py3{12-15}{,t},anypy: python igor.py test_with_core sysmon {posargs}
5755

5856
[testenv:anypy]

0 commit comments

Comments
 (0)