[Reproducible-builds] [dh-python] 18/183: add Interpreter.should_ignore method

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Sep 19 15:30:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository dh-python.

commit 81a5b891b11b3bbf7a8527ea886942296569741b
Author: Piotr Ożarowski <piotr at debian.org>
Date:   Sat Jun 29 23:53:49 2013 +0200

    add Interpreter.should_ignore method
---
 dh_python2              |  9 ++-------
 dh_python3              | 12 ++----------
 dhpython/__init__.py    |  7 ++++++-
 dhpython/interpreter.py | 13 ++++++++++++-
 4 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/dh_python2 b/dh_python2
index b45a755..566b9b2 100755
--- a/dh_python2
+++ b/dh_python2
@@ -277,13 +277,8 @@ def scan(package, dname=None, options=None):
         private_to_check = [dname]
 
     for root, dirs, file_names in os.walk(proot):
-        # ignore Python 3.X locations
-        if '/usr/lib/python3' in root or\
-           '/usr/local/lib/python3' in root:
-            # warn only once
-            if root[root.find('/lib/python'):].count('/') == 2:
-                log.warning('Python 3.x location detected, '
-                            'please use dh_python3: %s', root)
+        if interpreter.should_ignore(root):
+            del dirs[:]
             continue
 
         bin_dir = private_dir = None
diff --git a/dh_python3 b/dh_python3
index 9bea7de..fe2e578 100755
--- a/dh_python3
+++ b/dh_python3
@@ -75,16 +75,8 @@ def scan(package, dname=None, options=None):
         private_to_check = [dname]
 
     for root, dirs, file_names in os.walk(proot):
-        # ignore Python 2.X locations
-        if '/usr/lib/python2' in root or\
-           '/usr/local/lib/python2' in root or\
-           '/usr/share/pyshared/' in root or\
-           '/usr/lib/pyshared/' in root:
-            # warn only once
-            tmp = root.replace('/local', '').split('/')
-            if len(tmp) == 5:  # debian/package/usr/foo/bar
-                log.warning('Python 2.x location detected, '
-                            'please use dh_python2: %s', root)
+        if interpreter.should_ignore(root):
+            del dirs[:]
             continue
 
         bin_dir = private_dir = None
diff --git a/dhpython/__init__.py b/dhpython/__init__.py
index a4bce83..cd6bcf5 100644
--- a/dhpython/__init__.py
+++ b/dhpython/__init__.py
@@ -24,7 +24,7 @@ PKG_PREFIX_MAP = {'cpython2': 'python',
                   'cpython3': 'python3',
                   'pypy': 'pypy'}
 
-# minimum version required for py3compile/py3clean:
+# minimum version required for compile/clean scripts:
 MINPYCDEP = {'cpython2': 'python (>= 2.6.6-3)',
              'cpython3': 'python3 (>= 3.2.3-3~)',
              'pypy': 'pypy'}
@@ -34,6 +34,11 @@ PUBLIC_DIR_RE = {
     'cpython3': re.compile(r'.*?/usr/lib/python(3(?:\.\d+)?)/dist-packages'),
     'pypy': re.compile(r'.*?/usr/lib/pypy/dist-packages')}
 
+INTERPRETER_DIR_TPLS = {
+    'cpython2': r'.*/python2\.\d/',
+    'cpython3': r'.*/python3(?:\.\d+)?/',
+    'pypy': r'.*/pypy/'}
+
 # Interpreter site-directories
 OLD_SITE_DIRS = {
     'cpython2': [
diff --git a/dhpython/interpreter.py b/dhpython/interpreter.py
index 7d39d27..73c2a76 100644
--- a/dhpython/interpreter.py
+++ b/dhpython/interpreter.py
@@ -22,7 +22,7 @@ import logging
 import os
 import re
 from os.path import join, split
-from dhpython import OLD_SITE_DIRS, PUBLIC_DIR_RE
+from dhpython import INTERPRETER_DIR_TPLS, PUBLIC_DIR_RE, OLD_SITE_DIRS
 
 SHEBANG_RE = re.compile(r'''
     (?:\#!\s*){0,1}  # shebang prefix
@@ -263,6 +263,17 @@ class Interpreter:
         if match:
             return Version(match.groups(0))
 
+    def should_ignore(self, path):
+        """Return True if path is used by another interpreter implementation."""
+        cache_key = 'should_ignore_{}'.format(self.impl)
+        if cache_key not in self.__class__._cache:
+            expr = [v for k, v in INTERPRETER_DIR_TPLS.items() if k != self.impl]
+            regexp = re.compile('|'.join('({})'.format(i) for i in expr))
+            self.__class__._cache[cache_key] = regexp
+        else:
+            regexp = self.__class__._cache[cache_key]
+        return regexp.search(path)
+
     def cache_file(self, fpath, version=None):
         """Given path to a .py file, return path to its .pyc/.pyo file.
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dh-python.git



More information about the Reproducible-builds mailing list