Source: scapy Version: 2.3.3-1 Severity: important Tags: patch Dear Maintainer,
while working on packaging software that depends on the scapy python module, I noticed that the version information in the Debian package is broken: $ python Python 2.7.13+ (default, Jul 19 2017, 18:15:03) [GCC 6.4.0 20170704] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import scapy >>> scapy.VERSION 'unknown.version' >>> The python-scapy pacakge contains a file /usr/lib/python2.7/dist-packages/scapy-unknown.version in which the "Version:" line also contains that string "unknown.version". Something is clearly wrong here. VERSION is initialized in scapy/__init__.py, from "git describe output" or from a VERSION file if that exists. If neither a git tag nor the VERSION file can be found, the version is set to "unknown.version". Upstream had a cute idea there, but this is not robust: - If I build the package from a git clone of the https://anonscm.debian.org/git/pkg-netmeasure/scapy.git, I get "debian/2.3.3-1" as the version string... - If I build in sbuild where no git metadata is available, I get "unknown.version" Please consider adding my patch which removes git-related code from scapy/__init__.py and creates the VERSION file from DEB_VERSION_UPSTREAM. Cheers, -Hilko
>From 0c78fd23b8df08dece45efca646bde2333fbea50 Mon Sep 17 00:00:00 2001 From: Hilko Bengen <[email protected]> Date: Sat, 12 Aug 2017 20:34:51 +0200 Subject: [PATCH] fix unreliable generation of scapy.VERSION at build time --- debian/patches/fix-version.patch | 70 ++++++++++++++++++++++++++++++++++++++++ debian/patches/series | 1 + debian/rules | 9 +++--- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 debian/patches/fix-version.patch diff --git a/debian/patches/fix-version.patch b/debian/patches/fix-version.patch new file mode 100644 index 0000000..ad528a1 --- /dev/null +++ b/debian/patches/fix-version.patch @@ -0,0 +1,70 @@ +Index: scapy/scapy/__init__.py +=================================================================== +--- scapy.orig/scapy/__init__.py ++++ scapy/scapy/__init__.py +@@ -19,61 +19,15 @@ import subprocess + + _SCAPY_PKG_DIR = os.path.dirname(__file__) + +-def _version_from_git_describe(): +- """ +- Read the version from ``git describe``. It returns the latest tag with an +- optional suffix if the current directory is not exactly on the tag. +- +- Example:: +- +- $ git describe --always +- v2.3.2-346-g164a52c075c8 +- +- The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are +- removed if present. +- +- If the current directory is not exactly on the tag, a ``.devN`` suffix is +- appended where N is the number of commits made after the last tag. +- +- Example:: +- +- >>> _version_from_git_describe() +- '2.3.2.dev346' +- """ +- p = subprocess.Popen(['git', 'describe', '--always'], cwd=_SCAPY_PKG_DIR, +- stdout=subprocess.PIPE, stderr=subprocess.PIPE) +- +- out, err = p.communicate() +- +- if p.returncode == 0: +- tag = out.strip() +- match = re.match(r'^v?(.+?)-(\d+)-g[a-f0-9]+$', tag) +- if match: +- # remove the 'v' prefix and add a '.devN' suffix +- return '%s.dev%s' % (match.group(1), match.group(2)) +- else: +- # just remove the 'v' prefix +- return re.sub(r'^v', '', tag) +- else: +- raise subprocess.CalledProcessError(p.returncode, err) +- + def _version(): + version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION') ++ # failed to read the tag from git, try to read it from a VERSION file + try: +- tag = _version_from_git_describe() +- # successfully read the tag from git, write it in VERSION for +- # installation and/or archive generation. +- with open(version_file, 'w') as f: +- f.write(tag) ++ with open(version_file, 'r') as f: ++ tag = f.read() + return tag + except: +- # failed to read the tag from git, try to read it from a VERSION file +- try: +- with open(version_file, 'r') as f: +- tag = f.read() +- return tag +- except: +- return 'unknown.version' ++ return 'unknown.version' + + VERSION = _version() + diff --git a/debian/patches/series b/debian/patches/series index 603979a..a2267d3 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,2 +1,3 @@ setup.py.patch paths.patch +fix-version.patch diff --git a/debian/rules b/debian/rules index f5b229b..43c38b9 100755 --- a/debian/rules +++ b/debian/rules @@ -2,15 +2,14 @@ #export DH_VERBOSE=1 -# include /usr/share/cdbs/1/rules/debhelper.mk -# include /usr/share/cdbs/1/class/python-distutils.mk -# include /usr/share/cdbs/1/rules/simple-patchsys.mk -# -# DEB_DH_INSTALL_SOURCEDIR := debian/tmp +include /usr/share/dpkg/pkg-info.mk %: dh $@ --with=python2 --with=quilt +override_dh_auto_configure: + echo $(DEB_VERSION_UPSTREAM) > scapy/VERSION + override_dh_auto_clean: dh_auto_clean -rm scapy/VERSION -- 2.14.1

