Skip to content

Commit 3a99529

Browse files
author
Joe Hamman
authored
add ISSUE_TEMPLATE for github and xr.show_versions() (#1485)
* add ISSUE_TEMPLATE for github and xr.show_versions() * fix Nio import * print version info on appveyor * use mod.__version__ for numpy/scipy * add CONTRIBUTING.md * whats new * fix whatsnew * update flake8 prompt to only run on python sources * update travis to run flak8 * fix flake8 * flake8 fix
1 parent 1436509 commit 3a99529

20 files changed

+231
-5
lines changed

.github/CONTRIBUTING.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Contributing to xarray
2+
3+
## Usage questions
4+
5+
The best places to submit questions about how to use xarray are
6+
[Stack Overflow](https://stackoverflow.com/questions/tagged/python-xarray) and
7+
the [xarray Google group](https://groups.google.com/forum/#!forum/xarray).
8+
9+
## Reporting issues
10+
11+
When reporting issues please include as much detail as possible about your
12+
operating system, xarray version and python version. Whenever possible, please
13+
also include a brief, self-contained code example that demonstrates the problem.
14+
15+
## Contributing code
16+
17+
Thanks for your interest in contributing code to xarray!
18+
19+
- If you are new to Git or Github, please take a minute to read through a few tutorials
20+
on [Git](https://git-scm.com/docs/gittutorial) and [GitHub](https://guides.github.com/).
21+
- The basic workflow for contributing to xarray is:
22+
1. [Fork](https://help.github.com/articles/fork-a-repo/) the xarray repository
23+
2. [Clone](https://help.github.com/articles/cloning-a-repository/) the xarray repository to create a local copy on your computer:
24+
```
25+
git clone [email protected]:${user}/xarray.git
26+
cd xarray
27+
```
28+
3. Create a branch for your changes
29+
```
30+
git checkout -b name-of-your-branch
31+
```
32+
4. Make change to your local copy of the xarray repository
33+
5. Commit those changes
34+
```
35+
git add file1 file2 file3
36+
git commit -m 'a descriptive commit message'
37+
```
38+
6. Push your updated branch to your fork
39+
```
40+
git push origin name-of-your-branch
41+
```
42+
7. [Open a pull request](https://help.github.com/articles/creating-a-pull-request/) to the pydata/xarray repository.

.github/ISSUE_TEMPLATE.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#### Code Sample, a copy-pastable example if possible
2+
3+
```python
4+
# Your code here
5+
6+
```
7+
#### Problem description
8+
9+
[this should explain **why** the current behavior is a problem and why the expected output is a better solution.]
10+
11+
#### Expected Output
12+
13+
#### Output of ``xr.show_versions()``
14+
15+
<details>
16+
# Paste the output here xr.show_versions() here
17+
18+
</details>

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
- [ ] Closes #xxxx
22
- [ ] Tests added / passed
3-
- [ ] Passes ``git diff upstream/master | flake8 --diff``
3+
- [ ] Passes ``git diff upstream/master **/*py | flake8 --diff``
44
- [ ] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ install:
8686
- source activate test_env
8787
- conda list
8888
- python setup.py install
89+
- python xarray/util/print_versions.py
8990

9091
script:
9192
- py.test xarray --cov=xarray --cov-config ci/.coveragerc --cov-report term-missing --verbose $EXTRA_FLAGS
93+
- git diff upstream/master **/*py | flake8 --diff --exit-zero || true
9294

9395
after_success:
9496
- coveralls

appveyor.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ install:
3131
# the parent CMD process).
3232
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
3333

34-
# Check that we have the expected version and architecture for Python
35-
- "python --version"
36-
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
37-
3834
# install xarray and dependencies
3935
- "conda env create --file ./ci/requirements-%CONDA_ENV%.yml"
4036
- "activate test_env"
4137
- "conda list"
4238
- "python setup.py install"
39+
- "python xarray/util/print_versions.py"
4340

4441
build: false
4542

ci/requirements-py27-cdat+pynio.yml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies:
1616
- pathlib2
1717
- pynio
1818
- pytest
19+
- flake8
1920
- mock
2021
- scipy
2122
- seaborn

ci/requirements-py27-min.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: test_env
22
dependencies:
33
- python=2.7
44
- pytest
5+
- flake8
56
- mock
67
- numpy==1.11
78
- pandas==0.18.0

ci/requirements-py27-windows.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
- netcdf4
1212
- pathlib2
1313
- pytest
14+
- flake8
1415
- mock
1516
- numpy
1617
- pandas

ci/requirements-py34.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dependencies:
33
- python=3.4
44
- bottleneck
55
- pytest
6+
- flake8
67
- pandas
78
- pip:
89
- coveralls

ci/requirements-py35.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
- matplotlib
1111
- netcdf4
1212
- pytest
13+
- flake8
1314
- numpy
1415
- pandas
1516
- scipy

ci/requirements-py36-bottleneck-dev.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
- matplotlib
1111
- netcdf4
1212
- pytest
13+
- flake8
1314
- numpy
1415
- pandas
1516
- scipy

ci/requirements-py36-condaforge-rc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
- matplotlib
1212
- netcdf4
1313
- pytest
14+
- flake8
1415
- numpy
1516
- pandas
1617
- seaborn

ci/requirements-py36-dask-dev.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies:
88
- matplotlib
99
- netcdf4
1010
- pytest
11+
- flake8
1112
- numpy
1213
- pandas
1314
- seaborn

ci/requirements-py36-netcdf4-dev.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
- h5netcdf
1111
- matplotlib
1212
- pytest
13+
- flake8
1314
- numpy
1415
- pandas
1516
- scipy

ci/requirements-py36-pandas-dev.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
- matplotlib
1212
- netcdf4
1313
- pytest
14+
- flake8
1415
- numpy
1516
- scipy
1617
- toolz

ci/requirements-py36.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
- matplotlib
1111
- netcdf4
1212
- pytest
13+
- flake8
1314
- numpy
1415
- pandas
1516
- scipy

doc/whats-new.rst

+4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ Enhancements
217217
(:issue:`576`).
218218
By `Stephan Hoyer <https://github.com/shoyer>`_.
219219

220+
- Added :py:func:`~xarray.show_versions` function to aid in debugging
221+
(:issue:`1485`).
222+
By `Joe Hamman` <https://github.com/jhamman>`_.
223+
220224
- Support using an existing, opened netCDF4 ``Dataset`` with
221225
:py:class:`~xarray.backends.NetCDF4DataStore`. This permits creating an
222226
:py:class:`~xarray.Dataset` from a netCDF4 ``Dataset`` that has been opened using

xarray/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'the source directory, please instead create a new '
2929
'virtual environment (using conda or virtualenv) and '
3030
'then install it in-place by running: pip install -e .')
31+
from .util.print_versions import show_versions
3132

3233
from . import tutorial
3334
from . import ufuncs

xarray/util/__init__.py

Whitespace-only changes.

xarray/util/print_versions.py

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
'''utility functions for printing version information
2+
3+
4+
see pandas/pandas/util/_print_versions.py'''
5+
import os
6+
import platform
7+
import sys
8+
import struct
9+
import subprocess
10+
import codecs
11+
import locale
12+
import importlib
13+
14+
15+
def get_sys_info():
16+
"Returns system information as a dict"
17+
18+
blob = []
19+
20+
# get full commit hash
21+
commit = None
22+
if os.path.isdir(".git") and os.path.isdir("xarray"):
23+
try:
24+
pipe = subprocess.Popen('git log --format="%H" -n 1'.split(" "),
25+
stdout=subprocess.PIPE,
26+
stderr=subprocess.PIPE)
27+
so, serr = pipe.communicate()
28+
except:
29+
pass
30+
else:
31+
if pipe.returncode == 0:
32+
commit = so
33+
try:
34+
commit = so.decode('utf-8')
35+
except ValueError:
36+
pass
37+
commit = commit.strip().strip('"')
38+
39+
blob.append(('commit', commit))
40+
41+
try:
42+
(sysname, nodename, release,
43+
version, machine, processor) = platform.uname()
44+
blob.extend([
45+
("python", "%d.%d.%d.%s.%s" % sys.version_info[:]),
46+
("python-bits", struct.calcsize("P") * 8),
47+
("OS", "%s" % (sysname)),
48+
("OS-release", "%s" % (release)),
49+
# ("Version", "%s" % (version)),
50+
("machine", "%s" % (machine)),
51+
("processor", "%s" % (processor)),
52+
("byteorder", "%s" % sys.byteorder),
53+
("LC_ALL", "%s" % os.environ.get('LC_ALL', "None")),
54+
("LANG", "%s" % os.environ.get('LANG', "None")),
55+
("LOCALE", "%s.%s" % locale.getlocale()),
56+
57+
])
58+
except:
59+
pass
60+
61+
return blob
62+
63+
64+
def show_versions(as_json=False):
65+
sys_info = get_sys_info()
66+
67+
deps = [
68+
# (MODULE_NAME, f(mod) -> mod version)
69+
("xarray", lambda mod: mod.__version__),
70+
("pandas", lambda mod: mod.__version__),
71+
("numpy", lambda mod: mod.__version__),
72+
("scipy", lambda mod: mod.__version__),
73+
# xarray optionals
74+
("netCDF4", lambda mod: mod.__version__),
75+
# ("pydap", lambda mod: mod.version.version),
76+
("h5netcdf", lambda mod: mod.__version__),
77+
("Nio", lambda mod: mod.__version__),
78+
("bottleneck", lambda mod: mod.__version__),
79+
("cyordereddict", lambda mod: mod.__version__),
80+
("dask", lambda mod: mod.__version__),
81+
("matplotlib", lambda mod: mod.__version__),
82+
("cartopy", lambda mod: mod.__version__),
83+
("seaborn", lambda mod: mod.__version__),
84+
# xarray setup/test
85+
("setuptools", lambda mod: mod.__version__),
86+
("pip", lambda mod: mod.__version__),
87+
("conda", lambda mod: mod.__version__),
88+
("pytest", lambda mod: mod.__version__),
89+
# Misc.
90+
("IPython", lambda mod: mod.__version__),
91+
("sphinx", lambda mod: mod.__version__),
92+
]
93+
94+
deps_blob = list()
95+
for (modname, ver_f) in deps:
96+
try:
97+
if modname in sys.modules:
98+
mod = sys.modules[modname]
99+
else:
100+
mod = importlib.import_module(modname)
101+
ver = ver_f(mod)
102+
deps_blob.append((modname, ver))
103+
except:
104+
deps_blob.append((modname, None))
105+
106+
if (as_json):
107+
try:
108+
import json
109+
except:
110+
import simplejson as json
111+
112+
j = dict(system=dict(sys_info), dependencies=dict(deps_blob))
113+
114+
if as_json is True:
115+
print(j)
116+
else:
117+
with codecs.open(as_json, "wb", encoding='utf8') as f:
118+
json.dump(j, f, indent=2)
119+
120+
else:
121+
122+
print("\nINSTALLED VERSIONS")
123+
print("------------------")
124+
125+
for k, stat in sys_info:
126+
print("%s: %s" % (k, stat))
127+
128+
print("")
129+
for k, stat in deps_blob:
130+
print("%s: %s" % (k, stat))
131+
132+
133+
def main():
134+
from optparse import OptionParser
135+
parser = OptionParser()
136+
parser.add_option("-j", "--json", metavar="FILE", nargs=1,
137+
help="Save output as JSON into file, pass in "
138+
"'-' to output to stdout")
139+
140+
(options, args) = parser.parse_args()
141+
142+
if options.json == "-":
143+
options.json = True
144+
145+
show_versions(as_json=options.json)
146+
147+
return 0
148+
149+
150+
if __name__ == "__main__":
151+
sys.exit(main())

0 commit comments

Comments
 (0)