aboutsummaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorCosimo Lupo <cosimo.lupo@daltonmaag.com>2015-08-11 10:38:20 +0100
committerCosimo Lupo <cosimo.lupo@daltonmaag.com>2015-08-11 11:12:58 +0100
commitd2c8b2777d41adb0a8c52becca70b8dc8c40e2dd (patch)
tree00ba71aa714ac543b9f3c09de1a7d9fccdd336f1 /setup.py
parent8c7edd3e07b46634361f47fce220ed8c5a9be8aa (diff)
downloadbrotli-d2c8b2777d41adb0a8c52becca70b8dc8c40e2dd.zip
brotli-d2c8b2777d41adb0a8c52becca70b8dc8c40e2dd.tar.gz
brotli-d2c8b2777d41adb0a8c52becca70b8dc8c40e2dd.tar.bz2
[setup.py] retrieve version string from brotlimodule.cc so we don't need to modify it more than once
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py22
1 files changed, 18 insertions, 4 deletions
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",