Skip to content

Commit

Permalink
Merge pull request #259 from Juanlu001/python-3-8
Browse files Browse the repository at this point in the history
Add support for Python 3.8
  • Loading branch information
astrojuanlu authored Jan 21, 2020
2 parents ec9f4dd + 51a2ecd commit 99a5955
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "nightly"

branches:
Expand All @@ -17,9 +18,12 @@ matrix:
- python: "nightly"

before_install:
- pip install pycodestyle mypy==0.670 # See https://github.com/python/mypy/issues/6564
- pip install pycodestyle
- pycodestyle . --count
- mypy --ignore-missing-imports --check-untyped-defs telluric/
- if [[ $TRAVIS_PYTHON_VERSION != "3.4" ]]; then
pip install mypy;
mypy --ignore-missing-imports --check-untyped-defs telluric/;
fi

install:
- pip install numpy # Required
Expand Down
2 changes: 1 addition & 1 deletion telluric/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def key(feature):
return feature[by]

sorted_features = sorted(list(self), reverse=desc, key=key)
return self.__class__(sorted_features)
return FeatureCollection(sorted_features)

def groupby(self, by):
# type: (Union[str, Callable[[GeoFeature], str]]) -> _CollectionGroupBy
Expand Down
7 changes: 3 additions & 4 deletions telluric/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"""
import logging
import threading
from typing import Optional


class ThreadContext(threading.local):
def __init__(self):
# Initializes in each thread
self._options = None # type: Optional[dict]
self._options = {}

def get(self, key, default=None):
return self._options.get(key, default)
Expand Down Expand Up @@ -104,7 +103,7 @@ def from_defaults(cls, **kwargs):
def __enter__(self):
log.debug("Entering env context: %r", self)
# No parent TelluricContext exists.
if local_context._options is None:
if not local_context._options:
log.debug("Starting outermost env")
self._has_parent_env = False

Expand Down Expand Up @@ -157,4 +156,4 @@ def del_context():
"""Delete options in the existing context."""
if not local_context._options:
raise TelluricContextError("TelluricContext context not exists")
local_context._options = None
local_context._options.clear()
6 changes: 4 additions & 2 deletions telluric/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ def plot(feature, mp=None, style_function=None, **map_kwargs):

class NotebookPlottingMixin:
def _run_in_tileserver(self, capture):
TileServer.run_tileserver(self, self.envelope)
mp = TileServer.folium_client(self, self.envelope, capture=capture)
# Variable annotation syntax is only available in Python >= 3.6,
# so we cannot declare an envelope property here
TileServer.run_tileserver(self, self.envelope) # type: ignore
mp = TileServer.folium_client(self, self.envelope, capture=capture) # type: ignore
return mp._repr_html_()

def _repr_html_(self):
Expand Down
3 changes: 2 additions & 1 deletion telluric/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ def get_bounds(self, crs):

def get_bounding_box(self, crs):
"""Gets bounding box as GeoVector in a specified CRS."""
return self.from_bounds(*self.get_bounds(crs), crs=crs)
# https://github.com/python/mypy/issues/6799
return self.from_bounds(*self.get_bounds(crs), crs=crs) # type: ignore

def _repr_svg_(self):
return self._shape._repr_svg_()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_telluric_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_context_in_one_level():
assert local_context.get('b') == 2
assert local_context.get('c') == 'stam'
assert local_context.get('d') == {'a': 'a', 'b': 'b'}
assert local_context._options is None
assert local_context._options == {}


def test_context_in_two_level():
Expand All @@ -23,7 +23,7 @@ def test_context_in_two_level():
assert local_context.get('b') == 2
assert local_context.get('c') == 'stam'
assert local_context.get('d') == {'a': 'a', 'b': 'b'}
assert local_context._options is None
assert local_context._options == {}


def test_different_context_on_different_threads():
Expand All @@ -39,7 +39,7 @@ def thread_test_1():
assert local_context.get('d') == {'a': 'a', 'b': 'b'}
assert local_context.get('x') is None
assert local_context.get('y') is None
assert local_context._options is None
assert local_context._options == {}

def thread_test_2():
with TelluricContext(a=4, b=5, x='something', y=13):
Expand All @@ -50,13 +50,13 @@ def thread_test_2():
assert local_context.get('c') is None
assert local_context.get('d') is None
sleep(0.1)
assert local_context._options is None
assert local_context._options == {}

t1 = threading.Thread(target=thread_test_1)
t2 = threading.Thread(target=thread_test_2)
t1.start()
t2.start()
assert local_context._options is None
assert local_context._options == {}
t1.join()
t2.join()
assert local_context._options is None
assert local_context._options == {}

0 comments on commit 99a5955

Please sign in to comment.