Skip to content

Commit

Permalink
Merge pull request #1 from clear-street/feat/prep-for-pypi
Browse files Browse the repository at this point in the history
prep for pypi
  • Loading branch information
Tanishq Dubey authored Jan 6, 2020
2 parents 10d62d0 + b922226 commit e1c775f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 26 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements.test.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pytest -s --cov=gestalt .
pytest -s --cov=gestalt tests/*.py
- name: Typecheck with mypy
run: |
pip install mypy
mypy --strict gestalt.py
mypy --strict gestalt
- name: Style check with yapf
run: |
pip install yapf
yapf -d gestalt.py
yapf -d --recursive .
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Clear Street Technologies

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File renamed without changes.
6 changes: 6 additions & 0 deletions requirements.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
yapf==0.29.0
flake8==3.7.9
mypy==0.720
mypy-extensions==0.4.1
pytest==4.3.1
pytest-cov==2.8.1
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[aliases]
test = pytest

[tool:pytest]
addopts = --verbose
python_files = tests/*.py
31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup


def readme():
with open('README.md') as f:
return f.read()


setup(name='gestalt-cfg',
version='1.0.0',
description='A sensible configuration library for Python',
long_description=readme(),
long_description_content_type="text/markdown",
url='https://github.com/clear-street/gestalt',
author='Clear Street',
author_email='[email protected]',
license='MIT',
packages=['gestalt'],
python_requires='>=3.6',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development :: Libraries',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3 :: Only',
'Operating System :: OS Independent',
])
File renamed without changes.
38 changes: 20 additions & 18 deletions test_gestalt.py → tests/test_gestalt.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# type: ignore

import pytest
import os
from gestalt import gestalt
import gestalt


# Testing JSON Loading
def test_loading_json():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
x = g.dump()
assert len(x)
Expand All @@ -22,13 +24,13 @@ def test_loading_json_nonexist_dir():
def test_loading_json_file_not_dir():
g = gestalt.Gestalt()
with pytest.raises(ValueError) as terr:
g.add_config_path('./gestalt.py')
g.add_config_path('./setup.py')
assert 'is not a directory' in terr


def test_get_wrong_type():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
with pytest.raises(TypeError) as terr:
g.get_string('numbers')
Expand All @@ -37,7 +39,7 @@ def test_get_wrong_type():

def test_get_non_exist_key():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
with pytest.raises(ValueError) as terr:
g.get_string('non-exist')
Expand All @@ -46,7 +48,7 @@ def test_get_non_exist_key():

def test_get_key_wrong_type():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
with pytest.raises(TypeError) as terr:
g.get_string(1234)
Expand All @@ -55,7 +57,7 @@ def test_get_key_wrong_type():

def test_get_key_wrong_default_type():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
with pytest.raises(TypeError) as terr:
g.get_string('nonexist', 1234)
Expand All @@ -64,23 +66,23 @@ def test_get_key_wrong_default_type():

def test_get_json_string():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_string('yarn')
assert testval == 'blue skies'


def test_get_json_default_string():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_string('nonexist', 'mydefval')
assert testval == 'mydefval'


def test_get_json_set_default_string():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
g.set_default_string('nonexisttest', 'otherdefval')
testval = g.get_string('nonexisttest')
Expand All @@ -89,31 +91,31 @@ def test_get_json_set_default_string():

def test_get_json_int():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_int('numbers')
assert testval == 12345678


def test_get_json_float():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_float('strangenumbers')
assert testval == 123.456


def test_get_json_bool():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_bool('truthy')
assert testval is True


def test_get_json_list():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_list('listing')
assert testval
Expand All @@ -123,7 +125,7 @@ def test_get_json_list():

def test_get_json_nested():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_string('deep.nested1')
assert testval == 'hello'
Expand Down Expand Up @@ -199,7 +201,7 @@ def test_re_set_bad_type():

def test_set_override():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
testval = g.get_int('numbers')
assert testval == 12345678
Expand All @@ -210,7 +212,7 @@ def test_set_override():

def test_set_bad_type_file_config():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
with pytest.raises(TypeError) as terr:
g.set_string('numbers', 'notgood')
Expand Down Expand Up @@ -329,7 +331,7 @@ def test_set_default_string_bad_val_override():

def test_set_default_bad_type_file_config():
g = gestalt.Gestalt()
g.add_config_path('./testdata')
g.add_config_path('./tests/testdata')
g.build_config()
with pytest.raises(TypeError) as terr:
g.set_default_string('numbers', 'notgood')
Expand Down
File renamed without changes.

0 comments on commit e1c775f

Please sign in to comment.