From 82f0d465c54c6a8cbc21e7b7f528da63e9713436 Mon Sep 17 00:00:00 2001 From: Sourabh Bajaj Date: Wed, 15 Mar 2017 12:51:46 -0700 Subject: [PATCH] Revert "[BEAM-547] Version should be accessed from pom file" This reverts commit b43eea47e3b1e842bc28543679500452ceda5a33. --- 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, 18 insertions(+), 46 deletions(-) delete mode 100644 sdks/python/apache_beam/version_test.py diff --git a/sdks/python/apache_beam/__init__.py b/sdks/python/apache_beam/__init__.py index 2001c80ce6e6..77c89adc2f2f 100644 --- a/sdks/python/apache_beam/__init__.py +++ b/sdks/python/apache_beam/__init__.py @@ -77,9 +77,6 @@ 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() diff --git a/sdks/python/apache_beam/runners/dataflow/internal/dependency.py b/sdks/python/apache_beam/runners/dataflow/internal/dependency.py index 4e49a4fe8360..902d738c0c73 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.get_version()) + return ('Apache Beam SDK for Python', beam_version.__version__) else: return ('Google Cloud Dataflow SDK for Python', container_version) diff --git a/sdks/python/apache_beam/version.py b/sdks/python/apache_beam/version.py index ef07dbf99f99..e5d61a132aa6 100644 --- a/sdks/python/apache_beam/version.py +++ b/sdks/python/apache_beam/version.py @@ -21,17 +21,14 @@ import re -__version__ = None +__version__ = '0.7.0.dev' -def get_version(): - global __version__ - if not __version__: - __version__ = get_version_from_pom() - return __version__ +# The following utilities are legacy code from the Maven integration; +# see BEAM-378 for further details. -# Read the version from pom.xml file +# Reads the actual version from pom.xml file, def get_version_from_pom(): with open('pom.xml', 'r') as f: pom = f.read() @@ -46,5 +43,15 @@ def get_version_from_pom(): return version -if __name__ == '__main__': - __version__ = get_version_from_pom() +# 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) diff --git a/sdks/python/apache_beam/version_test.py b/sdks/python/apache_beam/version_test.py deleted file mode 100644 index e3c431deb5dd..000000000000 --- a/sdks/python/apache_beam/version_test.py +++ /dev/null @@ -1,32 +0,0 @@ -# -# 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() diff --git a/sdks/python/setup.py b/sdks/python/setup.py index 3456e7de26f5..3b44b824d7e1 100644 --- a/sdks/python/setup.py +++ b/sdks/python/setup.py @@ -30,7 +30,7 @@ def get_version(): - global_names = {'__name__': '__main__'} + global_names = {} exec(open(os.path.normpath('./apache_beam/version.py')).read(), global_names) return global_names['__version__']