Returns the Scapy version from multiple methods :return: the Scapy version
()
| 130 | |
| 131 | |
| 132 | def _version(): |
| 133 | # type: () -> str |
| 134 | """Returns the Scapy version from multiple methods |
| 135 | |
| 136 | :return: the Scapy version |
| 137 | """ |
| 138 | # Method 0: from external packaging |
| 139 | try: |
| 140 | # possibly forced by external packaging |
| 141 | return os.environ['SCAPY_VERSION'] |
| 142 | except KeyError: |
| 143 | pass |
| 144 | |
| 145 | # Method 1: from the VERSION file, included in sdist and wheels |
| 146 | version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION') |
| 147 | try: |
| 148 | # file generated when running sdist |
| 149 | with open(version_file, 'r') as fdsec: |
| 150 | tag = fdsec.read() |
| 151 | return tag |
| 152 | except (FileNotFoundError, NotADirectoryError): |
| 153 | pass |
| 154 | |
| 155 | # Method 2: from the archive tag, exported when using git archives |
| 156 | try: |
| 157 | return _version_from_git_archive() |
| 158 | except ValueError: |
| 159 | pass |
| 160 | |
| 161 | # Method 3: from git itself, used when Scapy was cloned |
| 162 | try: |
| 163 | return _version_from_git_describe() |
| 164 | except Exception: |
| 165 | pass |
| 166 | |
| 167 | # Fallback |
| 168 | try: |
| 169 | # last resort, use the modification date of __init__.py |
| 170 | d = datetime.datetime.fromtimestamp( |
| 171 | os.path.getmtime(__file__), datetime.timezone.utc |
| 172 | ) |
| 173 | return d.strftime('%Y.%m.%d') |
| 174 | except Exception: |
| 175 | pass |
| 176 | |
| 177 | # all hope is lost |
| 178 | return '0.0.0' |
| 179 | |
| 180 | |
| 181 | VERSION = __version__ = _version() |
no test coverage detected