Skip to content

Commit 4eee5cb

Browse files
Ready: Fix examples download cli cmd (#349)
* edit versioning in setup.py to fix examples download issue * edit manifest to pass travis * edit manifest, setup, and version to fix versioning and include for conda build * fix versioning: single source of truth from setup.py param get_setup_version; split version string for conda and pip install; set check manifest ignore xrspatial/examples in pyproject.toml * check tag for version * add change for tags * test git tags for version source * flake8 setup.py fix indent * test out single-source version from tags * fix versioning for pip packaging and put explicit version in conda.recipe meta.yaml. Add test script for pip packaging new version generation and examples download * add line in MANIFEST * add gitattributes * edit versioning formatting and add test pip packaging edits * placate flake8 * give it back to xrs Co-authored-by: Brendan Collins <brendan@makepath.com>
1 parent 9b7f44d commit 4eee5cb

File tree

10 files changed

+143
-20
lines changed

10 files changed

+143
-20
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__init__.py export-subst
2+
setup.py export-subst

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ share/python-wheels/
2828
MANIFEST
2929
xrspatial/_version.py
3030

31+
3132
# PyInstaller
3233
# Usually these files are written by a python script from a template
3334
# before PyInstaller builds the exe, so as to inject date/other infos into it.

MANIFEST.in

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ include *.txt
22
include *.md
33

44
graft xrspatial
5+
graft xrspatial/examples
6+
graft xrspatial/examples/user_guide
57

68
prune docs
79
prune *.egg-info
@@ -11,13 +13,15 @@ prune conda.recipe
1113
prune img
1214
prune .idea
1315

14-
include xrspatial/examples/*
15-
include xrspatial/examples/user_guide/*
16-
1716
exclude examples/.ipynb_checkpoints/*
17+
exclude examples/user_guide/.ipynb_checkpoints/*
1818
exclude xrspatial/_version.py
19+
exclude xrspatial/.DS_Store
20+
exclude xrspatial/.version
1921
exclude xrspatial/__pycache__/*
20-
exclude xrspatial/examples/user_guide_idea/*
22+
exclude xrspatial/tests/__pycache__/*
23+
exclude xrspatial/tests/.DS_Store
24+
exclude xrspatial/tests/_qgis_results/__pycache__/*
2125
exclude tile_idea.py
2226
exclude *.enc
2327
exclude .gitignore
@@ -32,4 +36,6 @@ include *.yml
3236
recursive-include examples *.gif
3337
recursive-include examples *.ipynb
3438
recursive-include examples *.py
35-
recursive-include examples *.yml
39+
recursive-include examples *.yml
40+
recursive-include test_pip_packaging *.py
41+
recursive-include test_pip_packaging *.sh

conda.recipe/meta.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22

33
package:
44
name: xarray-spatial
5-
version: 0.2.0
5+
version: "0.2.0"
6+
67

78
source:
89
path: ..
910

1011
requirements:
1112
host:
1213
- python
13-
- setuptools
14+
- setuptools >=46.4.0
1415
- pyct
16+
- param
1517
run:
1618
- python
1719
{% for dep in sdata.get('install_requires', {}) %}
1820
- {{ dep }}
1921
{% endfor %}
2022

21-
# will need the extras_require['tests'] deps below once those are added in setup.py
2223
test:
2324
requires:
2425
- pytest >=2.8.5
25-
# {% for dep in sdata['extras_require']['tests'] %}
26-
# - {{ dep }}
27-
# {% endfor %}
26+
{% for dep in sdata['extras_require']['tests'] %}
27+
- {{ dep }}
28+
{% endfor %}
2829
imports:
2930
- xrspatial
3031

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ requires = [
33
'pyct >= 0.4.8',
44
'setuptools >= 54.1.2',
55
'wheel >= 0.36.2',
6-
]
6+
]
7+
[tool.check-manifest]
8+
ignore = ["xrspatial/examples/*", "xrspatial/examples/user_guide/*"]

setup.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import shutil
44
from setuptools import setup
55

6+
67
# build dependencies
78
import pyct.build
9+
import param
810

911
# dependencies
1012

@@ -23,6 +25,8 @@
2325
'scipy',
2426
'xarray',
2527
'pyct <=0.4.6',
28+
'param >=1.6.1',
29+
'distributed >=2021.03.0',
2630
'spatialpandas'
2731
]
2832

@@ -42,15 +46,25 @@
4246

4347
extras_require['all'] = sorted(set(sum(extras_require.values(), [])))
4448

49+
version = param.version.get_setup_version(__file__, 'xarray-spatial',
50+
pkgname='xrspatial',
51+
archive_commit="$Format:%h$")
52+
53+
if 'sdist' in sys.argv and 'bdist_wheel' in sys.argv:
54+
try:
55+
version_test = version.split('.post')[1]
56+
version = version.split('.post')[0]
57+
except IndexError:
58+
version = version.split('+')[0]
59+
if version is None:
60+
sys.exit('invalid version')
61+
62+
4563
# metadata for setuptools
4664

4765
setup_args = dict(
4866
name='xarray-spatial',
49-
use_scm_version={
50-
'write_to': 'xrspatial/_version.py',
51-
'write_to_template': '__version__ = "{version}"',
52-
'tag_regex': r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
53-
},
67+
version=version,
5468
description='xarray-based spatial analysis tools',
5569
install_requires=install_requires,
5670
extras_require=extras_require,
@@ -70,9 +84,10 @@
7084
},
7185
)
7286

87+
7388
if __name__ == '__main__':
7489
example_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
75-
'xarray-spatial', 'examples')
90+
'xrspatial', 'examples')
7691
if 'develop' not in sys.argv:
7792
pyct.build.examples(example_path, __file__, force=True)
7893
setup(**setup_args)

test_pip_packaging/gen_tags.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import sys
3+
import param
4+
5+
6+
version_before = param.version.get_setup_version(
7+
os.path.dirname(__file__),
8+
'xarray-spatial',
9+
pkgname='xrspatial',
10+
archive_commit="$Format:%h$")
11+
12+
version_digits = None
13+
14+
try:
15+
version_digits_test = version_before.split('.post')[1]
16+
version_digits = version_before.split('.post')[0]
17+
except IndexError:
18+
version_digits = version_before.rsplit('+')[0]
19+
20+
if version_digits is None:
21+
sys.exit('version digits not found; '
22+
'check your git tags with cmd: git tag -l')
23+
24+
digits_list = version_digits.split('.')
25+
26+
if len(digits_list) < 3:
27+
sys.exit('less than 3 digits in version')
28+
elif len(digits_list) == 4:
29+
last_digit = digits_list[-1]
30+
first_digits = '.'.join(digits_list[0], digits_list[1], digits_list[2])
31+
elif len(digits_list) == 3:
32+
last_digit = '0'
33+
first_digits = version_digits
34+
35+
next_version = '.'.join([first_digits, str(int(last_digit) + 1)])
36+
37+
if (len(next_version.split('.')) < 4 or
38+
len(next_version.rsplit('.', 1)[0].split('.')) != 3):
39+
sys.exit(f"next version not formatted correctly {next_version}")
40+
41+
print(f'v{next_version}')
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# generates new package version, builds pip package,
4+
# uploads to pypi, creates new env and new dir,
5+
# installs xarray-spatial, runs examples, and ls
6+
# to see if correct files are in folder
7+
8+
# clear previous build detritus
9+
rm -rf build/
10+
rm -rf dist/
11+
rm -rf xarray_spatial_*
12+
rm -f xrspatial/.version
13+
14+
15+
# change name of package
16+
17+
18+
# add tag
19+
version="$(python test_pip_packaging/gen_tags.py)"
20+
echo "$version"
21+
git tag -a "$version" -m new
22+
git push origin "$version"
23+
24+
25+
# clear previous tag
26+
#last_version="$(git describe --abbrev=0 --tags "$(git rev-list --tags --skip=1 --max-count=1)")"
27+
#echo "$last_version"
28+
#git tag -d "$last_version"
29+
#git push --delete origin "$last_version"
30+
31+
32+
# run sdist and upload twine
33+
python setup.py sdist bdist_wheel
34+
twine upload --username="$username" --password="$password" dist/*
35+
36+
37+
# test out in new env
38+
# conda deactivate
39+
# cd ..
40+
# mkdir test_cli || cd .
41+
# cd test_cli || exit
42+
# rm -rf xrspatial-examples
43+
# conda deactivate
44+
# conda create -n test_cli -y
45+
# conda activate test_cli
46+
# conda install -c anaconda pip -y
47+
# version_arr=(${version//v/ })
48+
# version_num=${version_arr[1]}
49+
# sleep 10s
50+
# pip install xarray-spatial=="$version_num"
51+
# xrspatial examples
52+
# pip uninstall xarray-spatial -y
53+
# ls xrspatial-examples
54+
# conda deactivate
55+
# cd ../xarray-spatial || exit

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ envlist = py{36,37,38}
55

66
[testenv]
77
description = Unit tests
8-
deps = -rrequirements.txt
8+
deps = requirements.txt
99
commands = pytest

xrspatial/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from xrspatial.pathfinding import a_star_search # noqa
4343

4444
try:
45-
from ._version import __version__
45+
from .version import __version__
4646
except ImportError:
4747
__version__ = "unknown"
4848

0 commit comments

Comments
 (0)