Repository: beam Updated Branches: refs/heads/master bb9ae7350 -> 7c7103608
[BEAM-547] Version should be accessed from pom file Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/b43eea47 Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/b43eea47 Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/b43eea47 Branch: refs/heads/master Commit: b43eea47e3b1e842bc28543679500452ceda5a33 Parents: bb9ae73 Author: Sourabh Bajaj <[email protected]> Authored: Tue Mar 7 18:39:43 2017 -0800 Committer: Ahmet Altay <[email protected]> Committed: Wed Mar 15 10:22:41 2017 -0700 ---------------------------------------------------------------------- sdks/python/apache_beam/__init__.py | 3 ++ .../runners/dataflow/internal/dependency.py | 2 +- sdks/python/apache_beam/version.py | 25 ++++++--------- sdks/python/apache_beam/version_test.py | 32 ++++++++++++++++++++ sdks/python/setup.py | 2 +- 5 files changed, 46 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/b43eea47/sdks/python/apache_beam/__init__.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/__init__.py b/sdks/python/apache_beam/__init__.py index 77c89ad..2001c80 100644 --- a/sdks/python/apache_beam/__init__.py +++ b/sdks/python/apache_beam/__init__.py @@ -77,6 +77,9 @@ import apache_beam.internal.pickler from apache_beam import coders from apache_beam import io from apache_beam import typehints +from apache_beam import version from apache_beam.pipeline import Pipeline from apache_beam.transforms import * # pylint: enable=wrong-import-position + +__version__ = version.get_version() http://git-wip-us.apache.org/repos/asf/beam/blob/b43eea47/sdks/python/apache_beam/runners/dataflow/internal/dependency.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/runners/dataflow/internal/dependency.py b/sdks/python/apache_beam/runners/dataflow/internal/dependency.py index 902d738..4e49a4f 100644 --- a/sdks/python/apache_beam/runners/dataflow/internal/dependency.py +++ b/sdks/python/apache_beam/runners/dataflow/internal/dependency.py @@ -476,7 +476,7 @@ def get_sdk_name_and_version(): # TODO(ccy): Make this check cleaner. container_version = get_required_container_version() if container_version == BEAM_CONTAINER_VERSION: - return ('Apache Beam SDK for Python', beam_version.__version__) + return ('Apache Beam SDK for Python', beam_version.get_version()) else: return ('Google Cloud Dataflow SDK for Python', container_version) http://git-wip-us.apache.org/repos/asf/beam/blob/b43eea47/sdks/python/apache_beam/version.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/version.py b/sdks/python/apache_beam/version.py index e5d61a1..ef07dbf 100644 --- a/sdks/python/apache_beam/version.py +++ b/sdks/python/apache_beam/version.py @@ -21,14 +21,17 @@ import re -__version__ = '0.7.0.dev' +__version__ = None -# The following utilities are legacy code from the Maven integration; -# see BEAM-378 for further details. +def get_version(): + global __version__ + if not __version__: + __version__ = get_version_from_pom() + return __version__ -# Reads the actual version from pom.xml file, +# Read the version from pom.xml file def get_version_from_pom(): with open('pom.xml', 'r') as f: pom = f.read() @@ -43,15 +46,5 @@ def get_version_from_pom(): return version -# Synchronizes apache_beam.__version__ field for later usage -def sync_version(version): - init_path = 'apache_beam/__init__.py' - regex = r'^__version__\s*=\s*".*"' - with open(init_path, "r") as f: - lines = f.readlines() - with open(init_path, "w") as f: - for line in lines: - if re.search(regex, line): - f.write(re.sub(regex, '__version__ = "%s"' % version, line)) - else: - f.write(line) +if __name__ == '__main__': + __version__ = get_version_from_pom() http://git-wip-us.apache.org/repos/asf/beam/blob/b43eea47/sdks/python/apache_beam/version_test.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/version_test.py b/sdks/python/apache_beam/version_test.py new file mode 100644 index 0000000..e3c431d --- /dev/null +++ b/sdks/python/apache_beam/version_test.py @@ -0,0 +1,32 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +"""Unit tests for the version module.""" + +import unittest +from apache_beam import version as beam_version + + +class Version(unittest.TestCase): + + def test_version(self): + # Test that version is processed from the external file and cached. + self.assertIsNotNone(beam_version.get_version()) + self.assertEqual(beam_version.get_version(), beam_version.__version__) + + +if __name__ == '__main__': + unittest.main() http://git-wip-us.apache.org/repos/asf/beam/blob/b43eea47/sdks/python/setup.py ---------------------------------------------------------------------- diff --git a/sdks/python/setup.py b/sdks/python/setup.py index 3b44b82..3456e7d 100644 --- a/sdks/python/setup.py +++ b/sdks/python/setup.py @@ -30,7 +30,7 @@ from pkg_resources import get_distribution, DistributionNotFound def get_version(): - global_names = {} + global_names = {'__name__': '__main__'} exec(open(os.path.normpath('./apache_beam/version.py')).read(), global_names) return global_names['__version__']
