Skip to content

Commit 717d790

Browse files
committed
remove extensions in igor
1 parent 2a2a54f commit 717d790

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ help: ## Show this help.
1616
@awk -F ':.*##' '/^[^: ]+:.*##/{printf " \033[1m%-20s\033[m %s\n",$$1,$$2} /^##@/{printf "\n%s\n",substr($$0,5)}' $(MAKEFILE_LIST)
1717

1818
_clean_platform:
19-
@rm -f *.so */*.so
20-
@rm -f *.pyd */*.pyd
19+
@rm -f *.so */*.so */*.so.hidden
20+
@rm -f *.pyd */*.pyd */*.pyd.hidden
2121
@rm -rf __pycache__ */__pycache__ */*/__pycache__ */*/*/__pycache__ */*/*/*/__pycache__ */*/*/*/*/__pycache__
2222
@rm -f *.pyc */*.pyc */*/*.pyc */*/*/*.pyc */*/*/*/*.pyc */*/*/*/*/*.pyc
2323
@rm -f *.pyo */*.pyo */*/*.pyo */*/*/*.pyo */*/*/*/*.pyo */*/*/*/*/*.pyo

igor.py

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

5454

55-
def do_remove_extension(*args):
56-
"""Remove the compiled C extension, no matter what its name."""
55+
def hide_extension(core, *args):
56+
"""Hide the compiled C extension, no matter what its name."""
57+
58+
if core == "ctrace":
59+
return
5760

5861
so_patterns = """
5962
tracer.so
@@ -94,7 +97,11 @@ def do_remove_extension(*args):
9497
if VERBOSITY > 1:
9598
print(f"Removing {os.path.abspath(filename)}")
9699
try:
97-
os.remove(filename)
100+
hidden_name = filename + ".hidden"
101+
if os.path.exists(hidden_name):
102+
os.remove(hidden_name)
103+
os.rename(filename, hidden_name)
104+
return hidden_name
98105
except OSError as exc:
99106
if VERBOSITY > 1:
100107
print(f"Couldn't remove {os.path.abspath(filename)}: {exc}")
@@ -157,11 +164,16 @@ def make_env_id(core):
157164

158165
def run_tests(core, *runner_args):
159166
"""The actual running of tests."""
167+
hidden = hide_extension(core)
160168
if "COVERAGE_TESTING" not in os.environ:
161169
os.environ["COVERAGE_TESTING"] = "True"
162170
print_banner(label_for_core(core))
163171

164-
return pytest.main(list(runner_args))
172+
try:
173+
return pytest.main(list(runner_args))
174+
finally:
175+
if hidden:
176+
os.remove(hidden)
165177

166178

167179
def run_tests_with_coverage(core, *runner_args):
@@ -210,6 +222,8 @@ def run_tests_with_coverage(core, *runner_args):
210222
if getattr(mod, "__file__", "??").startswith(covdir):
211223
covmods[name] = mod
212224
del sys.modules[name]
225+
hidden = hide_extension(core)
226+
# print("igor: re-importing coverage")
213227
import coverage # pylint: disable=reimported
214228

215229
sys.modules.update(covmods)
@@ -220,6 +234,8 @@ def run_tests_with_coverage(core, *runner_args):
220234
finally:
221235
cov.stop()
222236
os.remove(pth_path)
237+
if hidden:
238+
os.remove(hidden)
223239

224240
cov.save()
225241
return status

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)