1#!/usr/bin/env python 2 3# Copyright 2015 OpenMarket Ltd 4# Copyright 2018 New Vector Ltd 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18from setuptools import setup 19from codecs import open 20import os 21 22here = os.path.abspath(os.path.dirname(__file__)) 23 24 25def read_file(path_segments): 26 """Read a UTF-8 file from the package. Takes a list of strings to join to 27 make the path""" 28 file_path = os.path.join(here, *path_segments) 29 with open(file_path, encoding="utf-8") as f: 30 return f.read() 31 32 33def exec_file(path_segments, name): 34 """Extract a constant from a python file by looking for a line defining 35 the constant and executing it.""" 36 result = {} 37 code = read_file(path_segments) 38 lines = [line for line in code.split("\n") if line.startswith(name)] 39 exec("\n".join(lines), result) 40 return result[name] 41 42 43setup( 44 name="canonicaljson", 45 version=exec_file(("canonicaljson.py",), "__version__"), 46 py_modules=["canonicaljson"], 47 description="Canonical JSON", 48 install_requires=[ 49 # simplerjson versions before 3.14.0 had a bug with some characters 50 # (e.g. \u2028) if ensure_ascii was set to false. 51 "simplejson>=3.14.0", 52 "frozendict>=1.0", 53 ], 54 zip_safe=True, 55 long_description=read_file(("README.rst",)), 56 keywords="json", 57 author="The Matrix.org Team", 58 author_email="team@matrix.org", 59 url="https://github.com/matrix-org/python-canonicaljson", 60 license="Apache License, Version 2.0", 61 python_requires="~=3.5", 62 classifiers=[ 63 "Development Status :: 5 - Production/Stable", 64 "Intended Audience :: Developers", 65 "License :: OSI Approved :: Apache Software License", 66 "Programming Language :: Python :: 2", 67 "Programming Language :: Python :: 3", 68 ], 69) 70