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

bugfix: respect config options in dbt_project.yml #255

Merged
merged 13 commits into from
Dec 28, 2016
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
logs/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -60,3 +61,6 @@ target/

#Ipython Notebook
.ipynb_checkpoints

#Emacs
*~
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## dbt 0.6.1 (unreleased)

#### Bugfixes

- respect `config` options in profiles.yml ([#255](https://github.com/analyst-collective/dbt/pull/255))

## dbt release 0.6.0

### tl;dr
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
.PHONY: test
.PHONY: test test-unit test-integration

changed_tests := `git status --porcelain | grep '^\(M\| M\|A\| A\)' | awk '{ print $$2 }' | grep '\/test_[a-zA-Z_\-\.]\+.py'`

test:
@echo "Test run starting..."
@docker-compose run test /usr/src/app/test/runner.sh
test: test-unit test-integration

test-unit:
@echo "Unit test run starting..."
tox -e unit-py27,unit-py35

test-integration:
@echo "Integration test run starting..."
@docker-compose run test /usr/src/app/test/integration.sh

test-new:
@echo "Test run starting..."
Expand Down
27 changes: 27 additions & 0 deletions dbt/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os.path
import yaml

import dbt.project as project


def read_config(profiles_dir=None):
if profiles_dir is None:
profiles_dir = default_profiles_dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does default_profiles_dir come from?


path = os.path.join(profiles_dir, 'profiles.yml')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think passing None to os.path.join causes a TypeError.

Previously, this file was assumed to be located at ~/.dbt/profiles.yml. We should either remove the default value for profiles_dir and insist that the caller passes a value, or we should coalesce None to the default filepath

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good call. since read_config is part of the private API of this namespace, and calls have to go through send_anonymous_usage_stats, i just removed the default None value.


if os.path.isfile(path):
with open(path, 'r') as f:
profile = yaml.safe_load(f)
return profile.get('config', {})

return {}


def send_anonymous_usage_stats(profiles_dir):
config = read_config(profiles_dir)

if config is not None and config.get("send_anonymous_usage_stats") == False:
return False

return True
14 changes: 2 additions & 12 deletions dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@
import dbt.task.test as test_task
import dbt.task.archive as archive_task
import dbt.tracking


def is_opted_out(profiles_dir):
profiles = project.read_profiles(profiles_dir)

if profiles is None or profiles.get("config") is None:
return False
elif profiles['config'].get("send_anonymous_usage_stats") == False:
return True
else:
return False
import dbt.config as config

def main(args=None):
if args is None:
Expand All @@ -46,7 +36,7 @@ def handle(args):
parsed = parse_args(args)

# this needs to happen after args are parsed so we can determine the correct profiles.yml file
if is_opted_out(parsed.profiles_dir):
if not config.send_anonymous_usage_stats(parsed.profiles_dir):
dbt.tracking.do_not_track()

res = run_from_args(parsed)
Expand Down
7 changes: 7 additions & 0 deletions test/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

. /usr/src/app/test/setup.sh
workon dbt

cd /usr/src/app
tox -e integration-py27,integration-py35
14 changes: 0 additions & 14 deletions test/runner.sh

This file was deleted.

48 changes: 48 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import unittest
import yaml

import dbt.config

if os.name == 'nt':
TMPDIR = 'c:/Windows/TEMP'
else:
TMPDIR = '/tmp'

class ConfigTest(unittest.TestCase):

def set_up_empty_config(self):
profiles_path = '{}/profiles.yml'.format(TMPDIR)

with open(profiles_path, 'w') as f:
f.write(yaml.dump({}))

def set_up_config_options(self, send_anonymous_usage_stats=False):
profiles_path = '{}/profiles.yml'.format(TMPDIR)

with open(profiles_path, 'w') as f:
f.write(yaml.dump({
'config': {
'send_anonymous_usage_stats': send_anonymous_usage_stats
}
}))

def tearDown(self):
profiles_path = '{}/profiles.yml'.format(TMPDIR)

try:
os.remove(profiles_path)
except:
pass

def test__implicit_opt_in(self):
self.set_up_empty_config()
self.assertTrue(dbt.config.send_anonymous_usage_stats(TMPDIR))

def test__explicit_opt_out(self):
self.set_up_config_options(send_anonymous_usage_stats=False)
self.assertFalse(dbt.config.send_anonymous_usage_stats(TMPDIR))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def test__explicit_opt_in(self):
self.set_up_config_options(send_anonymous_usage_stats=True)
self.assertTrue(dbt.config.send_anonymous_usage_stats(TMPDIR))
32 changes: 24 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py27, py35
envlist = unit-py27, unit-py35, integration-py27, integration-py35

[testenv:unit-py27]
basepython = python2.7
commands = /bin/bash -c '$(which nosetests) -v test/unit'
deps =
-rrequirements.txt
-rdev_requirements.txt

[testenv:unit-py35]
basepython = python3.5
commands = /bin/bash -c '$(which nosetests) -v test/unit'
deps =
-rrequirements.txt
-rdev_requirements.txt

[testenv]
commands = /bin/bash -c 'HOME=/root/ DBT_INVOCATION_ENV=ci-circle {envpython} $(which nosetests) -v --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov test/unit test/integration/*'
[testenv:integration-py27]
basepython = python2.7
commands = /bin/bash -c 'HOME=/root/ DBT_INVOCATION_ENV=ci-circle {envpython} $(which nosetests) -v --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov test/integration/*'
deps =
-rrequirements.txt
-rdev_requirements.txt

[testenv:integration-py35]
basepython = python3.5
commands = /bin/bash -c 'HOME=/root/ DBT_INVOCATION_ENV=ci-circle {envpython} $(which nosetests) -v --with-coverage --cover-branches --cover-html --cover-html-dir=htmlcov test/integration/*'
deps =
-rrequirements.txt
-rdev_requirements.txt

[testenv:pywin]
basepython = {env:PYTHON:}\python.exe
Expand Down