diff --git a/debpython/namespace.py b/debpython/namespace.py index 5810e08c01cc3df0d11e5cba010393d1db9ec1ff..1aa795c2b4851b3df052e09206f0458791b7524f 100644 --- a/debpython/namespace.py +++ b/debpython/namespace.py @@ -22,7 +22,7 @@ from __future__ import with_statement import logging from os import environ, listdir, remove, rmdir -from os.path import dirname, exists, join, getsize +from os.path import dirname, exists, join, getsize, split from subprocess import Popen, PIPE from debpython.pydist import PUBLIC_DIR_RE @@ -82,19 +82,22 @@ def add_namespace_files(files, package=None, action=None): if dpath not in already_processed: already_processed.add(dpath) if PUBLIC_DIR_RE.match(dpath): - for ns in namespaces: - fpath = join(dpath, '__init__.py') - if dpath.endswith(ns): - if action is True: - try: - open(fpath, 'a').close() - except: - log.error('cannot create %s', fpath) - else: - yield fpath - else: # action is False - # postpone it due to dpkg -S call - removal_candidates.add(fpath) + while not dpath.endswith(('site-packages', 'dist-packages')): + for ns in namespaces: + fpath = join(dpath, '__init__.py') + if dpath.endswith(ns): + if action is True: + try: + open(fpath, 'a').close() + except: + log.error('cannot create %s', fpath) + else: + yield fpath + else: # action is False + # postpone it due to dpkg -S call + removal_candidates.add(fpath) + already_processed.add(dpath) + dpath = split(dpath)[0] # now deal with to-be-removed namespace candidates (dpkg -S is expensive) # dpgk -S is used just to be safe (in case some other package is providing diff --git a/pyclean b/pyclean index 7ab9e506d8a7b909286f0d3eabedf14ae321ed64..81035d2d35b0f32b4f5a0f66cd9c31c2533ef9db 100755 --- a/pyclean +++ b/pyclean @@ -24,9 +24,10 @@ import logging import optparse +import sys from os import environ, remove from os.path import exists -from sys import argv +sys.path.insert(1, '/usr/share/python/') from debpython import files as dpf from debpython.namespace import add_namespace_files @@ -81,7 +82,7 @@ def main(): if options.verbose or environ.get('PYCLEAN_DEBUG') == '1': log.setLevel(logging.DEBUG) - log.debug('argv: %s', argv) + log.debug('argv: %s', sys.argv) log.debug('options: %s', options) log.debug('args: %s', args) else: diff --git a/pycompile b/pycompile index d21ed61046ff9bcf42f53fb1a39085601b24d3b2..1ff303fff7298b57d9c2f00669f70b110da1bf09 100755 --- a/pycompile +++ b/pycompile @@ -266,9 +266,7 @@ multiple times to build up a list of things to exclude.') for item in args: e_patterns = get_exclude_patterns(item, options.regexpr, versions) files = dpf.from_directory(item, extensions=('.py', '.so')) - files = list(files); print files files = add_namespace_files(files, action=True) - files = list(files); print files files = dpf.filter_out_ext(files, ('.so',)) compile(files, versions, options.force, options.optimize, e_patterns) diff --git a/tests/t5/Makefile b/tests/t5/Makefile index d3be536e38b9124596a37cc0fc4e728ab38eed94..cde00619bc32154e238c89efbdc4d18231e9471c 100644 --- a/tests/t5/Makefile +++ b/tests/t5/Makefile @@ -19,12 +19,16 @@ check: grep -q "pyclean -p python-foo" debian/python-foo/DEBIAN/prerm # test pycompile DESTDIR=debian/python-foo/ ../../pycompile -v debian/python-foo/usr/lib/ - [ `ls debian/python-foo/usr/lib/python2.*/*-packages/remove_this_one/__init__.py | wc -l` != '0' ] - [ `ls debian/python-foo/usr/lib/python2.*/*-packages/remove_this_one/__init__.pyc | wc -l` != '0' ] + set -e; for i in remove_this_one bar bar/baz;\ + do [ `ls debian/python-foo/usr/lib/python2.*/*-packages/$$i/__init__.py | wc -l` != '0' ];\ + [ `ls debian/python-foo/usr/lib/python2.*/*-packages/$$i/__init__.pyc | wc -l` != '0' ];\ + done # test pyclean DESTDIR=debian/python-foo/ ../../pyclean -v debian/python-foo/usr/lib/ - [ `ls debian/python-foo/usr/lib/python2.*/*-packages/remove_this_one/__init__.py 2>/dev/null || true | wc -l` = 0 ] - [ `ls debian/python-foo/usr/lib/python2.*/*-packages/remove_this_one/__init__.pyc 2>/dev/null || true | wc -l` = 0 ] + set -e; for i in remove_this_one bar bar/baz;\ + do [ `ls debian/python-foo/usr/lib/python2.*/*-packages/$$i/__init__.py 2>/dev/null || true | wc -l` = 0 ];\ + [ `ls debian/python-foo/usr/lib/python2.*/*-packages/$$i/__init__.pyc 2>/dev/null || true | wc -l` = 0 ];\ + done clean: ./debian/rules clean diff --git a/tests/t5/debian/dirs b/tests/t5/debian/dirs index c3d23470f25cfd9404fd4267f74c2206f46b847e..b30451056589b5d76aecd95e924bb0ffef3cbff1 100644 --- a/tests/t5/debian/dirs +++ b/tests/t5/debian/dirs @@ -1,3 +1,4 @@ +/usr/share/pyshared/bar/baz /usr/share/pyshared/foo.egg-info /usr/share/pyshared/keep_this_one /usr/share/pyshared/remove_this_one diff --git a/tests/t5/debian/rules b/tests/t5/debian/rules index 4d0c029402607278d98228e8915f8cabebef9dd8..d6695f6895ab295921ede7fed34503dece1e67fb 100755 --- a/tests/t5/debian/rules +++ b/tests/t5/debian/rules @@ -9,11 +9,11 @@ override_dh_auto_install: cd debian/python-foo/usr/share/pyshared/;\ echo "keep_this_one\nremove_this_one" > foo.egg-info/namespace_packages.txt;\ echo "True" > keep_this_one/__init__.py;\ - touch remove_this_one/__init__.py remove_this_one/foo.py + touch remove_this_one/__init__.py remove_this_one/foo.py bar/baz/spam.py override_dh_pysupport: - DH_VERBOSE=1 ../../dh_python2 --namespace foo --namespace bar.baz + DH_VERBOSE=1 ../../dh_python2 --namespace foo --namespace bar.baz --namespace bar clean: dh_clean