Skip to content

Commit

Permalink
Merge pull request #410 from sjsrey/remote
Browse files Browse the repository at this point in the history
Do not poll remotes on init.
  • Loading branch information
sjsrey authored Jun 13, 2021
2 parents 06b57db + 8d8580e commit f75ade3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
12 changes: 8 additions & 4 deletions libpysal/cg/ops/tests/test_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ def test_dissolve(self):
self.assertEqual(out[0].area, 2.0)
self.assertEqual(out[1].area, 2.0)

answer_vertices0 = [(0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (0, 0)]
answer_vertices1 = [(2, 1), (2, 0), (1, 0), (1, 1), (1, 2), (2, 2), (2, 1)]
answer_vertices0 = set([(0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (0, 0)])
answer_vertices1 = set([(2, 1), (2, 0), (1, 0), (1, 1), (1, 2), (2, 2), (2, 1)])

s0 = set([tuple(map(int,t)) for t in out[0].vertices])
s1 = set([tuple(map(int,t)) for t in out[1].vertices])

self.assertTrue(s0==answer_vertices0)
self.assertTrue(s1==answer_vertices1)

np.testing.assert_allclose(out[0].vertices, answer_vertices0)
np.testing.assert_allclose(out[1].vertices, answer_vertices1)

def test_clip(self):
pass
Expand Down
25 changes: 22 additions & 3 deletions libpysal/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@

from .base import example_manager
from .remotes import datasets as remote_datasets
from .remotes import download as fetch_all
from .builtin import datasets as builtin_datasets


from typing import Union

__all__ = ["get_path", "available", "explain", "fetch_all"]

example_manager.add_examples(remote_datasets)
example_manager.add_examples(builtin_datasets)

def fetch_all():
"""Fetch and install all remote datasets
"""
datasets = remote_datasets.datasets
names = list(datasets.keys())
names.sort()
for name in names:
print(name)
example = datasets[name]
try:
example.download()
except:
print("Example not downloaded: {}".format(name))
example_manager.add_examples(datasets)


def available() -> str:
"""List available datasets."""
fetch_all()

return example_manager.available()

Expand All @@ -30,8 +44,13 @@ def explain(name: str) -> str:

def load_example(example_name: str) -> Union[base.Example, builtin.LocalExample]:
"""Load example dataset instance."""
example = example_manager.load(example_name)

if example is None:
fetch_all() # refresh remotes
example = example_manager.load(example_name)

return example_manager.load(example_name)
return example


def get_path(file_name: str) -> str:
Expand Down
25 changes: 11 additions & 14 deletions libpysal/examples/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,17 @@ def poll_remotes():
return datasets


datasets = poll_remotes()
#datasets = poll_remotes()

class Remotes:
def __init__(self):
self._datasets = None

def download(datasets=datasets):
"""
Download all known remotes
"""
@property
def datasets(self):
if self._datasets is None:
self._datasets = poll_remotes()
return self._datasets

datasets = Remotes()

names = list(datasets.keys())
names.sort()
for name in names:
print(name)
example = datasets[name]
try:
example.download()
except:
print("Example not downloaded: {}".format(name))

0 comments on commit f75ade3

Please sign in to comment.