mirror of
https://github.com/google/brotli.git
synced 2024-11-29 06:31:06 +00:00
Merge pull request #435 from nicksay/py-1-cleanup-setup
Python: Clean up setup.py file
This commit is contained in:
commit
541dd651e0
262
setup.py
262
setup.py
@ -1,14 +1,19 @@
|
|||||||
|
# Copyright 2015 The Brotli Authors. All rights reserved.
|
||||||
|
#
|
||||||
|
# Distributed under MIT license.
|
||||||
|
# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import re
|
||||||
try:
|
try:
|
||||||
import setuptools
|
from setuptools import Extension
|
||||||
|
from setuptools import setup
|
||||||
except:
|
except:
|
||||||
pass
|
from distutils.core import Extension
|
||||||
import distutils
|
from distutils.core import setup
|
||||||
from distutils.core import setup, Extension
|
|
||||||
from distutils.command.build_ext import build_ext
|
from distutils.command.build_ext import build_ext
|
||||||
from distutils.cmd import Command
|
from distutils.cmd import Command
|
||||||
import platform
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
||||||
@ -16,16 +21,20 @@ CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
|||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
""" Return BROTLI_VERSION string as defined in 'common/version.h' file. """
|
""" Return BROTLI_VERSION string as defined in 'common/version.h' file. """
|
||||||
brotlimodule = os.path.join(CURR_DIR, 'common', 'version.h')
|
version_file_path = os.path.join(CURR_DIR, 'common', 'version.h')
|
||||||
version = 0
|
version = 0
|
||||||
with open(brotlimodule, 'r') as f:
|
with open(version_file_path, 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
m = re.match(r'#define\sBROTLI_VERSION\s+0x([0-9a-fA-F]+)', line)
|
m = re.match(r'#define\sBROTLI_VERSION\s+0x([0-9a-fA-F]+)', line)
|
||||||
if m:
|
if m:
|
||||||
version = int(m.group(1), 16)
|
version = int(m.group(1), 16)
|
||||||
if version == 0:
|
if version == 0:
|
||||||
return ""
|
return ''
|
||||||
return "{0}.{1}.{2}".format(version >> 24, (version >> 12) & 0xFFF, version & 0xFFF)
|
# Semantic version is calculated as (MAJOR << 24) | (MINOR << 12) | PATCH.
|
||||||
|
major = version >> 24
|
||||||
|
minor = (version >> 12) & 0xFFF
|
||||||
|
patch = version & 0xFFF
|
||||||
|
return '{0}.{1}.{2}'.format(major, minor, patch)
|
||||||
|
|
||||||
|
|
||||||
class TestCommand(Command):
|
class TestCommand(Command):
|
||||||
@ -47,7 +56,7 @@ class TestCommand(Command):
|
|||||||
test_dir = os.path.join(CURR_DIR, 'python', 'tests')
|
test_dir = os.path.join(CURR_DIR, 'python', 'tests')
|
||||||
os.chdir(test_dir)
|
os.chdir(test_dir)
|
||||||
|
|
||||||
for test in glob.glob("*_test.py"):
|
for test in glob.glob('*_test.py'):
|
||||||
try:
|
try:
|
||||||
subprocess.check_call([sys.executable, test])
|
subprocess.check_call([sys.executable, test])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
@ -55,6 +64,7 @@ class TestCommand(Command):
|
|||||||
|
|
||||||
|
|
||||||
class BuildExt(build_ext):
|
class BuildExt(build_ext):
|
||||||
|
|
||||||
def get_source_files(self):
|
def get_source_files(self):
|
||||||
filenames = build_ext.get_source_files(self)
|
filenames = build_ext.get_source_files(self)
|
||||||
for ext in self.extensions:
|
for ext in self.extensions:
|
||||||
@ -65,30 +75,31 @@ class BuildExt(build_ext):
|
|||||||
c_sources = []
|
c_sources = []
|
||||||
cxx_sources = []
|
cxx_sources = []
|
||||||
for source in ext.sources:
|
for source in ext.sources:
|
||||||
if source.endswith(".c"):
|
if source.endswith('.c'):
|
||||||
c_sources.append(source)
|
c_sources.append(source)
|
||||||
else:
|
else:
|
||||||
cxx_sources.append(source)
|
cxx_sources.append(source)
|
||||||
extra_args = ext.extra_compile_args or []
|
extra_args = ext.extra_compile_args or []
|
||||||
|
|
||||||
objects = []
|
objects = []
|
||||||
for lang, sources in (("c", c_sources), ("c++", cxx_sources)):
|
for lang, sources in (('c', c_sources), ('c++', cxx_sources)):
|
||||||
if lang == "c++":
|
if lang == 'c++':
|
||||||
if self.compiler.compiler_type == "msvc":
|
if self.compiler.compiler_type == 'msvc':
|
||||||
extra_args.append("/EHsc")
|
extra_args.append('/EHsc')
|
||||||
|
|
||||||
macros = ext.define_macros[:]
|
macros = ext.define_macros[:]
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == 'Darwin':
|
||||||
macros.append(("OS_MACOSX", "1"))
|
macros.append(('OS_MACOSX', '1'))
|
||||||
elif self.compiler.compiler_type == "mingw32":
|
elif self.compiler.compiler_type == 'mingw32':
|
||||||
# On Windows Python 2.7, pyconfig.h defines "hypot" as "_hypot",
|
# On Windows Python 2.7, pyconfig.h defines "hypot" as "_hypot",
|
||||||
# This clashes with GCC's cmath, and causes compilation errors when
|
# This clashes with GCC's cmath, and causes compilation errors when
|
||||||
# building under MinGW: http://bugs.python.org/issue11566
|
# building under MinGW: http://bugs.python.org/issue11566
|
||||||
macros.append(("_hypot", "hypot"))
|
macros.append(('_hypot', 'hypot'))
|
||||||
for undef in ext.undef_macros:
|
for undef in ext.undef_macros:
|
||||||
macros.append((undef,))
|
macros.append((undef,))
|
||||||
|
|
||||||
objs = self.compiler.compile(sources,
|
objs = self.compiler.compile(
|
||||||
|
sources,
|
||||||
output_dir=self.build_temp,
|
output_dir=self.build_temp,
|
||||||
macros=macros,
|
macros=macros,
|
||||||
include_dirs=ext.include_dirs,
|
include_dirs=ext.include_dirs,
|
||||||
@ -103,7 +114,7 @@ class BuildExt(build_ext):
|
|||||||
extra_args = ext.extra_link_args or []
|
extra_args = ext.extra_link_args or []
|
||||||
# when using GCC on Windows, we statically link libgcc and libstdc++,
|
# when using GCC on Windows, we statically link libgcc and libstdc++,
|
||||||
# so that we don't need to package extra DLLs
|
# so that we don't need to package extra DLLs
|
||||||
if self.compiler.compiler_type == "mingw32":
|
if self.compiler.compiler_type == 'mingw32':
|
||||||
extra_args.extend(['-static-libgcc', '-static-libstdc++'])
|
extra_args.extend(['-static-libgcc', '-static-libstdc++'])
|
||||||
|
|
||||||
ext_path = self.get_ext_fullpath(ext.name)
|
ext_path = self.get_ext_fullpath(ext.name)
|
||||||
@ -111,7 +122,8 @@ class BuildExt(build_ext):
|
|||||||
language = ext.language or self.compiler.detect_language(sources)
|
language = ext.language or self.compiler.detect_language(sources)
|
||||||
|
|
||||||
self.compiler.link_shared_object(
|
self.compiler.link_shared_object(
|
||||||
objects, ext_path,
|
objects,
|
||||||
|
ext_path,
|
||||||
libraries=self.get_libraries(ext),
|
libraries=self.get_libraries(ext),
|
||||||
library_dirs=ext.library_dirs,
|
library_dirs=ext.library_dirs,
|
||||||
runtime_library_dirs=ext.runtime_library_dirs,
|
runtime_library_dirs=ext.runtime_library_dirs,
|
||||||
@ -121,93 +133,22 @@ class BuildExt(build_ext):
|
|||||||
build_temp=self.build_temp,
|
build_temp=self.build_temp,
|
||||||
target_lang=language)
|
target_lang=language)
|
||||||
|
|
||||||
brotli = Extension("brotli",
|
|
||||||
sources=[
|
|
||||||
"python/brotlimodule.cc",
|
|
||||||
"common/dictionary.c",
|
|
||||||
"dec/bit_reader.c",
|
|
||||||
"dec/decode.c",
|
|
||||||
"dec/huffman.c",
|
|
||||||
"dec/state.c",
|
|
||||||
"enc/backward_references.c",
|
|
||||||
"enc/bit_cost.c",
|
|
||||||
"enc/block_splitter.c",
|
|
||||||
"enc/brotli_bit_stream.c",
|
|
||||||
"enc/cluster.c",
|
|
||||||
"enc/compress_fragment.c",
|
|
||||||
"enc/compress_fragment_two_pass.c",
|
|
||||||
"enc/encode.c",
|
|
||||||
"enc/entropy_encode.c",
|
|
||||||
"enc/histogram.c",
|
|
||||||
"enc/literal_cost.c",
|
|
||||||
"enc/memory.c",
|
|
||||||
"enc/metablock.c",
|
|
||||||
"enc/static_dict.c",
|
|
||||||
"enc/utf8_util.c",
|
|
||||||
],
|
|
||||||
depends=[
|
|
||||||
"common/constants.h",
|
|
||||||
"common/dictionary.h",
|
|
||||||
"common/port.h",
|
|
||||||
"common/version.h",
|
|
||||||
"dec/bit_reader.h",
|
|
||||||
"dec/context.h",
|
|
||||||
"dec/huffman.h",
|
|
||||||
"dec/port.h",
|
|
||||||
"dec/prefix.h",
|
|
||||||
"dec/state.h",
|
|
||||||
"dec/streams.h",
|
|
||||||
"dec/transform.h",
|
|
||||||
"enc/backward_references.h",
|
|
||||||
"enc/backward_references_inc.h",
|
|
||||||
"enc/bit_cost.h",
|
|
||||||
"enc/bit_cost_inc.h",
|
|
||||||
"enc/block_splitter.h",
|
|
||||||
"enc/block_splitter_inc.h",
|
|
||||||
"enc/brotli_bit_stream.h",
|
|
||||||
"enc/cluster.h",
|
|
||||||
"enc/cluster_inc.h",
|
|
||||||
"enc/command.h",
|
|
||||||
"enc/compress_fragment.h",
|
|
||||||
"enc/compress_fragment_two_pass.h"
|
|
||||||
"enc/context.h",
|
|
||||||
"enc/dictionary_hash.h",
|
|
||||||
"enc/entropy_encode.h",
|
|
||||||
"enc/entropy_encode_static.h",
|
|
||||||
"enc/fast_log.h",
|
|
||||||
"enc/find_match_length.h",
|
|
||||||
"enc/hash.h",
|
|
||||||
"enc/hash_longest_match_inc.h",
|
|
||||||
"enc/hash_longest_match_quickly_inc.h",
|
|
||||||
"enc/histogram.h",
|
|
||||||
"enc/histogram_inc.h",
|
|
||||||
"enc/literal_cost.h",
|
|
||||||
"enc/memory.h",
|
|
||||||
"enc/metablock.h",
|
|
||||||
"enc/metablock_inc.h",
|
|
||||||
"enc/port.h",
|
|
||||||
"enc/prefix.h",
|
|
||||||
"enc/ringbuffer.h",
|
|
||||||
"enc/static_dict.h",
|
|
||||||
"enc/static_dict_lut.h",
|
|
||||||
"enc/utf8_util.h",
|
|
||||||
"enc/write_bits.h",
|
|
||||||
],
|
|
||||||
include_dirs = [
|
|
||||||
"include",
|
|
||||||
],
|
|
||||||
language="c++",
|
|
||||||
)
|
|
||||||
|
|
||||||
setup(
|
NAME = 'Brotli'
|
||||||
name="Brotli",
|
|
||||||
version=get_version(),
|
VERSION = get_version()
|
||||||
url="https://github.com/google/brotli",
|
|
||||||
description="Python binding of the Brotli compression library",
|
URL = 'https://github.com/google/brotli'
|
||||||
author="Khaled Hosny",
|
|
||||||
author_email="khaledhosny@eglug.org",
|
DESCRIPTION = 'Python bindings for the Brotli compression library'
|
||||||
license="Apache 2.0",
|
|
||||||
classifiers=[
|
AUTHOR = 'The Brotli Authors'
|
||||||
|
|
||||||
|
LICENSE = 'Apache 2.0'
|
||||||
|
|
||||||
|
PLATFORMS = ['Posix', 'MacOS X', 'Windows']
|
||||||
|
|
||||||
|
CLASSIFIERS = [
|
||||||
'Development Status :: 4 - Beta',
|
'Development Status :: 4 - Beta',
|
||||||
'Environment :: Console',
|
'Environment :: Console',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
@ -231,10 +172,101 @@ setup(
|
|||||||
'Topic :: System :: Archiving :: Compression',
|
'Topic :: System :: Archiving :: Compression',
|
||||||
'Topic :: Text Processing :: Fonts',
|
'Topic :: Text Processing :: Fonts',
|
||||||
'Topic :: Utilities',
|
'Topic :: Utilities',
|
||||||
|
]
|
||||||
|
|
||||||
|
EXT_MODULES = [
|
||||||
|
Extension(
|
||||||
|
'brotli',
|
||||||
|
sources=[
|
||||||
|
'python/brotlimodule.cc',
|
||||||
|
'common/dictionary.c',
|
||||||
|
'dec/bit_reader.c',
|
||||||
|
'dec/decode.c',
|
||||||
|
'dec/huffman.c',
|
||||||
|
'dec/state.c',
|
||||||
|
'enc/backward_references.c',
|
||||||
|
'enc/bit_cost.c',
|
||||||
|
'enc/block_splitter.c',
|
||||||
|
'enc/brotli_bit_stream.c',
|
||||||
|
'enc/cluster.c',
|
||||||
|
'enc/compress_fragment.c',
|
||||||
|
'enc/compress_fragment_two_pass.c',
|
||||||
|
'enc/encode.c',
|
||||||
|
'enc/entropy_encode.c',
|
||||||
|
'enc/histogram.c',
|
||||||
|
'enc/literal_cost.c',
|
||||||
|
'enc/memory.c',
|
||||||
|
'enc/metablock.c',
|
||||||
|
'enc/static_dict.c',
|
||||||
|
'enc/utf8_util.c',
|
||||||
],
|
],
|
||||||
ext_modules=[brotli],
|
depends=[
|
||||||
cmdclass={
|
'common/constants.h',
|
||||||
|
'common/dictionary.h',
|
||||||
|
'common/port.h',
|
||||||
|
'common/version.h',
|
||||||
|
'dec/bit_reader.h',
|
||||||
|
'dec/context.h',
|
||||||
|
'dec/huffman.h',
|
||||||
|
'dec/port.h',
|
||||||
|
'dec/prefix.h',
|
||||||
|
'dec/state.h',
|
||||||
|
'dec/streams.h',
|
||||||
|
'dec/transform.h',
|
||||||
|
'enc/backward_references.h',
|
||||||
|
'enc/backward_references_inc.h',
|
||||||
|
'enc/bit_cost.h',
|
||||||
|
'enc/bit_cost_inc.h',
|
||||||
|
'enc/block_splitter.h',
|
||||||
|
'enc/block_splitter_inc.h',
|
||||||
|
'enc/brotli_bit_stream.h',
|
||||||
|
'enc/cluster.h',
|
||||||
|
'enc/cluster_inc.h',
|
||||||
|
'enc/command.h',
|
||||||
|
'enc/compress_fragment.h',
|
||||||
|
'enc/compress_fragment_two_pass.h'
|
||||||
|
'enc/context.h',
|
||||||
|
'enc/dictionary_hash.h',
|
||||||
|
'enc/entropy_encode.h',
|
||||||
|
'enc/entropy_encode_static.h',
|
||||||
|
'enc/fast_log.h',
|
||||||
|
'enc/find_match_length.h',
|
||||||
|
'enc/hash.h',
|
||||||
|
'enc/hash_longest_match_inc.h',
|
||||||
|
'enc/hash_longest_match_quickly_inc.h',
|
||||||
|
'enc/histogram.h',
|
||||||
|
'enc/histogram_inc.h',
|
||||||
|
'enc/literal_cost.h',
|
||||||
|
'enc/memory.h',
|
||||||
|
'enc/metablock.h',
|
||||||
|
'enc/metablock_inc.h',
|
||||||
|
'enc/port.h',
|
||||||
|
'enc/prefix.h',
|
||||||
|
'enc/ringbuffer.h',
|
||||||
|
'enc/static_dict.h',
|
||||||
|
'enc/static_dict_lut.h',
|
||||||
|
'enc/utf8_util.h',
|
||||||
|
'enc/write_bits.h',
|
||||||
|
],
|
||||||
|
include_dirs=[
|
||||||
|
'include',
|
||||||
|
],
|
||||||
|
language='c++'),
|
||||||
|
]
|
||||||
|
|
||||||
|
CMD_CLASS = {
|
||||||
'build_ext': BuildExt,
|
'build_ext': BuildExt,
|
||||||
'test': TestCommand
|
'test': TestCommand,
|
||||||
},
|
}
|
||||||
)
|
|
||||||
|
setup(
|
||||||
|
name=NAME,
|
||||||
|
description=DESCRIPTION,
|
||||||
|
version=VERSION,
|
||||||
|
url=URL,
|
||||||
|
author=AUTHOR,
|
||||||
|
license=LICENSE,
|
||||||
|
platforms=PLATFORMS,
|
||||||
|
classifiers=CLASSIFIERS,
|
||||||
|
ext_modules=EXT_MODULES,
|
||||||
|
cmdclass=CMD_CLASS)
|
||||||
|
Loading…
Reference in New Issue
Block a user