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:
parent
f1f23d08ed
commit
77c18c1d69
|
@ -15,4 +15,5 @@
|
||||||
from .builder import Builder
|
from .builder import Builder
|
||||||
from .table import Table
|
from .table import Table
|
||||||
from .compat import range_func as compat_range
|
from .compat import range_func as compat_range
|
||||||
|
from ._version import __version__
|
||||||
from . import util
|
from . import util
|
||||||
|
|
|
@ -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"
|
|
@ -12,18 +12,28 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import fileinput
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from setuptools import setup
|
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():
|
def version():
|
||||||
version = os.getenv('VERSION', None)
|
version = os.getenv('VERSION', None)
|
||||||
if version:
|
if version:
|
||||||
# Most git tags are prefixed with 'v' (example: v1.2.3) this is
|
# Most git tags are prefixed with 'v' (example: v1.2.3) this is
|
||||||
# never desirable for artifact repositories, so we strip the
|
# never desirable for artifact repositories, so we strip the
|
||||||
# leading 'v' if it's present.
|
# 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:
|
else:
|
||||||
# Default version is an ISO8601 compiliant datetime. PyPI doesn't allow
|
# Default version is an ISO8601 compiliant datetime. PyPI doesn't allow
|
||||||
# the colon ':' character in its versions, and time is required to 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: {}"
|
print("VERSION environment variable not set, using datetime instead: {}"
|
||||||
.format(version))
|
.format(version))
|
||||||
|
|
||||||
|
_update_version_attr(version)
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='flatbuffers',
|
name='flatbuffers',
|
||||||
version=version(),
|
version=version(),
|
||||||
|
|
Loading…
Reference in New Issue