From fb6ac28b44947c74600d09ff2231bc0d1987537d Mon Sep 17 00:00:00 2001 From: xutianming Date: Mon, 5 Nov 2018 05:53:55 +0800 Subject: [PATCH] single sourcing the package version (#3220) --- python/ray/__init__.py | 3 +-- python/setup.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/python/ray/__init__.py b/python/ray/__init__.py index 95255bba1..a507cdd2e 100644 --- a/python/ray/__init__.py +++ b/python/ray/__init__.py @@ -61,8 +61,7 @@ import ray.internal # noqa: E402 import ray.actor # noqa: F401 from ray.actor import method # noqa: E402 -# Ray version string. TODO(rkn): This is also defined separately in setup.py. -# Fix this. +# Ray version string. __version__ = "0.5.3" __all__ = [ diff --git a/python/setup.py b/python/setup.py index e55cc2529..bd0ef97a6 100644 --- a/python/setup.py +++ b/python/setup.py @@ -3,6 +3,7 @@ from __future__ import division from __future__ import print_function import os +import re import shutil import subprocess import sys @@ -118,10 +119,20 @@ class BinaryDistribution(Distribution): return True +def find_version(*filepath): + # Extract version information from filepath + here = os.path.abspath(os.path.dirname(__file__)) + with open(os.path.join(here, *filepath)) as fp: + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + fp.read(), re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + setup( name="ray", - # The version string is also in __init__.py. TODO(pcm): Fix this. - version="0.5.3", + version=find_version("ray", "__init__.py"), description=("A system for parallel and distributed Python that unifies " "the ML ecosystem."), long_description=open("../README.rst").read(),