We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
unknown.version in egg.info and in the banner
Hi,

I'm porting 2.3.3 to OpenBSD. I had two issues:
1. after the install with setuptools, the .egg-info generated is called 'lib/python2.7/site-packages/scapy-unknown.version-py2.7.egg-info'

I patched setup.py to hardcode the version then it worked
```
--- setup.py.orig       Tue Oct 18 10:44:43 2016
+++ setup.py    Mon Oct 31 17:19:45 2016
@@ -47,7 +47,7 @@ if os.name == "nt":
 
 setup(
     name='scapy',
-    version=__import__('scapy').VERSION,
+    version='2.3.3',
     packages=[
         'scapy',
         'scapy/arch',

```
I now have lib/python2.7/site-packages/scapy-2.3.3-py2.7.egg-info

2. running scapy it says "Welcome to Scapy (unknown.version)" even with the setup.py change. I went through scapy-2.3.3/scapy/main.py but I didn't find anything suspicious.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scapy/__init__.py`
Content:
```
1 ## This file is part of Scapy
2 ## See http://www.secdev.org/projects/scapy for more informations
3 ## Copyright (C) Philippe Biondi <phil@secdev.org>
4 ## This program is published under a GPLv2 license
5 
6 """
7 Scapy: create, send, sniff, dissect and manipulate network packets.
8 
9 Usable either from an interactive console or as a Python library.
10 http://www.secdev.org/projects/scapy
11 """
12 
13 import os
14 import re
15 import subprocess
16 
17 
18 _SCAPY_PKG_DIR = os.path.dirname(__file__)
19 
20 def _version_from_git_describe():
21     """
22     Read the version from ``git describe``. It returns the latest tag with an
23     optional suffix if the current directory is not exactly on the tag.
24 
25     Example::
26 
27         $ git describe --always
28         v2.3.2-346-g164a52c075c8
29 
30     The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are
31     removed if present.
32 
33     If the current directory is not exactly on the tag, a ``.devN`` suffix is
34     appended where N is the number of commits made after the last tag.
35 
36     Example::
37 
38         >>> _version_from_git_describe()
39         '2.3.2.dev346'
40     """
41     p = subprocess.Popen(['git', 'describe', '--always'], cwd=_SCAPY_PKG_DIR,
42                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43 
44     out, err = p.communicate()
45 
46     if p.returncode == 0:
47         tag = out.strip()
48         match = re.match(r'^v?(.+?)-(\d+)-g[a-f0-9]+$', tag)
49         if match:
50             # remove the 'v' prefix and add a '.devN' suffix
51             return '%s.dev%s' % (match.group(1), match.group(2))
52         else:
53             # just remove the 'v' prefix
54             return re.sub(r'^v', '', tag)
55     else:
56         raise subprocess.CalledProcessError(p.returncode, err)
57 
58 def _version():
59     version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION')
60     try:
61         tag = _version_from_git_describe()
62         # successfully read the tag from git, write it in VERSION for
63         # installation and/or archive generation.
64         with open(version_file, 'w') as f:
65             f.write(tag)
66         return tag
67     except:
68         # failed to read the tag from git, try to read it from a VERSION file
69         try:
70             with open(version_file, 'r') as f:
71                 tag = f.read()
72             return tag
73         except:
74             return 'unknown.version'
75 
76 VERSION = _version()
77 
78 if __name__ == "__main__":
79     from scapy.main import interact
80     interact()
81
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scapy/__init__.py b/scapy/__init__.py
--- a/scapy/__init__.py
+++ b/scapy/__init__.py
@@ -71,7 +71,17 @@
                 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()

{"golden_diff": "diff --git a/scapy/__init__.py b/scapy/__init__.py\n--- a/scapy/__init__.py\n+++ b/scapy/__init__.py\n@@ -71,7 +71,17 @@\n                 tag = f.read()\n             return tag\n         except:\n-            return 'unknown.version'\n+            # Rely on git archive \"export-subst\" git attribute.\n+            # See 'man gitattributes' for more details.\n+            git_archive_id = '$Format:%h %d$'\n+            sha1 = git_archive_id.strip().split()[0]\n+            match = re.search(r'tag:(\\S+)', git_archive_id)\n+            if match:\n+                return match.group(1)\n+            elif sha1:\n+                return sha1\n+            else:\n+                return 'unknown.version'\n \n VERSION = _version()\n", "issue": "unknown.version in egg.info and in the banner\nHi,\r\n\r\nI'm porting 2.3.3 to OpenBSD. I had two issues:\r\n1. after the install with setuptools, the .egg-info generated is called 'lib/python2.7/site-packages/scapy-unknown.version-py2.7.egg-info'\r\n\r\nI patched setup.py to hardcode the version then it worked\r\n```\r\n--- setup.py.orig       Tue Oct 18 10:44:43 2016\r\n+++ setup.py    Mon Oct 31 17:19:45 2016\r\n@@ -47,7 +47,7 @@ if os.name == \"nt\":\r\n \r\n setup(\r\n     name='scapy',\r\n-    version=__import__('scapy').VERSION,\r\n+    version='2.3.3',\r\n     packages=[\r\n         'scapy',\r\n         'scapy/arch',\r\n\r\n```\r\nI now have lib/python2.7/site-packages/scapy-2.3.3-py2.7.egg-info\r\n\r\n2. running scapy it says \"Welcome to Scapy (unknown.version)\" even with the setup.py change. I went through scapy-2.3.3/scapy/main.py but I didn't find anything suspicious.\n", "before_files": [{"content": "## This file is part of Scapy\n## See http://www.secdev.org/projects/scapy for more informations\n## Copyright (C) Philippe Biondi <phil@secdev.org>\n## This program is published under a GPLv2 license\n\n\"\"\"\nScapy: create, send, sniff, dissect and manipulate network packets.\n\nUsable either from an interactive console or as a Python library.\nhttp://www.secdev.org/projects/scapy\n\"\"\"\n\nimport os\nimport re\nimport subprocess\n\n\n_SCAPY_PKG_DIR = os.path.dirname(__file__)\n\ndef _version_from_git_describe():\n    \"\"\"\n    Read the version from ``git describe``. It returns the latest tag with an\n    optional suffix if the current directory is not exactly on the tag.\n\n    Example::\n\n        $ git describe --always\n        v2.3.2-346-g164a52c075c8\n\n    The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are\n    removed if present.\n\n    If the current directory is not exactly on the tag, a ``.devN`` suffix is\n    appended where N is the number of commits made after the last tag.\n\n    Example::\n\n        >>> _version_from_git_describe()\n        '2.3.2.dev346'\n    \"\"\"\n    p = subprocess.Popen(['git', 'describe', '--always'], cwd=_SCAPY_PKG_DIR,\n                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    out, err = p.communicate()\n\n    if p.returncode == 0:\n        tag = out.strip()\n        match = re.match(r'^v?(.+?)-(\\d+)-g[a-f0-9]+$', tag)\n        if match:\n            # remove the 'v' prefix and add a '.devN' suffix\n            return '%s.dev%s' % (match.group(1), match.group(2))\n        else:\n            # just remove the 'v' prefix\n            return re.sub(r'^v', '', tag)\n    else:\n        raise subprocess.CalledProcessError(p.returncode, err)\n\ndef _version():\n    version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION')\n    try:\n        tag = _version_from_git_describe()\n        # successfully read the tag from git, write it in VERSION for\n        # installation and/or archive generation.\n        with open(version_file, 'w') as f:\n            f.write(tag)\n        return tag\n    except:\n        # failed to read the tag from git, try to read it from a VERSION file\n        try:\n            with open(version_file, 'r') as f:\n                tag = f.read()\n            return tag\n        except:\n            return 'unknown.version'\n\nVERSION = _version()\n\nif __name__ == \"__main__\":\n    from scapy.main import interact\n    interact()\n", "path": "scapy/__init__.py"}], "after_files": [{"content": "## This file is part of Scapy\n## See http://www.secdev.org/projects/scapy for more informations\n## Copyright (C) Philippe Biondi <phil@secdev.org>\n## This program is published under a GPLv2 license\n\n\"\"\"\nScapy: create, send, sniff, dissect and manipulate network packets.\n\nUsable either from an interactive console or as a Python library.\nhttp://www.secdev.org/projects/scapy\n\"\"\"\n\nimport os\nimport re\nimport subprocess\n\n\n_SCAPY_PKG_DIR = os.path.dirname(__file__)\n\ndef _version_from_git_describe():\n    \"\"\"\n    Read the version from ``git describe``. It returns the latest tag with an\n    optional suffix if the current directory is not exactly on the tag.\n\n    Example::\n\n        $ git describe --always\n        v2.3.2-346-g164a52c075c8\n\n    The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are\n    removed if present.\n\n    If the current directory is not exactly on the tag, a ``.devN`` suffix is\n    appended where N is the number of commits made after the last tag.\n\n    Example::\n\n        >>> _version_from_git_describe()\n        '2.3.2.dev346'\n    \"\"\"\n    p = subprocess.Popen(['git', 'describe', '--always'], cwd=_SCAPY_PKG_DIR,\n                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    out, err = p.communicate()\n\n    if p.returncode == 0:\n        tag = out.strip()\n        match = re.match(r'^v?(.+?)-(\\d+)-g[a-f0-9]+$', tag)\n        if match:\n            # remove the 'v' prefix and add a '.devN' suffix\n            return '%s.dev%s' % (match.group(1), match.group(2))\n        else:\n            # just remove the 'v' prefix\n            return re.sub(r'^v', '', tag)\n    else:\n        raise subprocess.CalledProcessError(p.returncode, err)\n\ndef _version():\n    version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION')\n    try:\n        tag = _version_from_git_describe()\n        # successfully read the tag from git, write it in VERSION for\n        # installation and/or archive generation.\n        with open(version_file, 'w') as f:\n            f.write(tag)\n        return tag\n    except:\n        # failed to read the tag from git, try to read it from a VERSION file\n        try:\n            with open(version_file, 'r') as f:\n                tag = f.read()\n            return tag\n        except:\n            # Rely on git archive \"export-subst\" git attribute.\n            # See 'man gitattributes' for more details.\n            git_archive_id = '$Format:%h %d$'\n            sha1 = git_archive_id.strip().split()[0]\n            match = re.search(r'tag:(\\S+)', git_archive_id)\n            if match:\n                return match.group(1)\n            elif sha1:\n                return sha1\n            else:\n                return 'unknown.version'\n\nVERSION = _version()\n\nif __name__ == \"__main__\":\n    from scapy.main import interact\n    interact()\n", "path": "scapy/__init__.py"}]}