Skip to content

Commit

Permalink
Work around .whl in use during teardown on Windows
Browse files Browse the repository at this point in the history
I think wheel.install.WheelFile isn't properly managing its handles and
doesn't close the zipfile when it's done with it. Force a gc at tearDown
time to clean up any references and so close the handle prior to the
rmtree done by buildoutTearDown which was failing on Windows with:

WindowsError: [Error 32] The process cannot access the file because it
is being used by another process:
'c:\\...\\_TEST_\\sample_eggs\\demo-1.0-py2-none-any.whl'

Also, can't use self.register_teardown because (bug?) buildoutTearDown
doesn't call the registerd functions in reverse order, so our cleanup
would run *after* the rmtree call regsitered by buildoutSetup, which is
too late.
  • Loading branch information
daybarr committed Apr 24, 2017
1 parent cd635a9 commit 502e3ad
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/buildout/wheel/tests/testwheel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gc
import os
import shutil
import sys
Expand All @@ -20,9 +21,20 @@ def globs(self):

def setUp(self):
self.here = os.path.dirname(__file__)
self.fake_buildout = None
zc.buildout.testing.buildoutSetUp(self)

def tearDown(self):
if self.fake_buildout:
pkg_resources.load_entry_point(
'buildout.wheel', 'zc.buildout.unloadextension', 'wheel'
)(self.fake_buildout)

# For Windows, have to force gc to close handle on '.whl' file
# prior to the rmtree done by buildoutTearDown
self.fake_buildout = None
gc.collect()

zc.buildout.testing.buildoutTearDown(self)
os.chdir(self.here)

Expand All @@ -46,12 +58,7 @@ def test_install_wheels(self):
buildout = Buildout()
pkg_resources.load_entry_point(
'buildout.wheel', 'zc.buildout.extension', 'wheel')(buildout)

@self.register_teardown
def unload():
pkg_resources.load_entry_point(
'buildout.wheel', 'zc.buildout.unloadextension', 'wheel'
)(buildout)
self.fake_buildout = buildout

ws = zc.buildout.easy_install.install(
['demo', 'extdemo'],
Expand Down

0 comments on commit 502e3ad

Please sign in to comment.