export a __version__ variable for python module (#5309)

* export a __version__ variable for python module

* assign version to be used below

* better support python2

* Add copyright header
This commit is contained in:
Omer Akram 2020-07-31 03:56:21 +05:00 committed by GitHub
parent f1f23d08ed
commit 77c18c1d69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -15,4 +15,5 @@
from .builder import Builder
from .table import Table
from .compat import range_func as compat_range
from ._version import __version__
from . import util

View File

@ -0,0 +1,17 @@
# Copyright 2019 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Placeholder, to be updated during the release process
# by the setup.py
__version__ = u"latest"

View File

@ -12,18 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import fileinput
import os
import re
import sys
from datetime import datetime
from setuptools import setup
def _update_version_attr(new_version):
for line in fileinput.input('flatbuffers/_version.py', inplace=True):
if line.startswith('__version__'):
line = re.sub(r'".*"', '"{}"'.format(new_version), line)
sys.stdout.write(line)
def version():
version = os.getenv('VERSION', None)
if version:
# Most git tags are prefixed with 'v' (example: v1.2.3) this is
# never desirable for artifact repositories, so we strip the
# leading 'v' if it's present.
return version[1:] if version.startswith('v') else version
version = version[1:] if version.startswith('v') else version
else:
# Default version is an ISO8601 compiliant datetime. PyPI doesn't allow
# the colon ':' character in its versions, and time is required to allow
@ -39,8 +49,11 @@ def version():
print("VERSION environment variable not set, using datetime instead: {}"
.format(version))
_update_version_attr(version)
return version
setup(
name='flatbuffers',
version=version(),