Merge pull request #373 from 6WIND/gitarchive-version

fix version when installing from git archive
This commit is contained in:
Pierre Lalet 2016-12-15 08:36:47 +00:00 committed by GitHub
commit 97326605cf
2 changed files with 12 additions and 1 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
scapy/__init__.py export-subst

View File

@ -71,6 +71,16 @@ def _version():
tag = f.read() tag = f.read()
return tag return tag
except: except:
# 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' return 'unknown.version'
VERSION = _version() VERSION = _version()