Skip to content

Commit 75aac0b

Browse files
authored
Add download-examples CLI command for all notebooks (#241)
1 parent 428b4af commit 75aac0b

File tree

11 files changed

+288
-52
lines changed

11 files changed

+288
-52
lines changed

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ prune examples
1212
prune img
1313

1414
exclude xrspatial/_version.py
15+
exclude xrspatial/__pycache__/*
16+
exclude xrspatial/examples/*
17+
exclude xrspatial/examples/user_guide/*
18+
exclude xrspatial/examples/user_guide_idea/*
1519
exclude tile_idea.py
1620
exclude *.yml
1721
exclude *.enc
@@ -21,3 +25,4 @@ exclude *.dot
2125
exclude *.gif
2226
exclude *.svg
2327
exclude tox.ini
28+
exclude test_examples_cli.py

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,4 @@ With the introduction of projects like Numba, Python gained new ways to provide
205205
- @chase-dwelle
206206
- @SAN154
207207
- @SapirLastimoza-Dooley
208+
- @lex-c

conda.recipe/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
set -e
44
set -x
55

6-
BLD_DIR=`pwd`
7-
6+
BLD_DIR='pwd'
87
SRC_DIR=$RECIPE_DIR/..
98
pushd $SRC_DIR
109

conda.recipe/meta.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1+
{% set sdata = load_setup_py_data() %}
12

23
package:
34
name: xarray-spatial
45
version: 0.1.2
56

7+
source:
8+
path: ..
9+
610
requirements:
7-
build:
11+
host:
812
- python
913
- setuptools
10-
14+
- pyct
1115
run:
1216
- python
13-
- datashader
17+
{% for dep in sdata.get('install_requires', {}) %}
18+
- {{ dep }}
19+
{% endfor %}
1420

21+
# will need the extras_require['tests'] deps below once those are added in setup.py
1522
test:
1623
requires:
1724
- pytest >=2.8.5
25+
# {% for dep in sdata['extras_require']['tests'] %}
26+
# - {{ dep }}
27+
# {% endfor %}
1828
imports:
1929
- xrspatial
2030

examples/datasets.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
3+
data:
4+
- url: https://xarrayspatial.blob.core.windows.net/examples-data/facilities.csv
5+
title: 'Pharmacy Facilities Data'
6+
files:
7+
- facilities.csv
8+
- url: https://xarrayspatial.blob.core.windows.net/examples-data/USA_Block_Groups-shp.zip/USA_Block_Groups.shp
9+
title: 'USA Block Groups Shapefile'
10+
files:
11+
- USA_Block_Groups.shp
12+
- url: https://xarrayspatial.blob.core.windows.net/examples-data/USA_Counties-shp.zip/USA_Counties.shp
13+
title: 'USA Counties Shapefile'
14+
files:
15+
- USA_Counties.shp

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
'pyct >= 0.4.8',
4+
'setuptools >= 54.1.2',
5+
'wheel >= 0.36.2',
6+
]

record.txt

Lines changed: 98 additions & 0 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,80 @@
1+
import os, sys
2+
import shutil
13
from setuptools import setup
4+
import pkg_resources
25

6+
# build dependencies
7+
import pyct.build
38

4-
setup(name='xarray-spatial',
5-
use_scm_version={
6-
"write_to": "xrspatial/_version.py",
7-
"write_to_template": '__version__ = "{version}"',
8-
"tag_regex": r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$",
9-
},
10-
description='xarray-based spatial analysis tools',
11-
packages=['xrspatial',
12-
'xrspatial.tests'],
13-
install_requires=[
14-
'dask',
15-
'datashader',
16-
'numba',
17-
'numpy',
18-
'pandas',
19-
'pillow',
20-
'requests',
21-
'scipy',
22-
'xarray',
23-
],
24-
zip_safe=False,
25-
classifiers=["Programming Language :: Python :: 3",
26-
"License :: OSI Approved :: MIT License",
27-
"Operating System :: OS Independent"],
28-
include_package_data=True)
9+
# dependencies
10+
11+
# datashader first, then pyct unless pyct version compatible with ds is specified
12+
# spatialpandas may not be required in final pharmacy_desert version
13+
# pyct may not be required after pyctdev is released
14+
install_requires = [
15+
'dask',
16+
'datashader',
17+
'numba',
18+
'numpy',
19+
'pandas',
20+
'pillow',
21+
'requests',
22+
'scipy',
23+
'xarray',
24+
'pyct',
25+
]
26+
27+
examples = [
28+
'spatialpandas',
29+
]
30+
31+
# Additional tests dependencies and examples_extra may be needed in the future
32+
extras_require = {
33+
'tests': [
34+
'pytest',
35+
],
36+
'examples': examples,
37+
}
38+
39+
# additional doc dependencies may be needed
40+
extras_require['doc'] = extras_require['examples'] + ['numpydoc']
41+
42+
extras_require['all'] = sorted(set(sum(extras_require.values(), [])))
43+
44+
# metadata for setuptools
45+
46+
setup_args = dict(
47+
name='xarray-spatial',
48+
use_scm_version={
49+
"write_to": "xrspatial/_version.py",
50+
"write_to_template": '__version__ = "{version}"',
51+
"tag_regex": r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$",
52+
},
53+
description='xarray-based spatial analysis tools',
54+
install_requires=install_requires,
55+
extras_require=extras_require,
56+
tests_require=extras_require['tests'],
57+
zip_safe=False,
58+
classifiers=["Programming Language :: Python :: 3",
59+
"License :: OSI Approved :: MIT License",
60+
"Operating System :: OS Independent"],
61+
packages=['xrspatial',
62+
'xrspatial.tests'
63+
],
64+
include_package_data=True,
65+
entry_points={
66+
'console_scripts': [
67+
'xrspatial = xrspatial.__main__:main'
68+
]
69+
},
70+
)
71+
72+
if __name__ == '__main__':
73+
example_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
74+
'xrspatial', 'examples')
75+
if 'develop' not in sys.argv:
76+
pyct.build.examples(example_path, __file__, force=True)
77+
setup(**setup_args)
78+
79+
if os.path.isdir(example_path):
80+
shutil.rmtree(example_path)

test_examples_cli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
from xrspatial import __main__ as m
3+
from unittest.mock import patch
4+
5+
6+
# test_args include copy-examples, fetch-data, or examples (does both)
7+
def run_examples_cmds(*cli_cmds):
8+
9+
"""
10+
11+
Run conda package cli commands to download examples and fetch data for notebooks
12+
Parameters: 'copy-examples', 'fetch-data', 'examples'
13+
Output: downloads examples and data to new xrspatial-examples directory in xarray-spatial
14+
15+
"""
16+
17+
for arg in cli_cmds:
18+
with patch.object(sys, 'argv', ['xrspatial', arg]):
19+
m.main()
20+
21+
run_examples_cmds('examples')

xrspatial/__main__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
3+
def main(args=None):
4+
try:
5+
import pyct.cmd
6+
except ImportError:
7+
import sys
8+
from . import _missing_cmd
9+
print(_missing_cmd())
10+
sys.exit(1)
11+
return pyct.cmd.substitute_main('xrspatial',args=args)
12+
13+
if __name__ == "__main__":
14+
main()

0 commit comments

Comments
 (0)