1# Copyright 2016 Google Inc. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import fileinput 16import os 17import re 18import sys 19from datetime import datetime 20from setuptools import setup 21 22 23def _update_version_attr(new_version): 24 for line in fileinput.input('flatbuffers/_version.py', inplace=True): 25 if line.startswith('__version__'): 26 line = re.sub(r'".*"', '"{}"'.format(new_version), line) 27 sys.stdout.write(line) 28 29 30def version(): 31 version = os.getenv('VERSION', None) 32 if version: 33 # Most git tags are prefixed with 'v' (example: v1.2.3) this is 34 # never desirable for artifact repositories, so we strip the 35 # leading 'v' if it's present. 36 version = version[1:] if version.startswith('v') else version 37 else: 38 # Default version is an ISO8601 compiliant datetime. PyPI doesn't allow 39 # the colon ':' character in its versions, and time is required to allow 40 # for multiple publications to master in one day. This datetime string 41 # uses the "basic" ISO8601 format for both its date and time components 42 # to avoid issues with the colon character (ISO requires that date and 43 # time components of a date-time string must be uniformly basic or 44 # extended, which is why the date component does not have dashes. 45 # 46 # Publications using datetime versions should only be made from master 47 # to represent the HEAD moving forward. 48 version = datetime.utcnow().strftime('%Y%m%d%H%M%S') 49 print("VERSION environment variable not set, using datetime instead: {}" 50 .format(version)) 51 52 _update_version_attr(version) 53 54 return version 55 56 57setup( 58 name='flatbuffers', 59 version=version(), 60 license='Apache 2.0', 61 author='FlatBuffers Contributors', 62 author_email='[email protected]', 63 url='https://google.github.io/flatbuffers/', 64 long_description=('Python runtime library for use with the ' 65 '`Flatbuffers <https://google.github.io/flatbuffers/>`_ ' 66 'serialization format.'), 67 packages=['flatbuffers'], 68 include_package_data=True, 69 requires=[], 70 description='The FlatBuffers serialization format for Python', 71 classifiers=[ 72 'Intended Audience :: Developers', 73 'License :: OSI Approved :: Apache Software License', 74 'Operating System :: OS Independent', 75 'Programming Language :: Python', 76 'Programming Language :: Python :: 2', 77 'Programming Language :: Python :: 3', 78 'Topic :: Software Development :: Libraries :: Python Modules', 79 ], 80 project_urls={ 81 'Documentation': 'https://google.github.io/flatbuffers/', 82 'Source': 'https://github.com/google/flatbuffers', 83 }, 84)