Skip to content

add ISSUE_TEMPLATE for github and xr.show_versions() #1485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#### Code Sample, a copy-pastable example if possible

```python
# Your code here

```
#### Problem description

[this should explain **why** the current behavior is a problem and why the expected output is a better solution.]

#### Expected Output

#### Output of ``xr.show_versions()``

<details>
# Paste the output here xr.show_versions() here

</details>
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ install:
conda remove scipy;
fi
- python setup.py install
- python xarray/util/print_versions.py

script:
- py.test xarray --cov=xarray --cov-report term-missing --verbose $EXTRA_FLAGS
Expand Down
5 changes: 1 addition & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ install:
# the parent CMD process).
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"

# Check that we have the expected version and architecture for Python
- "python --version"
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""

# install xarray and dependencies
- "conda env create --file ./ci/requirements-%CONDA_ENV%.yml"
- "activate test_env"
- "python setup.py install"
- "python xarray/util/print_versions.py"

build: false

Expand Down
1 change: 1 addition & 0 deletions xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'the source directory, please instead create a new '
'virtual environment (using conda or virtualenv) and '
'then install it in-place by running: pip install -e .')
from .util.print_versions import show_versions

from . import tutorial
from . import ufuncs
Expand Down
Empty file added xarray/util/__init__.py
Empty file.
151 changes: 151 additions & 0 deletions xarray/util/print_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
'''utility functions for printing version information


see pandas/pandas/util/_print_versions.py'''
import os
import platform
import sys
import struct
import subprocess
import codecs
import locale
import importlib


def get_sys_info():
"Returns system information as a dict"

blob = []

# get full commit hash
commit = None
if os.path.isdir(".git") and os.path.isdir("xarray"):
try:
pipe = subprocess.Popen('git log --format="%H" -n 1'.split(" "),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
so, serr = pipe.communicate()
except:
pass
else:
if pipe.returncode == 0:
commit = so
try:
commit = so.decode('utf-8')
except ValueError:
pass
commit = commit.strip().strip('"')

blob.append(('commit', commit))

try:
(sysname, nodename, release,
version, machine, processor) = platform.uname()
blob.extend([
("python", "%d.%d.%d.%s.%s" % sys.version_info[:]),
("python-bits", struct.calcsize("P") * 8),
("OS", "%s" % (sysname)),
("OS-release", "%s" % (release)),
# ("Version", "%s" % (version)),
("machine", "%s" % (machine)),
("processor", "%s" % (processor)),
("byteorder", "%s" % sys.byteorder),
("LC_ALL", "%s" % os.environ.get('LC_ALL', "None")),
("LANG", "%s" % os.environ.get('LANG', "None")),
("LOCALE", "%s.%s" % locale.getlocale()),

])
except:
pass

return blob


def show_versions(as_json=False):
sys_info = get_sys_info()

deps = [
# (MODULE_NAME, f(mod) -> mod version)
("xarray", lambda mod: mod.__version__),
("pandas", lambda mod: mod.__version__),
("numpy", lambda mod: mod.version.version),
("scipy", lambda mod: mod.version.version),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use mod.__version__ for numpy and scipy? That's the more standard way to access this information.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that works. Done.

# xarray optionals
("netCDF4", lambda mod: mod.__version__),
# ("pydap", lambda mod: mod.version.version),
("h5netcdf", lambda mod: mod.__version__),
("Nio", lambda mod: mod.__version__),
("bottleneck", lambda mod: mod.__version__),
("cyordereddict", lambda mod: mod.__version__),
("dask", lambda mod: mod.__version__),
("matplotlib", lambda mod: mod.__version__),
("cartopy", lambda mod: mod.__version__),
("seaborn", lambda mod: mod.__version__),
# xarray setup/test
("setuptools", lambda mod: mod.__version__),
("pip", lambda mod: mod.__version__),
("conda", lambda mod: mod.__version__),
("pytest", lambda mod: mod.__version__),
# Misc.
("IPython", lambda mod: mod.__version__),
("sphinx", lambda mod: mod.__version__),
]

deps_blob = list()
for (modname, ver_f) in deps:
try:
if modname in sys.modules:
mod = sys.modules[modname]
else:
mod = importlib.import_module(modname)
ver = ver_f(mod)
deps_blob.append((modname, ver))
except:
deps_blob.append((modname, None))

if (as_json):
try:
import json
except:
import simplejson as json

j = dict(system=dict(sys_info), dependencies=dict(deps_blob))

if as_json is True:
print(j)
else:
with codecs.open(as_json, "wb", encoding='utf8') as f:
json.dump(j, f, indent=2)

else:

print("\nINSTALLED VERSIONS")
print("------------------")

for k, stat in sys_info:
print("%s: %s" % (k, stat))

print("")
for k, stat in deps_blob:
print("%s: %s" % (k, stat))


def main():
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-j", "--json", metavar="FILE", nargs=1,
help="Save output as JSON into file, pass in "
"'-' to output to stdout")

(options, args) = parser.parse_args()

if options.json == "-":
options.json = True

show_versions(as_json=options.json)

return 0


if __name__ == "__main__":
sys.exit(main())