Commit 36795cbf authored by Jérome Perrin's avatar Jérome Perrin

prune: fix detection of parts used in scripts

python interpreter is sometimes referenced only in bin/buildout's
shebang, even if not used anymore in any software, if it was used to
initially created the buildout. In that case, the part should still be
considered as used and not pruned.
parent 83da99e0
Pipeline #8441 passed with stage
in 0 seconds
......@@ -149,6 +149,9 @@ def getUsageSignatureFromSoftwareAndSharedPart(
'.installed.cfg')):
with open(installed_cfg) as f:
signatures[installed_cfg] = f.read()
for script in glob.glob(os.path.join(software_root, '*', 'bin', '*')):
with open(script) as f:
signatures[script] = f.read()
if shared_root:
for shared_signature in glob.glob(os.path.join(shared_root, '*', '*',
'.*signature')):
......
......@@ -110,6 +110,20 @@ class TestPrune(unittest.TestCase):
self.logger.warning.assert_called_with(
'Unusued shared parts at %s%s', not_used, ' ... removed')
def test_shared_part_used_in_buildout_script(self):
not_used = self._createSharedPart('not_used')
used_in_script = self._createSharedPart('used_in_script')
fake_software_path = self._createFakeSoftware(self.id())
os.mkdir(os.path.join(fake_software_path, 'bin'))
script = os.path.join(fake_software_path, 'bin', 'buildout')
with open(script, 'w') as f:
f.write('#!{}'.format(used_in_script))
do_prune(self.logger, self.config, False)
self.assertTrue(os.path.exists(used_in_script))
self.assertFalse(os.path.exists(not_used))
self.logger.warning.assert_called_with(
'Unusued shared parts at %s%s', not_used, ' ... removed')
def test_shared_part_used_in_recursive_instance(self):
used_in_software_from_instance = self._createSharedPart('used_in_software_from_instance')
used_in_shared_part_from_instance = self._createSharedPart('used_in_shared_part_from_instance')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment