Skip to content

Commit

Permalink
Merge pull request #345 from pcattori/typecheck-and-test-improvements
Browse files Browse the repository at this point in the history
Typecheck and test improvements
  • Loading branch information
pcattori committed Mar 21, 2020
2 parents 502a6dd + c18f9a8 commit 6f26029
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 57 deletions.
32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sphinx-autodoc-typehints = "^1.8"
pandas = "^0.25.3"
pytest = "^5.3.2"
invoke = "^1.4.0"
mypy = "^0.761"
mypy = "^0.770"

[build-system]
requires = ["poetry>=1.0"]
Expand Down
35 changes: 11 additions & 24 deletions tamr_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# flake8: noqa

# BETA check
############
# BETA start
############

import os
import sys

beta_flag = "TAMR_CLIENT_BETA"
beta_enabled = "1"
beta = os.environ.get(beta_flag)
import tamr_client.beta as beta

if beta != beta_enabled:
msg = (
f"ERROR: 'tamr_client' package is in BETA, but you do not have the '{beta_flag}' environment variable set to '1'."
"\n\nHINT: Use 'tamr_unify_client' package instead for non-BETA features"
f"\nHINT: Set environment variable '{beta_flag}=1' to opt-in to BETA features."
"\n\nWARNING: Do not rely on BETA features in production workflows."
" Support from Tamr may be limited."
)
print(msg)
sys.exit(1)
beta._check()

##########
# BETA end
##########
# Logging
#########

import logging

# https://docs.python-guide.org/writing/logging/#logging-in-a-library
logging.getLogger(__name__).addHandler(logging.NullHandler())

# Import shortcuts
##################

# utilities
import tamr_client.response as response

Expand Down Expand Up @@ -66,6 +56,3 @@
AttributeNotFound,
)
import tamr_client.attributes.attribute as attribute

# https://docs.python-guide.org/writing/logging/#logging-in-a-library
logging.getLogger(__name__).addHandler(logging.NullHandler())
2 changes: 2 additions & 0 deletions tamr_client/attributes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This __init__.py file is necessary for `mypy --package`
# See https://github.com/python/mypy/issues/5759
2 changes: 1 addition & 1 deletion tamr_client/attributes/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _from_json(url: tc.URL, data: JsonDict) -> Attribute:
)


def from_dataset_all(session: tc.Session, dataset: tc.Dataset) -> Tuple[Attribute]:
def from_dataset_all(session: tc.Session, dataset: tc.Dataset) -> Tuple[Attribute, ...]:
"""Get all attributes from a dataset
Args:
Expand Down
19 changes: 19 additions & 0 deletions tamr_client/beta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys


def _check():
beta_flag = "TAMR_CLIENT_BETA"
beta_enabled = "1"
beta = os.environ.get(beta_flag)

if beta != beta_enabled:
msg = (
f"ERROR: 'tamr_client' package is in BETA, but you do not have the '{beta_flag}' environment variable set to '1'."
"\n\nHINT: Use 'tamr_unify_client' package instead for non-BETA features"
f"\nHINT: Set environment variable '{beta_flag}=1' to opt-in to BETA features."
"\n\nWARNING: Do not rely on BETA features in production workflows."
" Support from Tamr may be limited."
)
print(msg)
sys.exit(1)
2 changes: 2 additions & 0 deletions tamr_client/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This __init__.py file is necessary for `mypy --package`
# See https://github.com/python/mypy/issues/5759
23 changes: 13 additions & 10 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
beta = "TAMR_CLIENT_BETA=1"


def _find_packages(path: Path):
for pkg in path.iterdir():
if pkg.is_dir() and len(list(pkg.glob("**/*.py"))) >= 1:
yield pkg


@task
def lint(c):
c.run("poetry run flake8 .", echo=True, pty=True)
Expand All @@ -19,17 +25,14 @@ def format(c, fix=False):
@task
def typecheck(c, warn=True):
repo = Path(".")

tc = repo / "tamr_client"
tests = repo / "tests"
pkgs = [
tc,
tc / "attributes",
tests / "attributes",
tc / "datasets",
tests / "datasets",
]
for pkg in pkgs:
c.run(f"poetry run mypy {str(pkg)}", echo=True, pty=True, warn=warn)
c.run(f"poetry run mypy --package {tc}", echo=True, pty=True, warn=warn)

tc_tests = " ".join(
str(x) for x in (repo / "tests" / "tamr_client").glob("**/*.py")
)
c.run(f"poetry run mypy {tc_tests}", echo=True, pty=True, warn=warn)


@task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import responses

import tamr_client as tc
import tests.utils as utils
import tests.tamr_client.utils as utils


def test_from_json():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import tamr_client as tc
import tests.utils
import tests.tamr_client.utils as utils


def test_from_json():
geom_json = tests.utils.load_json("attributes.json")[1]
geom_json = utils.load_json("attributes.json")[1]
geom_type = tc.attribute_type.from_json(geom_json["type"])
assert isinstance(geom_type, tc.attribute_type.Record)

Expand Down Expand Up @@ -33,7 +33,7 @@ def test_from_json():


def test_json():
attrs_json = tests.utils.load_json("attributes.json")
attrs_json = utils.load_json("attributes.json")
for attr_json in attrs_json:
attr_type_json = attr_json["type"]
attr_type = tc.attribute_type.from_json(attr_type_json)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import responses

import tamr_client as tc
import tests.utils as utils
import tests.tamr_client.utils as utils


@responses.activate
Expand Down
File renamed without changes.

0 comments on commit 6f26029

Please sign in to comment.