Skip to content

Commit

Permalink
Merge pull request #29 from jakevdp/black
Browse files Browse the repository at this point in the history
MAINT: add black code formatting & test
  • Loading branch information
jakevdp authored Dec 4, 2019
2 parents 8ef9182 + fc85f54 commit d3bf60a
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 57 deletions.
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@ language: python

cache: pip

env:
- TEST_DIR=/tmp/_vega_datasets

matrix:
include:
- python: 2.7
- python: 3.5
- python: 3.6
- python: 3.7
- python: 3.8
- name: "lint"
python: 3.8
install:
script:
- black --check .
- flake8 vega_datasets

env:
global:
- TEST_DIR=/tmp/_vega_datasets/

before_install:
- python -m pip install pip --upgrade;
- pip install pip --upgrade;
- pip install -r requirements_dev.txt

install:
- python -m pip install -e .;
- pip install -e .;

script:
- mkdir -p $TEST_DIR
- cd $TEST_DIR && python -m pytest --pyargs --doctest-modules vega_datasets;
- cd $TEST_DIR && pytest --pyargs --doctest-modules vega_datasets
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ install:
python setup.py install

test:
python -m pytest --pyargs vega_datasets --doctest-modules
black .
python -m flake8 vega_datasets
rm -r build
python setup.py build &&\
cd build/lib &&\
python -m pytest --pyargs --doctest-modules vega_datasets

test-coverage:
python -m pytest --pyargs vega_datasets --doctest-modules --cov=vega_datasets --cov-report term
python setup.py build &&\
cd build/lib &&\
python -m pytest --pyargs --doctest-modules --cov=altair_transform --cov-report term vega_datasets

test-coverage-html:
python -m pytest --pyargs vega_datasets --doctest-modules --cov=vega_datasets --cov-report html
python setup.py build &&\
cd build/lib &&\
python -m pytest --pyargs --doctest-modules --cov=altair_transform --cov-report html vega_datasets
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.black]
line-length = 88
target-version = ['py27', 'py35', 'py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| build
| dist
| tools/vega-datasets
)/
| altair_transform/utils/_parser_Parser_parsetab.py
'''
3 changes: 3 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
black; python_version >= '3.6'
flake8
pytest
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[flake8]
exclude = altair_transform/utils/_parser_Parser_parsetab.py
max-line-length = 88
ignore = E203, E266, E501, W503
max-complexity = 18
select = B,C,E,F,W,T4,B9

[metadata]
description-file = README.md
license_file = LICENSE


[bdist_wheel]
universal = 1
87 changes: 45 additions & 42 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
here = os.path.abspath(os.path.dirname(__file__))


def read(path, encoding='utf-8'):
def read(path, encoding="utf-8"):
path = os.path.join(here, path)
with io.open(path, encoding=encoding) as fp:
return fp.read()
Expand All @@ -19,50 +19,53 @@ def version(path):
See <https://packaging.python.org/en/latest/single_source_version.html>.
"""
version_file = read(path)
version_match = re.search(r"""^__version__ = ['"]([^'"]*)['"]""",
version_file, re.M)
version_match = re.search(
r"""^__version__ = ['"]([^'"]*)['"]""", version_file, re.M
)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")


setup(name="vega_datasets",
version=version('vega_datasets/__init__.py'),
description="A Python package for offline access to Vega datasets",
long_description=read('README.md'),
long_description_content_type="text/markdown",
author="Jake VanderPlas",
author_email="jakevdp@gmail.com",
maintainer="Jake VanderPlas",
maintainer_email="jakevdp@gmail.com",
url='http://github.com/altair-viz/vega_datasets',
download_url='http://github.com/altair-viz/vega_datasets',
license="MIT",
install_requires=["pandas"],
tests_require=["pytest"],
packages=find_packages(exclude=['tools']),
package_data={
'vega_datasets': ['datasets.json',
'dataset_info.json',
'local_datasets.json',
os.path.join('_data', '*.json'),
os.path.join('_data', '*.csv'),
os.path.join('_data', '*.tsv'),
]
},
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
project_urls={
'Bug Reports': 'https://github.com/altair-viz/vega_datasets/issues',
'Source': 'https://github.com/altair-viz/vega_datasets',
},
setup(
name="vega_datasets",
version=version("vega_datasets/__init__.py"),
description="A Python package for offline access to Vega datasets",
long_description=read("README.md"),
long_description_content_type="text/markdown",
author="Jake VanderPlas",
author_email="jakevdp@gmail.com",
maintainer="Jake VanderPlas",
maintainer_email="jakevdp@gmail.com",
url="http://github.com/altair-viz/vega_datasets",
download_url="http://github.com/altair-viz/vega_datasets",
license="MIT",
install_requires=["pandas"],
tests_require=["pytest"],
packages=find_packages(exclude=["tools"]),
package_data={
"vega_datasets": [
"datasets.json",
"dataset_info.json",
"local_datasets.json",
os.path.join("_data", "*.json"),
os.path.join("_data", "*.csv"),
os.path.join("_data", "*.tsv"),
]
},
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
project_urls={
"Bug Reports": "https://github.com/altair-viz/vega_datasets/issues",
"Source": "https://github.com/altair-viz/vega_datasets",
},
)
4 changes: 2 additions & 2 deletions vega_datasets/_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Python 2/3 compatibility
# flake8: noqa

try:
from urllib.error import URLError, HTTPError
Expand All @@ -9,7 +9,7 @@ def bytes_decode(bytes_, encoding="utf-8"):
return bytes_.decode(encoding)


except ImportError:
except ImportError: # noqa: F401
# Python 2.X
from urllib2 import URLError, HTTPError, urlopen
from urllib import urlretrieve
Expand Down
8 changes: 4 additions & 4 deletions vega_datasets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __call__(self, pivoted=False, use_local=True, **kwargs):
data : DataFrame
parsed data
"""
__doc__ = super(Stocks, self).__call__.__doc__
__doc__ = super(Stocks, self).__call__.__doc__ # noqa:F841
data = super(Stocks, self).__call__(use_local=use_local, **kwargs)
if pivoted:
data = data.pivot(index="date", columns="symbol", values="price")
Expand Down Expand Up @@ -336,7 +336,7 @@ class Miserables(Dataset):
"""

def __call__(self, use_local=True, **kwargs):
__doc__ = super(Miserables, self).__call__.__doc__
__doc__ = super(Miserables, self).__call__.__doc__ # noqa:F841
dct = json.loads(bytes_decode(self.raw(use_local=use_local)), **kwargs)
nodes = pd.DataFrame.from_records(dct["nodes"], index="index")
links = pd.DataFrame.from_records(dct["links"])
Expand Down Expand Up @@ -378,7 +378,7 @@ class US_10M(Dataset):
"""

def __call__(self, use_local=True, **kwargs):
__doc__ = super(US_10M, self).__call__.__doc__
__doc__ = super(US_10M, self).__call__.__doc__ # noqa:F841
return json.loads(bytes_decode(self.raw(use_local=use_local)), **kwargs)


Expand All @@ -392,7 +392,7 @@ class World_110M(Dataset):
"""

def __call__(self, use_local=True, **kwargs):
__doc__ = super(World_110M, self).__call__.__doc__
__doc__ = super(World_110M, self).__call__.__doc__ # noqa:F841
return json.loads(bytes_decode(self.raw(use_local=use_local)), **kwargs)


Expand Down
4 changes: 2 additions & 2 deletions vega_datasets/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_undefined_dataset():

def test_undefined_infodict():
with pytest.raises(ValueError) as err:
info = Dataset._infodict("blahblahblah")
Dataset._infodict("blahblahblah")
assert str(err.value).startswith("No such dataset blahblahblah exists")


Expand All @@ -24,7 +24,7 @@ def test_undefined_infodict():
)
def test_local_dataset_error(name):
with pytest.raises(ValueError) as err:
data = local_data(name)
local_data(name)
assert str(err.value).startswith(
"'{0}' dataset is not available locally" "".format(name.replace("-", "_"))
)

0 comments on commit d3bf60a

Please sign in to comment.