From 5bff2ec35e2133fdb8487541d032d70d43846e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20O=C5=BCarowski?= <piotr@debian.org> Date: Wed, 6 Jul 2011 19:47:09 +0200 Subject: [PATCH] "--namespace foo" no longer triggers .../dist-packages/bar/foo/__init__.py creation, use "--namespace bar.foo" instead --- debian/changelog | 2 ++ debpython/namespace.py | 32 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/debian/changelog b/debian/changelog index 9d4e056..7fddaea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -29,6 +29,8 @@ python-defaults (2.7.2-2) UNRELEASED; urgency=low python:Breaks - closes: 631397, describes .pyinstall and .pyremove files) - remove setuptools from requires.txt (it is replaced with python-pkg-resources Debian dependency) + - "--namespace foo" no longer triggers .../dist-packages/bar/foo/__init__.py + creation, use "--namespace bar.foo" instead -- Piotr Ożarowski <piotr@debian.org> Sun, 12 Jun 2011 13:28:48 +0200 diff --git a/debpython/namespace.py b/debpython/namespace.py index 1aa795c..ecee720 100644 --- a/debpython/namespace.py +++ b/debpython/namespace.py @@ -71,7 +71,7 @@ def load(package=None): def add_namespace_files(files, package=None, action=None): """Add __init__.py files to given generator.""" if action is not None: - namespaces = set("/%s" % i for i in load(package)) + namespaces = load(package) already_processed = set() removal_candidates = set() for fn in files: @@ -81,21 +81,23 @@ def add_namespace_files(files, package=None, action=None): dpath = dirname(fn) if dpath not in already_processed: already_processed.add(dpath) - if PUBLIC_DIR_RE.match(dpath): - while not dpath.endswith(('site-packages', 'dist-packages')): - for ns in namespaces: + m = PUBLIC_DIR_RE.match(dpath) + if m: + public_dir = m.group() + while dpath != public_dir: + ns_dir = dpath[len(public_dir) + 1:] + if ns_dir 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) + 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] -- GitLab