11#!/usr/bin/env python
22import os
3+ import re
34import platform
45import sys
56from setuptools import find_packages , setup
67from setuptools .command .build_ext import build_ext
78
9+ base_dir = os .path .dirname (os .path .abspath (__file__ ))
810long_description = (
911 open ("README.rst" ).read () + '\n \n ' + open ("HISTORY.rst" ).read ()
1012)
1113
14+ with open (os .path .join (base_dir , "src" , "brotlicffi" , "__init__.py" )) as f :
15+ __version__ = re .search (r"__version__ = \"([^\"]+)\"" , f .read ()).group (1 )
16+
17+
1218class BuildClibBeforeExt (build_ext ):
1319 """ Setuptools `develop` command (used by `pip install -e .`) only calls
1420 `build_ext`, unlike `install` which calls `build` and all its related
@@ -21,44 +27,43 @@ class BuildClibBeforeExt(build_ext):
2127 https://github.com/pypa/pip/issues/4523
2228 """
2329
30+ def get_source_files (self ):
31+ filenames = build_ext .get_source_files (self )
32+ filenames .extend (depends )
33+ return filenames
34+
2435 def run (self ):
2536 self .run_command ("build_clib" )
2637 build_ext .run (self )
2738
39+
40+ depends = []
2841libraries = []
2942USE_SHARED_BROTLI = os .environ .get ("USE_SHARED_BROTLI" )
3043if USE_SHARED_BROTLI != "1" :
44+ sources = []
45+
46+ for root , _ , filenames in os .walk ("libbrotli/c" ):
47+ root_parts = os .path .split (root )
48+ if "fuzz" in root_parts or "tools" in root_parts :
49+ continue
50+ for filename in filenames :
51+ relpath = os .path .relpath (os .path .join (root , filename ), base_dir )
52+ if filename .endswith (".h" ):
53+ depends .append (relpath )
54+ elif filename .endswith (".c" ):
55+ sources .append (relpath )
56+
3157 libraries = [
3258 ("libbrotli" , {
3359 "include_dirs" : [
34- "libbrotli/include" ,
35- "libbrotli/" ,
60+ "libbrotli/c/include" ,
61+ "libbrotli/c/common" ,
62+ "libbrotli/c" ,
3663 "src/brotlicffi"
3764 ],
38- "sources" : [
39- 'libbrotli/common/dictionary.c' ,
40- 'libbrotli/dec/huffman.c' ,
41- 'libbrotli/dec/bit_reader.c' ,
42- 'libbrotli/dec/decode.c' ,
43- 'libbrotli/dec/state.c' ,
44- 'libbrotli/enc/backward_references.c' ,
45- 'libbrotli/enc/backward_references_hq.c' ,
46- 'libbrotli/enc/bit_cost.c' ,
47- 'libbrotli/enc/block_splitter.c' ,
48- 'libbrotli/enc/histogram.c' ,
49- 'libbrotli/enc/memory.c' ,
50- 'libbrotli/enc/literal_cost.c' ,
51- 'libbrotli/enc/brotli_bit_stream.c' ,
52- 'libbrotli/enc/compress_fragment_two_pass.c' ,
53- 'libbrotli/enc/compress_fragment.c' ,
54- 'libbrotli/enc/cluster.c' ,
55- 'libbrotli/enc/utf8_util.c' ,
56- 'libbrotli/enc/encode.c' ,
57- 'libbrotli/enc/metablock.c' ,
58- 'libbrotli/enc/static_dict.c' ,
59- 'libbrotli/enc/dictionary_hash.c' ,
60- 'libbrotli/enc/entropy_encode.c'
61- ]
65+ "depends" : depends ,
66+ "sources" : sources ,
6267 }),
6368 ]
6469
@@ -77,7 +82,7 @@ def finalize_options(self):
7782
7883setup (
7984 name = "brotlicffi" ,
80- version = "0.8.0" ,
85+ version = __version__ ,
8186
8287 description = "Python CFFI bindings to the Brotli library" ,
8388 long_description = long_description ,
0 commit comments