From 9d6409e75ca4eaf06154f360256a9b0c38a6fa8d Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 2 Nov 2016 10:38:29 +0100 Subject: [PATCH] fix version when installing from git archive When installing from a git archive downloaded from github, the file scapy/VERSION is not present since it is generated when building a source archive with: ./setup.py sdist To work around the problem, use the export-subst git attribute to make git archive write the current revison information in scapy/__init__.py. Signed-off-by: Robin Jarry --- .gitattributes | 1 + scapy/__init__.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..0c210b4e7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +scapy/__init__.py export-subst diff --git a/scapy/__init__.py b/scapy/__init__.py index 871df95cb..b3bb3d0d5 100644 --- a/scapy/__init__.py +++ b/scapy/__init__.py @@ -71,7 +71,17 @@ def _version(): tag = f.read() return tag except: - return 'unknown.version' + # Rely on git archive "export-subst" git attribute. + # See 'man gitattributes' for more details. + git_archive_id = '$Format:%h %d$' + sha1 = git_archive_id.strip().split()[0] + match = re.search(r'tag:(\S+)', git_archive_id) + if match: + return match.group(1) + elif sha1: + return sha1 + else: + return 'unknown.version' VERSION = _version()