Skip to content
Snippets Groups Projects
Commit 4c090bcb authored by Piotr Ożarowski's avatar Piotr Ożarowski
Browse files

add_namespace_files: make sure directories without any file get __init__.py files as well

parent a0b54dbb
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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:
......
......@@ -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)
......
......@@ -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
/usr/share/pyshared/bar/baz
/usr/share/pyshared/foo.egg-info
/usr/share/pyshared/keep_this_one
/usr/share/pyshared/remove_this_one
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment