Uh oh!
There was an error while loading. Please reload this page.
forked from CESNET/libyang-python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
executable file
·171 lines (145 loc) · 5.68 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·171 lines (145 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
# Copyright (c) 2018-2020 Robin Jarry
# SPDX-License-Identifier: MIT
importdatetime
importos
importre
importsubprocess
importsetuptools
importsetuptools.command.sdist
# -------------------------------------------------------------------------------------
ifos.environ.get("LIBYANG_INSTALL", "system") =="embed":
raiseNotImplementedError(
"LIBYANG_INSTALL=embed is no longer supported. "
"Please install libyang separately first."
)
# -------------------------------------------------------------------------------------
defgit_describe_to_pep440(version):
"""
``git describe`` produces versions in the form: `v0.9.8-20-gf0f45ca` where
20 is the number of commit since last release, and gf0f45ca is the short
commit id preceded by 'g' we parse this a transform into a pep440 release
version 0.9.9.dev20 (increment last digit and add dev before 20)
"""
match=re.search(
r"""
v(?P<major>\d+)\.
(?P<minor>\d+)\.
(?P<patch>\d+)
((\.post|-)(?P<post>\d+)(?!-g))?
([\+~](?P<local_segment>.*?))?
(-(?P<dev>\d+))?(-g(?P<commit>.+))?
""",
version,
flags=re.VERBOSE,
)
ifnotmatch:
raiseValueError("unknown tag format")
dic= {
"major": int(match.group("major")),
"minor": int(match.group("minor")),
"patch": int(match.group("patch")),
}
fmt="{major}.{minor}.{patch}"
ifmatch.group("dev"):
dic["patch"] +=1
dic["dev"] =int(match.group("dev"))
fmt+=".dev{dev}"
elifmatch.group("post"):
dic["post"] =int(match.group("post"))
fmt+=".post{post}"
ifmatch.group("local_segment"):
dic["local_segment"] =match.group("local_segment")
fmt+="+{local_segment}"
returnfmt.format(**dic)
# -------------------------------------------------------------------------------------
defget_version_from_archive_id(git_archive_id="$Format:%ct %d$"):
"""
Extract the tag if a source is from git archive.
When source is exported via `git archive`, the git_archive_id init value is
modified and placeholders are expanded to the "archived" revision:
%ct: committer date, UNIX timestamp
%d: ref names, like the --decorate option of git-log
See man gitattributes(5) and git-log(1) (PRETTY FORMATS) for more details.
"""
# mangle the magic string to make sure it is not replaced by git archive
ifgit_archive_id.startswith("$For""mat:"): # pylint: disable=implicit-str-concat
raiseValueError("source was not modified by git archive")
# source was modified by git archive, try to parse the version from
# the value of git_archive_id
match=re.search(r"tag:\s*([^,)]+)", git_archive_id)
ifmatch:
# archived revision is tagged, use the tag
returngit_describe_to_pep440(match.group(1))
# archived revision is not tagged, use the commit date
tstamp=git_archive_id.strip().split()[0]
d=datetime.datetime.utcfromtimestamp(int(tstamp))
returnd.strftime("2.%Y.%m.%d")
# -------------------------------------------------------------------------------------
defread_file(fpath, encoding="utf-8"):
withopen(fpath, "r", encoding=encoding) asf:
returnf.read().strip()
# -------------------------------------------------------------------------------------
defget_version():
try:
returnread_file("libyang/VERSION")
exceptIOError:
pass
if"LIBYANG_PYTHON_FORCE_VERSION"inos.environ:
returnos.environ["LIBYANG_PYTHON_FORCE_VERSION"]
try:
returnget_version_from_archive_id()
exceptValueError:
pass
try:
ifos.path.isdir(".git"):
out=subprocess.check_output(
["git", "describe", "--tags", "--always"], stderr=subprocess.DEVNULL
)
returngit_describe_to_pep440(out.decode("utf-8").strip())
exceptException:
pass
return"2.99999.99999"
# -------------------------------------------------------------------------------------
classSDistCommand(setuptools.command.sdist.sdist):
defwrite_lines(self, file, lines):
withopen(file, "w", encoding="utf-8") asf:
forlineinlines:
f.write(line+"\n")
defmake_release_tree(self, base_dir, files):
super().make_release_tree(base_dir, files)
version_file=os.path.join(base_dir, "libyang/VERSION")
self.execute(
self.write_lines,
(version_file, [self.distribution.metadata.version]),
"Writing %s"%version_file,
)
# -------------------------------------------------------------------------------------
setuptools.setup(
name="libyang",
version=get_version(),
description="CFFI bindings to libyang",
long_description=read_file("README.rst"),
url="https://github.com/CESNET/libyang-python",
license="MIT",
author="Robin Jarry",
author_email="robin@jarry.cc",
keywords=["libyang", "cffi"],
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries",
],
packages=["libyang"],
zip_safe=False,
include_package_data=True,
python_requires=">=3.6",
setup_requires=["setuptools", 'cffi; platform_python_implementation != "PyPy"'],
install_requires=['cffi; platform_python_implementation != "PyPy"'],
cffi_modules=["cffi/build.py:BUILDER"],
cmdclass={"sdist": SDistCommand},
)