Skip to content

Commit 31d5d0f

Browse files
committedMar 17, 2015
Merge pull request #377 from xray/appveyor
Add Appveyor for CI on Windows
2 parents 4ca0860 + a8b5a5d commit 31d5d0f

File tree

5 files changed

+132
-51
lines changed

5 files changed

+132
-51
lines changed
 

‎appveyor.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# CI on Windows via appveyor
2+
# This file was based on Olivier Grisel's python-appveyor-demo
3+
4+
environment:
5+
6+
matrix:
7+
- PYTHON: "C:\\Python27-conda32"
8+
PYTHON_VERSION: "2.7"
9+
PYTHON_ARCH: "32"
10+
11+
- PYTHON: "C:\\Python34-conda64"
12+
PYTHON_VERSION: "3.4"
13+
PYTHON_ARCH: "64"
14+
15+
install:
16+
# Install miniconda Python
17+
- "powershell ./ci/install_python.ps1"
18+
19+
# Prepend newly installed Python to the PATH of this build (this cannot be
20+
# done from inside the powershell script as it would require to restart
21+
# the parent CMD process).
22+
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
23+
24+
# Check that we have the expected version and architecture for Python
25+
- "python --version"
26+
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
27+
28+
# install xray and depenencies
29+
- "conda install --yes --quiet pip nose numpy pandas scipy netCDF4"
30+
- "python setup.py install"
31+
32+
build: false
33+
34+
test_script:
35+
- "nosetests xray"

‎ci/install_python.ps1

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Sample script to install Python and pip under Windows
2+
# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner
3+
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
4+
5+
$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
6+
$BASE_URL = "https://www.python.org/ftp/python/"
7+
8+
9+
function DownloadMiniconda ($python_version, $platform_suffix) {
10+
$webclient = New-Object System.Net.WebClient
11+
if ($python_version -eq "3.4") {
12+
$filename = "Miniconda3-3.7.3-Windows-" + $platform_suffix + ".exe"
13+
} else {
14+
$filename = "Miniconda-3.7.3-Windows-" + $platform_suffix + ".exe"
15+
}
16+
$url = $MINICONDA_URL + $filename
17+
18+
$basedir = $pwd.Path + "\"
19+
$filepath = $basedir + $filename
20+
if (Test-Path $filename) {
21+
Write-Host "Reusing" $filepath
22+
return $filepath
23+
}
24+
25+
# Download and retry up to 3 times in case of network transient errors.
26+
Write-Host "Downloading" $filename "from" $url
27+
$retry_attempts = 2
28+
for($i=0; $i -lt $retry_attempts; $i++){
29+
try {
30+
$webclient.DownloadFile($url, $filepath)
31+
break
32+
}
33+
Catch [Exception]{
34+
Start-Sleep 1
35+
}
36+
}
37+
if (Test-Path $filepath) {
38+
Write-Host "File saved at" $filepath
39+
} else {
40+
# Retry once to get the error message if any at the last try
41+
$webclient.DownloadFile($url, $filepath)
42+
}
43+
return $filepath
44+
}
45+
46+
47+
function InstallMiniconda ($python_version, $architecture, $python_home) {
48+
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
49+
if (Test-Path $python_home) {
50+
Write-Host $python_home "already exists, skipping."
51+
return $false
52+
}
53+
if ($architecture -eq "32") {
54+
$platform_suffix = "x86"
55+
} else {
56+
$platform_suffix = "x86_64"
57+
}
58+
$filepath = DownloadMiniconda $python_version $platform_suffix
59+
Write-Host "Installing" $filepath "to" $python_home
60+
$install_log = $python_home + ".log"
61+
$args = "/S /D=$python_home"
62+
Write-Host $filepath $args
63+
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
64+
if (Test-Path $python_home) {
65+
Write-Host "Python $python_version ($architecture) installation complete"
66+
} else {
67+
Write-Host "Failed to install Python in $python_home"
68+
Get-Content -Path $install_log
69+
Exit 1
70+
}
71+
}
72+
73+
74+
function InstallMinicondaPip ($python_home) {
75+
$pip_path = $python_home + "\Scripts\pip.exe"
76+
$conda_path = $python_home + "\Scripts\conda.exe"
77+
if (-not(Test-Path $pip_path)) {
78+
Write-Host "Installing pip..."
79+
$args = "install --yes pip"
80+
Write-Host $conda_path $args
81+
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
82+
} else {
83+
Write-Host "pip already installed."
84+
}
85+
}
86+
87+
88+
function main () {
89+
InstallMiniconda $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
90+
InstallMinicondaPip $env:PYTHON
91+
}
92+
93+
main

‎doc/whats-new.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Bug fixes
8686
aggregation methods (:issue:`344`).
8787
- Dataset aggregations with ``keep_attrs=True`` now preserve attributes on
8888
data variables, not just the dataset itself.
89-
- Tests for xray now pass when run on Windows. DOUBLE CHECK THIS.
89+
- Tests for xray now pass when run on Windows (:issue:`360`).
9090
- Fixed a regression in v0.4 where saving to netCDF could fail with the error
9191
``ValueError: could not automatically determine time units``.
9292

‎xray/test/test_backends.py

+1-48
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def test_dump_and_open_encodings(self):
385385

386386
with open_dataset(tmp_file) as xray_dataset:
387387
with create_tmp_file() as tmp_file2:
388-
xray_dataset.dump(tmp_file2)
388+
xray_dataset.to_netcdf(tmp_file2)
389389
with nc4.Dataset(tmp_file2, 'r') as ds:
390390
self.assertEqual(ds.variables['time'].getncattr('units'), units)
391391
self.assertArrayEqual(ds.variables['time'], np.arange(10) + 4)
@@ -495,53 +495,6 @@ def test_default_to_char_arrays(self):
495495
self.assertDatasetIdentical(data, actual)
496496
self.assertEqual(actual['x'].dtype, np.dtype('S4'))
497497

498-
def test_open_encodings(self):
499-
# Create a netCDF file with explicit time units
500-
# and make sure it makes it into the encodings
501-
# and survives a round trip
502-
with create_tmp_file() as tmp_file:
503-
with nc4.Dataset(tmp_file, 'w') as ds:
504-
ds.createDimension('time', size=10)
505-
ds.createVariable('time', np.int32, dimensions=('time',))
506-
units = 'days since 1999-01-01'
507-
ds.variables['time'].setncattr('units', units)
508-
ds.variables['time'][:] = np.arange(10) + 4
509-
510-
expected = Dataset()
511-
512-
time = pd.date_range('1999-01-05', periods=10)
513-
encoding = {'units': units, 'dtype': np.dtype('int32')}
514-
expected['time'] = ('time', time, {}, encoding)
515-
516-
with open_dataset(tmp_file) as actual:
517-
self.assertVariableEqual(actual['time'], expected['time'])
518-
actual_encoding = dict((k, v) for k, v
519-
in iteritems(actual['time'].encoding)
520-
if k in expected['time'].encoding)
521-
self.assertDictEqual(actual_encoding,
522-
expected['time'].encoding)
523-
524-
def test_dump_and_open_encodings(self):
525-
# Create a netCDF file with explicit time units
526-
# and make sure it makes it into the encodings
527-
# and survives a round trip
528-
with create_tmp_file() as tmp_file:
529-
with nc4.Dataset(tmp_file, 'w') as ds:
530-
ds.createDimension('time', size=10)
531-
ds.createVariable('time', np.int32, dimensions=('time',))
532-
units = 'days since 1999-01-01'
533-
ds.variables['time'].setncattr('units', units)
534-
ds.variables['time'][:] = np.arange(10) + 4
535-
536-
xray_dataset = open_dataset(tmp_file)
537-
538-
with create_tmp_file() as tmp_file2:
539-
xray_dataset.to_netcdf(tmp_file2)
540-
541-
with nc4.Dataset(tmp_file2, 'r') as ds:
542-
self.assertEqual(ds.variables['time'].getncattr('units'), units)
543-
self.assertArrayEqual(ds.variables['time'], np.arange(10) + 4)
544-
545498
def test_coordinates_encoding(self):
546499
def equals_latlon(obj):
547500
return obj == 'lat lon' or obj == 'lon lat'

‎xray/test/test_variable.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def test_count(self):
755755

756756
actual = Variable(['x'], [True, False, True]).count()
757757
self.assertVariableIdentical(expected, actual)
758-
self.assertEqual(actual.dtype, 'int64')
758+
self.assertEqual(actual.dtype, int)
759759

760760
expected = Variable(['x'], [2, 3])
761761
actual = Variable(['x', 'y'], [[1, 0, np.nan], [1, 1, 1]]).count('y')
@@ -810,7 +810,7 @@ def test_converted_types(self):
810810
actual = _as_compatible_data(input_array)
811811
self.assertArrayEqual(np.asarray(input_array), actual)
812812
self.assertEqual(NumpyArrayAdapter, type(actual))
813-
self.assertEqual(np.dtype(np.int64), actual.dtype)
813+
self.assertEqual(np.asarray(input_array).dtype, actual.dtype)
814814

815815
def test_masked_array(self):
816816
original = np.ma.MaskedArray(np.arange(5))

0 commit comments

Comments
 (0)
Please sign in to comment.