From d2c8b2777d41adb0a8c52becca70b8dc8c40e2dd Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 11 Aug 2015 10:38:20 +0100 Subject: [setup.py] retrieve version string from brotlimodule.cc so we don't need to modify it more than once --- setup.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 8181205..9df1135 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,12 @@ from distutils.core import setup, Extension from distutils.command.build_ext import build_ext from distutils.cmd import Command import platform +import os +import re +CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) + # when compiling for Windows Python 2.7, force distutils to use Visual Studio # 2010 instead of 2008, as the latter doesn't support c++0x if platform.system() == 'Windows': @@ -19,6 +23,17 @@ if platform.system() == 'Windows': distutils.msvc9compiler.find_vcvarsall = patched_find_vcvarsall +def get_version(): + """ Return BROTLI_VERSION string as defined in 'brotlimodule.cc' file. """ + brotlimodule = os.path.join(CURR_DIR, 'python', 'brotlimodule.cc') + with open(brotlimodule, 'r') as f: + for line in f: + m = re.match(r'#define\sBROTLI_VERSION\s"(.*)"', line) + if m: + return m.group(1) + return "" + + class TestCommand(Command): """ Run all *_test.py scripts in 'tests' folder with the same Python interpreter used to run setup.py. @@ -33,10 +48,9 @@ class TestCommand(Command): pass def run(self): - import sys, os, subprocess, glob + import sys, subprocess, glob - curr_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) - test_dir = os.path.join(curr_dir, 'python', 'tests') + test_dir = os.path.join(CURR_DIR, 'python', 'tests') os.chdir(test_dir) for test in glob.glob("*_test.py"): @@ -177,7 +191,7 @@ brotli = Extension("brotli", setup( name="Brotli", - version="0.1", + version=get_version(), url="https://github.com/google/brotli", description="Python binding of the Brotli compression library", author="Khaled Hosny", -- cgit v1.1