From 5d5913efeb0427375c41b0c40d2fed7a45602fe0 Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Sun, 5 Apr 2020 00:32:02 +0530 Subject: [PATCH 1/3] Add DBT Plugin information to get_version_information --- core/dbt/version.py | 35 ++++++-- .../dbt/adapters/bigquery/__version__.py | 1 + .../dbt/adapters/postgres/__version__.py | 1 + .../dbt/adapters/redshift/__version__.py | 1 + .../dbt/adapters/snowflake/__version__.py | 1 + test/unit/test_version.py | 89 ++++++++++++++++--- 6 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 plugins/bigquery/dbt/adapters/bigquery/__version__.py create mode 100644 plugins/postgres/dbt/adapters/postgres/__version__.py create mode 100644 plugins/redshift/dbt/adapters/redshift/__version__.py create mode 100644 plugins/snowflake/dbt/adapters/snowflake/__version__.py diff --git a/core/dbt/version.py b/core/dbt/version.py index 34e553a8ef7..a6e7e167d3a 100644 --- a/core/dbt/version.py +++ b/core/dbt/version.py @@ -1,3 +1,5 @@ +import importlib +import os import json import requests @@ -37,23 +39,44 @@ def get_version_information(): version_msg = ("installed version: {}\n" " latest version: {}\n\n".format(installed_s, latest_s)) + plugin_version_msg = "Plugins:\n" + for plugin_name, version in _get_dbt_plugins_info(): + plugin_version_msg += ' - {plugin_name}: {version}\n'.format( + plugin_name=plugin_name, version=version + ) if latest is None: return ("{}The latest version of dbt could not be determined!\n" - "Make sure that the following URL is accessible:\n{}" - .format(version_msg, PYPI_VERSION_URL)) + "Make sure that the following URL is accessible:\n{}\n\n{}" + .format(version_msg, PYPI_VERSION_URL, plugin_version_msg)) if installed == latest: - return "{}Up to date!".format(version_msg) + return "{}Up to date!\n\n{}".format(version_msg, plugin_version_msg) elif installed > latest: return ("{}Your version of dbt is ahead of the latest " - "release!".format(version_msg)) + "release!\n\n{}".format(version_msg, plugin_version_msg)) else: return ("{}Your version of dbt is out of date! " "You can find instructions for upgrading here:\n" - "https://docs.getdbt.com/docs/installation" - .format(version_msg)) + "https://docs.getdbt.com/docs/installation\n\n{}" + .format(version_msg, plugin_version_msg)) + + +def _get_dbt_plugins_info(): + for path in importlib.util.find_spec('dbt').submodule_search_locations: + plugin_root, _ = os.path.split(path) + _, plugin_name = os.path.split(plugin_root) + if plugin_name == 'core': + continue + try: + mod = importlib.import_module( + f'dbt.adapters.{plugin_name}.__version__' + ) + except ImportError: + # not an adpater + continue + yield plugin_name, mod.version __version__ = '0.17.0a1' diff --git a/plugins/bigquery/dbt/adapters/bigquery/__version__.py b/plugins/bigquery/dbt/adapters/bigquery/__version__.py new file mode 100644 index 00000000000..be4f93a2665 --- /dev/null +++ b/plugins/bigquery/dbt/adapters/bigquery/__version__.py @@ -0,0 +1 @@ +version = '0.17.0a1' diff --git a/plugins/postgres/dbt/adapters/postgres/__version__.py b/plugins/postgres/dbt/adapters/postgres/__version__.py new file mode 100644 index 00000000000..be4f93a2665 --- /dev/null +++ b/plugins/postgres/dbt/adapters/postgres/__version__.py @@ -0,0 +1 @@ +version = '0.17.0a1' diff --git a/plugins/redshift/dbt/adapters/redshift/__version__.py b/plugins/redshift/dbt/adapters/redshift/__version__.py new file mode 100644 index 00000000000..be4f93a2665 --- /dev/null +++ b/plugins/redshift/dbt/adapters/redshift/__version__.py @@ -0,0 +1 @@ +version = '0.17.0a1' diff --git a/plugins/snowflake/dbt/adapters/snowflake/__version__.py b/plugins/snowflake/dbt/adapters/snowflake/__version__.py new file mode 100644 index 00000000000..be4f93a2665 --- /dev/null +++ b/plugins/snowflake/dbt/adapters/snowflake/__version__.py @@ -0,0 +1 @@ +version = '0.17.0a1' diff --git a/test/unit/test_version.py b/test/unit/test_version.py index 4f5b18a49b0..d159f735b81 100644 --- a/test/unit/test_version.py +++ b/test/unit/test_version.py @@ -3,15 +3,23 @@ import dbt.main import dbt.version -import sys class VersionTest(unittest.TestCase): @patch("dbt.version.__version__", "0.10.0") + @patch('dbt.version._get_dbt_plugins_info', autospec=True) @patch('dbt.version.requests.get') - def test_versions_equal(self, mock_get): - mock_get.return_value.json.return_value = {'info': {'version': '0.10.0'}} + def test_versions_equal(self, mock_get, mock_get_dbt_plugins_info): + mock_get.return_value.json.return_value = { + 'info': {'version': '0.10.0'} + } + mock_get_dbt_plugins_info.return_value = [ + ('dbt-postgres', '0.10.0'), + ('dbt-redshift', '0.10.0'), + ('dbt-bigquery', '0.10.0'), + ('dbt-snowflake', '0.10.0') + ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() @@ -19,7 +27,12 @@ def test_versions_equal(self, mock_get): expected_version_information = "installed version: 0.10.0\n" \ " latest version: 0.10.0\n\n" \ - "Up to date!" + "Up to date!\n\n" \ + "Plugins:\n" \ + " - dbt-postgres: 0.10.0\n" \ + " - dbt-redshift: 0.10.0\n" \ + " - dbt-bigquery: 0.10.0\n" \ + " - dbt-snowflake: 0.10.0\n" self.assertEqual(latest_version, installed_version) self.assertEqual(latest_version, installed_version) @@ -27,27 +40,48 @@ def test_versions_equal(self, mock_get): expected_version_information) @patch("dbt.version.__version__", "0.10.2-a1") + @patch('dbt.version._get_dbt_plugins_info', autospec=True) @patch('dbt.version.requests.get') - def test_installed_version_greater(self, mock_get): - mock_get.return_value.json.return_value = {'info': {'version': '0.10.1'}} - + def test_installed_version_greater(self, mock_get, mock_get_dbt_plugins_info): + mock_get.return_value.json.return_value = { + 'info': {'version': '0.10.1'} + } + mock_get_dbt_plugins_info.return_value = [ + ('dbt-postgres', '0.10.0'), + ('dbt-redshift', '0.10.0'), + ('dbt-bigquery', '0.10.0'), + ('dbt-snowflake', '0.10.0') + ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() version_information = dbt.version.get_version_information() expected_version_information = "installed version: 0.10.2-a1\n" \ " latest version: 0.10.1\n\n" \ - "Your version of dbt is ahead of the latest release!" + "Your version of dbt is ahead of the latest release!\n\n" \ + "Plugins:\n" \ + " - dbt-postgres: 0.10.0\n" \ + " - dbt-redshift: 0.10.0\n" \ + " - dbt-bigquery: 0.10.0\n" \ + " - dbt-snowflake: 0.10.0\n" assert installed_version > latest_version self.assertMultiLineEqual(version_information, expected_version_information) @patch("dbt.version.__version__", "0.9.5") + @patch('dbt.version._get_dbt_plugins_info', autospec=True) @patch('dbt.version.requests.get') - def test_installed_version_lower(self, mock_get): - mock_get.return_value.json.return_value = {'info': {'version': '0.10.0'}} - + def test_installed_version_lower(self, mock_get, mock_get_dbt_plugins_info): + mock_get.return_value.json.return_value = { + 'info': {'version': '0.10.0'} + } + mock_get_dbt_plugins_info.return_value = [ + ('dbt-postgres', '0.10.0'), + ('dbt-redshift', '0.10.0'), + ('dbt-bigquery', '0.10.0'), + ('dbt-snowflake', '0.10.0') + ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() version_information = dbt.version.get_version_information() @@ -56,7 +90,12 @@ def test_installed_version_lower(self, mock_get): " latest version: 0.10.0\n\n" \ "Your version of dbt is out of date! " \ "You can find instructions for upgrading here:\n" \ - "https://docs.getdbt.com/docs/installation" + "https://docs.getdbt.com/docs/installation\n\n" \ + "Plugins:\n" \ + " - dbt-postgres: 0.10.0\n" \ + " - dbt-redshift: 0.10.0\n" \ + " - dbt-bigquery: 0.10.0\n" \ + " - dbt-snowflake: 0.10.0\n" assert installed_version < latest_version self.assertMultiLineEqual(version_information, @@ -66,8 +105,32 @@ def test_installed_version_lower(self, mock_get): @patch('sys.stderr') @patch('dbt.version.requests.get') def test_dbt_version_flag(self, mock_get, stderr): - mock_get.return_value.json.return_value = {'info': {'version': '0.10.1'}} + mock_get.return_value.json.return_value = { + 'info': {'version': '0.10.1'} + } with self.assertRaises(SystemExit) as exc: dbt.main.handle_and_check(['--version']) self.assertEqual(exc.exception.code, 0) + + @patch('importlib.util.find_spec', autospec=True) + @patch('importlib.import_module', autospec=True) + def test_get_dbt_plugins_info_with_version_info( + self, mock_mod, mock_find_spec + ): + mock_submodule = unittest.mock.Mock() + mock_find_spec.return_value = mock_submodule + mock_submodule.submodule_search_locations = [ + '/tmp/dbt/plugins/postgres/dbt', '/tmp/dbt/plugins/snowflake/dbt'] + mod_version = unittest.mock.Mock() + mock_mod.return_value = mod_version + mod_version.version = '1.0' + self.assertEqual( + list(dbt.version._get_dbt_plugins_info()), + [('postgres', '1.0'), ('snowflake', '1.0')] + ) + mock_find_spec.assert_called_once_with('dbt') + mock_mod.assert_has_calls([ + unittest.mock.call('dbt.adapters.postgres.__version__'), + unittest.mock.call('dbt.adapters.snowflake.__version__') + ]) From 10d20197ed0cd080fe5195620bb07c3329ae605d Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Tue, 7 Apr 2020 00:26:04 +0530 Subject: [PATCH 2/3] Update changelog.md with github issue and PR details --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1189040620..7104782645b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,13 @@ - Added timeout to registry download call ([#2195](https://github.com/fishtown-analytics/dbt/issues/2195), [#2228](https://github.com/fishtown-analytics/dbt/pull/2228)) - When a macro is called with invalid arguments, include the calling model in the output ([#2073](https://github.com/fishtown-analytics/dbt/issues/2073), [#2238](https://github.com/fishtown-analytics/dbt/pull/2238)) - When a warn exception is not in a jinja do block, return an empty string instead of None ([#2222](https://github.com/fishtown-analytics/dbt/issues/2222), [#2259](https://github.com/fishtown-analytics/dbt/pull/2259)) +- Add dbt plugin versions to --version([#2272](https://github.com/fishtown-analytics/dbt/issues/2272), [#2279](https://github.com/fishtown-analytics/dbt/pull/2279)) Contributors: - [@raalsky](https://github.com/Raalsky) ([#2224](https://github.com/fishtown-analytics/dbt/pull/2224), [#2228](https://github.com/fishtown-analytics/dbt/pull/2228)) - [@ilkinulas](https://github.com/ilkinulas) [#2199](https://github.com/fishtown-analytics/dbt/pull/2199) - [@jeremyyeo](https://github.com/jeremyyeo) [#2259](https://github.com/fishtown-analytics/dbt/pull/2259) + - [@sumanau7] (https://github.com/sumanau7) [#2279](https://github.com/fishtown-analytics/dbt/pull/2279) ## dbt 0.16.0 (March 23, 2020) From f5697fd82b490da66ab310a1400a31f57fb3b23d Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Tue, 7 Apr 2020 00:55:54 +0530 Subject: [PATCH 3/3] Update CHANGELOG.md Co-Authored-By: Jacob Beck --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7104782645b..f51e9f48328 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Contributors: - [@raalsky](https://github.com/Raalsky) ([#2224](https://github.com/fishtown-analytics/dbt/pull/2224), [#2228](https://github.com/fishtown-analytics/dbt/pull/2228)) - [@ilkinulas](https://github.com/ilkinulas) [#2199](https://github.com/fishtown-analytics/dbt/pull/2199) - [@jeremyyeo](https://github.com/jeremyyeo) [#2259](https://github.com/fishtown-analytics/dbt/pull/2259) - - [@sumanau7] (https://github.com/sumanau7) [#2279](https://github.com/fishtown-analytics/dbt/pull/2279) + - [@sumanau7](https://github.com/sumanau7) [#2279](https://github.com/fishtown-analytics/dbt/pull/2279) ## dbt 0.16.0 (March 23, 2020)