Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dbt plugin version #2279

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sumanau7 marked this conversation as resolved.
Show resolved Hide resolved

## dbt 0.16.0 (March 23, 2020)

Expand Down
35 changes: 29 additions & 6 deletions core/dbt/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib
import os
import json

import requests
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions plugins/bigquery/dbt/adapters/bigquery/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = '0.17.0a1'
1 change: 1 addition & 0 deletions plugins/postgres/dbt/adapters/postgres/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = '0.17.0a1'
1 change: 1 addition & 0 deletions plugins/redshift/dbt/adapters/redshift/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = '0.17.0a1'
1 change: 1 addition & 0 deletions plugins/snowflake/dbt/adapters/snowflake/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = '0.17.0a1'
89 changes: 76 additions & 13 deletions test/unit/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,85 @@

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()
version_information = dbt.version.get_version_information()

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)
self.assertMultiLineEqual(version_information,
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()
Expand All @@ -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,
Expand All @@ -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(
sumanau7 marked this conversation as resolved.
Show resolved Hide resolved
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__')
])