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

translate Python version numbers into Debian ones for those

require.txt items that have a pydist file with (uscan like) rules
or PEP386 flag (Closes: #653740)
parent b8d09743
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ python-defaults (2.7.3-1) unstable; urgency=low ...@@ -13,6 +13,9 @@ python-defaults (2.7.3-1) unstable; urgency=low
(example: --shebang /usr/bin/python2.6) (example: --shebang /usr/bin/python2.6)
- no longer generates python2.X | python2.Y depenendies for public modules - no longer generates python2.X | python2.Y depenendies for public modules
(Closes: 625740) (Closes: 625740)
- translate Python version numbers into Debian ones for those
require.txt items that have a pydist file with (uscan like) rules
or PEP386 flag (Closes: #653740)
* pyversions, dh_python2, pycompile: allow to override system's list of * pyversions, dh_python2, pycompile: allow to override system's list of
supported Python versions via DEBPYTHON_SUPPORTED and default Python supported Python versions via DEBPYTHON_SUPPORTED and default Python
version via DEBPYTHON_DEFAULT env. variables version via DEBPYTHON_DEFAULT env. variables
......
...@@ -24,6 +24,7 @@ import logging ...@@ -24,6 +24,7 @@ import logging
import os import os
import re import re
from os.path import exists, isdir, join from os.path import exists, isdir, join
from string import maketrans
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from debpython.version import vrepr, getver, get_requested_versions from debpython.version import vrepr, getver, get_requested_versions
from debpython.tools import memoize from debpython.tools import memoize
...@@ -41,7 +42,7 @@ PYDIST_RE = re.compile(r""" ...@@ -41,7 +42,7 @@ PYDIST_RE = re.compile(r"""
;\s* ;\s*
(?P<standard>PEP386)? # PEP-386 mode (?P<standard>PEP386)? # PEP-386 mode
\s* \s*
(?P<rules>s/.*)? # translator rules (?P<rules>(?:s|tr|y).*)? # translator rules
)? )?
""", re.VERBOSE) """, re.VERBOSE)
REQUIRES_RE = re.compile(r''' REQUIRES_RE = re.compile(r'''
...@@ -117,13 +118,13 @@ def guess_dependency(req, version=None): ...@@ -117,13 +118,13 @@ def guess_dependency(req, version=None):
req = safe_name(name) + rest req = safe_name(name) + rest
data = load() data = load()
req_dict = REQUIRES_RE.match(req) req_d = REQUIRES_RE.match(req)
if not req_dict: if not req_d:
log.info('please ask dh_python2 author to fix REQUIRES_RE ' log.info('please ask dh_python2 author to fix REQUIRES_RE '
'or your upstream author to fix requires.txt') 'or your upstream author to fix requires.txt')
raise Exception('requirement is not valid: %s' % req) raise Exception('requirement is not valid: %s' % req)
req_dict = req_dict.groupdict() req_d = req_d.groupdict()
name = req_dict['name'] name = req_d['name']
details = data.get(name.lower()) details = data.get(name.lower())
if details: if details:
for item in details: for item in details:
...@@ -134,12 +135,13 @@ def guess_dependency(req, version=None): ...@@ -134,12 +135,13 @@ def guess_dependency(req, version=None):
if not item['dependency']: if not item['dependency']:
return # this requirement should be ignored return # this requirement should be ignored
if item['dependency'].endswith(')'): if item['dependency'].endswith(')'):
# no need to translate versions if version is hardcoded in Debian # no need to translate versions if version is hardcoded in
# dependency # Debian dependency
return item['dependency']
if req_dict['version']:
# FIXME: translate it (rules, versions)
return item['dependency'] return item['dependency']
if req_d['version'] and (item['standard'] or item['rules']) and\
req_d['operator'] not in (None, '=='):
v = _translate(req_d['version'], item['rules'], item['standard'])
return "%s (%s %s)" % (item['dependency'], req_d['operator'], v)
else: else:
return item['dependency'] return item['dependency']
...@@ -231,3 +233,53 @@ def sensible_pname(egg_name): ...@@ -231,3 +233,53 @@ def sensible_pname(egg_name):
def ci_regexp(name): def ci_regexp(name):
"""Return case insensitive dpkg -S regexp.""" """Return case insensitive dpkg -S regexp."""
return ''.join("[%s%s]" % (i.upper(), i) if i.isalpha() else i for i in name.lower()) return ''.join("[%s%s]" % (i.upper(), i) if i.isalpha() else i for i in name.lower())
PRE_VER_RE = re.compile(r'[-.]?(alpha|beta|rc|dev|a|b|c)')
GROUP_RE = re.compile(r'\$(\d+)')
def _pl2py(pattern):
"""Convert Perl RE patterns used in uscan to Python's
>>> print _pl2py('foo$3')
foo\g<3>
"""
return GROUP_RE.sub(r'\\g<\1>', pattern)
def _translate(version, rules, standard):
"""Translate Python version into Debian one.
>>> _translate('1.C2betac', ['s/c//gi'], None)
'1.2beta'
>>> _translate('5-fooa1.2beta3-fooD',
... ['s/^/1:/', 's/-foo//g', 's:([A-Z]):+$1:'], 'PEP386')
'1:5~a1.2~beta3+D'
>>> _translate('x.y.x.z', ['tr/xy/ab/', 'y,z,Z,'], None)
'a.b.a.Z'
"""
for rule in rules:
# uscan supports s, tr and y operations
if rule.startswith(('tr', 'y')):
# Note: no support for escaped separator in the pattern
pos = 1 if rule.startswith('y') else 2
tmp = rule[pos + 1:].split(rule[pos])
version = version.translate(maketrans(tmp[0], tmp[1]))
elif rule.startswith('s'):
# uscan supports: g, u and x flags
tmp = rule[2:].split(rule[1])
pattern = re.compile(tmp[0])
count = 1
if tmp[2:]:
flags = tmp[2]
if 'g' in flags:
count = 0
if 'i' in flags:
pattern = re.compile(tmp[0], re.I)
version = pattern.sub(_pl2py(tmp[1]), version, count)
else:
log.warn('unknown rule ignored: %s', rule)
if standard == 'PEP386':
version = PRE_VER_RE.sub('~\g<1>', version)
return version
...@@ -5,6 +5,7 @@ DPY=$(DEBPYTHON_DEFAULT) ...@@ -5,6 +5,7 @@ DPY=$(DEBPYTHON_DEFAULT)
check: check:
grep -q "Depends: .*python-mako" debian/python-foo/DEBIAN/control grep -q "Depends: .*python-mako" debian/python-foo/DEBIAN/control
grep -q 'python-foo (>= 2:0.1~rc2)' debian/python-foo/DEBIAN/control
test -f debian/python-foo/usr/lib/python2.6/dist-packages/foo/__init__.py test -f debian/python-foo/usr/lib/python2.6/dist-packages/foo/__init__.py
test ! -f debian/python-foo/usr/lib/python2.6/dist-packages/foo/spam.py test ! -f debian/python-foo/usr/lib/python2.6/dist-packages/foo/spam.py
grep -q "Depends: .*python (<<" debian/python-foo/DEBIAN/control grep -q "Depends: .*python (<<" debian/python-foo/DEBIAN/control
......
Mako python-mako (>= 0.2) Mako python-mako (>= 0.2)
SQLAlchemy python-sqlalchemy (>= 0.6) SQLAlchemy python-sqlalchemy (>= 0.6)
Foo python-foo Foo python-foo; PEP386 s/^/2:/
Bar python-bar Bar python-bar
Baz Baz
...@@ -12,5 +12,5 @@ override_dh_pysupport: ...@@ -12,5 +12,5 @@ override_dh_pysupport:
DH_VERBOSE=1 ../../dh_python2\ DH_VERBOSE=1 ../../dh_python2\
--depends 'SQLAlchemy >= 0.6.1'\ --depends 'SQLAlchemy >= 0.6.1'\
--recommends Mako\ --recommends Mako\
--suggests 'Foo >= 0.1'\ --suggests 'Foo >= 0.1rc2'\
--suggests 'bar >= 1.0' --suggests 'bar >= 1.0'
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