MCPcopy Create free account
hub / github.com/secdev/scapy / _version_from_git_describe

Function _version_from_git_describe

scapy/__init__.py:82–129  ·  view source on GitHub ↗

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 (``-g164a52c075c

()

Source from the content-addressed store, hash-verified

80
81
82def _version_from_git_describe():
83 # type: () -> str
84 """
85 Read the version from ``git describe``. It returns the latest tag with an
86 optional suffix if the current directory is not exactly on the tag.
87
88 Example::
89
90 $ git describe --always
91 v2.3.2-346-g164a52c075c8
92
93 The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are
94 removed if present.
95
96 If the current directory is not exactly on the tag, a ``.devN`` suffix is
97 appended where N is the number of commits made after the last tag.
98
99 Example::
100
101 >>> _version_from_git_describe()
102 '2.3.2.dev346'
103
104 :raises CalledProcessError: if git is unavailable
105 :return: Scapy's latest tag
106 """
107 if not os.path.isdir(os.path.join(os.path.dirname(_SCAPY_PKG_DIR), '.git')): # noqa: E501
108 raise ValueError('not in scapy git repo')
109
110 def _git(cmd):
111 # type: (str) -> str
112 process = subprocess.Popen(
113 cmd.split(),
114 cwd=_SCAPY_PKG_DIR,
115 stdout=subprocess.PIPE,
116 stderr=subprocess.PIPE
117 )
118 out, err = process.communicate()
119 if process.returncode == 0:
120 return out.decode().strip()
121 else:
122 raise subprocess.CalledProcessError(process.returncode, err)
123
124 tag = _git("git describe --tags --always --long")
125 if not tag.startswith("v"):
126 # Upstream was not fetched
127 commit = _git("git rev-list --tags --max-count=1")
128 tag = _git("git describe --tags --always --long %s" % commit)
129 return _parse_tag(tag)
130
131
132def _version():

Callers 1

_versionFunction · 0.85

Calls 3

_gitFunction · 0.85
_parse_tagFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…