Skip to content

Commit a147633

Browse files
committed
use setuptools_scm to resolve coordinator version
1 parent 341fba7 commit a147633

File tree

5 files changed

+92
-16
lines changed

5 files changed

+92
-16
lines changed

coordinator/gscoordinator/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
19+
from gscoordinator.version import __version__

coordinator/gscoordinator/coordinator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
# capture system stdout
4343
sys.stdout = StdoutWrapper(sys.stdout)
4444

45-
from graphscope import __version__
4645
from graphscope.proto import attr_value_pb2
4746
from graphscope.proto import coordinator_service_pb2_grpc
4847
from graphscope.proto import engine_service_pb2_grpc
@@ -65,6 +64,7 @@
6564
from gscoordinator.utils import generate_graph_type_sig
6665
from gscoordinator.utils import str2bool
6766
from gscoordinator.utils import to_maxgraph_schema
67+
from gscoordinator.version import __version__
6868

6969
COORDINATOR_HOME = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7070
GRAPHSCOPE_HOME = os.path.join(COORDINATOR_HOME, "..")

coordinator/gscoordinator/version.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
import os
19+
20+
version_file_path = os.path.join(
21+
os.path.dirname(os.path.abspath(__file__)), "..", "..", "VERSION"
22+
)
23+
24+
if os.path.isfile(version_file_path):
25+
with open(version_file_path, "r", encoding="utf-8") as fp:
26+
__version__ = fp.read().strip()
27+
__version_tuple__ = (int(v) for v in __version__.split("."))
28+
else:
29+
__version__ = "0.1.0"
30+
__version_tuple__ = (0, 1, 0)
31+
32+
del version_file_path

coordinator/setup.py

+57-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@
2828
from setuptools.command.develop import develop
2929
from setuptools.command.sdist import sdist
3030

31-
32-
def execfile(fname):
33-
with open(fname) as f:
34-
return f.readline().rstrip()
35-
36-
3731
repo_root = os.path.dirname(os.path.abspath(__file__))
38-
version_file_path = os.path.join(repo_root, "../VERSION")
39-
version = execfile(version_file_path)
4032

4133

4234
class BuildBuiltin(Command):
@@ -146,9 +138,58 @@ def parsed_dev_reqs():
146138
return fp.read().splitlines()
147139

148140

141+
def parse_version(root, **kwargs):
142+
"""
143+
Parse function for setuptools_scm that first tries to read '../VERSION' file
144+
to get a version number.
145+
"""
146+
from setuptools_scm.git import parse
147+
from setuptools_scm.version import meta
148+
149+
version_file = os.path.join(repo_root, "..", "VERSION")
150+
if os.path.isfile(version_file):
151+
with open(version_file, "r", encoding="utf-8") as fp:
152+
return meta(fp.read().strip())
153+
return parse(root, **kwargs)
154+
155+
156+
version_template = """#!/usr/bin/env python3
157+
# -*- coding: utf-8 -*-
158+
#
159+
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
160+
#
161+
# Licensed under the Apache License, Version 2.0 (the "License");
162+
# you may not use this file except in compliance with the License.
163+
# You may obtain a copy of the License at
164+
#
165+
# http://www.apache.org/licenses/LICENSE-2.0
166+
#
167+
# Unless required by applicable law or agreed to in writing, software
168+
# distributed under the License is distributed on an "AS IS" BASIS,
169+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170+
# See the License for the specific language governing permissions and
171+
# limitations under the License.
172+
173+
import os
174+
175+
version_file_path = os.path.join(
176+
os.path.dirname(os.path.abspath(__file__)), "..", "..", "VERSION"
177+
)
178+
179+
if os.path.isfile(version_file_path):
180+
with open(version_file_path, "r", encoding="utf-8") as fp:
181+
__version__ = fp.read().strip()
182+
__version_tuple__ = (int(v) for v in __version__.split("."))
183+
else:
184+
__version__ = "{version}"
185+
__version_tuple__ = {version_tuple}
186+
187+
del version_file_path
188+
"""
189+
190+
149191
setup(
150192
name="gscoordinator",
151-
version=version,
152193
description="",
153194
long_description=long_description,
154195
long_description_content_type="text/markdown",
@@ -172,6 +213,13 @@ def parsed_dev_reqs():
172213
"Programming Language :: Python :: 3.9",
173214
],
174215
keywords="GRAPE, Graph Computations",
216+
use_scm_version={
217+
"root": repo_root,
218+
"parse": parse_version,
219+
"write_to": os.path.join(repo_root, "gscoordinator/version.py"),
220+
"write_to_template": version_template,
221+
},
222+
setup_requires=["setuptools_scm", "grpcio", "grpcio-tools"],
175223
package_dir={".": "."},
176224
packages=find_packages("."),
177225
package_data={

python/setup.py

-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
from setuptools.command.sdist import sdist
3030
from wheel.bdist_wheel import bdist_wheel
3131

32-
33-
def execfile(fname):
34-
with open(fname) as f:
35-
return f.readline().rstrip()
36-
37-
3832
repo_root = os.path.dirname(os.path.abspath(__file__))
3933

4034

0 commit comments

Comments
 (0)