blob: 0615f2b8b20352e1ad91bfdd998b1a8f1ee08d09 [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001# 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
Austin Schuh272c6132020-11-14 16:37:52 -080015import fileinput
Austin Schuhe89fa2d2019-08-14 20:24:23 -070016import os
Austin Schuh272c6132020-11-14 16:37:52 -080017import re
18import sys
Austin Schuhe89fa2d2019-08-14 20:24:23 -070019from datetime import datetime
20from setuptools import setup
21
22
Austin Schuh272c6132020-11-14 16:37:52 -080023def _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
Austin Schuhe89fa2d2019-08-14 20:24:23 -070030def 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.
Austin Schuh272c6132020-11-14 16:37:52 -080036 version = version[1:] if version.startswith('v') else version
Austin Schuhe89fa2d2019-08-14 20:24:23 -070037 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
Austin Schuh272c6132020-11-14 16:37:52 -080052 _update_version_attr(version)
53
Austin Schuhe89fa2d2019-08-14 20:24:23 -070054 return version
55
Austin Schuh272c6132020-11-14 16:37:52 -080056
Austin Schuhe89fa2d2019-08-14 20:24:23 -070057setup(
58 name='flatbuffers',
59 version=version(),
60 license='Apache 2.0',
61 author='FlatBuffers Contributors',
62 author_email='me@rwinslow.com',
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)