Skip to content

Commit

Permalink
Add Appveyor for CI on Windows
Browse files Browse the repository at this point in the history
Fixes GH360
  • Loading branch information
shoyer committed Mar 17, 2015
1 parent 4ca0860 commit a8b5a5d
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 51 deletions.
35 changes: 35 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CI on Windows via appveyor
# This file was based on Olivier Grisel's python-appveyor-demo

environment:

matrix:
- PYTHON: "C:\\Python27-conda32"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "32"

- PYTHON: "C:\\Python34-conda64"
PYTHON_VERSION: "3.4"
PYTHON_ARCH: "64"

install:
# Install miniconda Python
- "powershell ./ci/install_python.ps1"

# Prepend newly installed Python to the PATH of this build (this cannot be
# done from inside the powershell script as it would require to restart
# 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 xray and depenencies
- "conda install --yes --quiet pip nose numpy pandas scipy netCDF4"
- "python setup.py install"

build: false

test_script:
- "nosetests xray"
93 changes: 93 additions & 0 deletions ci/install_python.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Sample script to install Python and pip under Windows
# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/

$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
$BASE_URL = "https://www.python.org/ftp/python/"


function DownloadMiniconda ($python_version, $platform_suffix) {
$webclient = New-Object System.Net.WebClient
if ($python_version -eq "3.4") {
$filename = "Miniconda3-3.7.3-Windows-" + $platform_suffix + ".exe"
} else {
$filename = "Miniconda-3.7.3-Windows-" + $platform_suffix + ".exe"
}
$url = $MINICONDA_URL + $filename

$basedir = $pwd.Path + "\"
$filepath = $basedir + $filename
if (Test-Path $filename) {
Write-Host "Reusing" $filepath
return $filepath
}

# Download and retry up to 3 times in case of network transient errors.
Write-Host "Downloading" $filename "from" $url
$retry_attempts = 2
for($i=0; $i -lt $retry_attempts; $i++){
try {
$webclient.DownloadFile($url, $filepath)
break
}
Catch [Exception]{
Start-Sleep 1
}
}
if (Test-Path $filepath) {
Write-Host "File saved at" $filepath
} else {
# Retry once to get the error message if any at the last try
$webclient.DownloadFile($url, $filepath)
}
return $filepath
}


function InstallMiniconda ($python_version, $architecture, $python_home) {
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
if (Test-Path $python_home) {
Write-Host $python_home "already exists, skipping."
return $false
}
if ($architecture -eq "32") {
$platform_suffix = "x86"
} else {
$platform_suffix = "x86_64"
}
$filepath = DownloadMiniconda $python_version $platform_suffix
Write-Host "Installing" $filepath "to" $python_home
$install_log = $python_home + ".log"
$args = "/S /D=$python_home"
Write-Host $filepath $args
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
if (Test-Path $python_home) {
Write-Host "Python $python_version ($architecture) installation complete"
} else {
Write-Host "Failed to install Python in $python_home"
Get-Content -Path $install_log
Exit 1
}
}


function InstallMinicondaPip ($python_home) {
$pip_path = $python_home + "\Scripts\pip.exe"
$conda_path = $python_home + "\Scripts\conda.exe"
if (-not(Test-Path $pip_path)) {
Write-Host "Installing pip..."
$args = "install --yes pip"
Write-Host $conda_path $args
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
} else {
Write-Host "pip already installed."
}
}


function main () {
InstallMiniconda $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
InstallMinicondaPip $env:PYTHON
}

main
2 changes: 1 addition & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Bug fixes
aggregation methods (:issue:`344`).
- Dataset aggregations with ``keep_attrs=True`` now preserve attributes on
data variables, not just the dataset itself.
- Tests for xray now pass when run on Windows. DOUBLE CHECK THIS.
- Tests for xray now pass when run on Windows (:issue:`360`).
- Fixed a regression in v0.4 where saving to netCDF could fail with the error
``ValueError: could not automatically determine time units``.

Expand Down
49 changes: 1 addition & 48 deletions xray/test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_dump_and_open_encodings(self):

with open_dataset(tmp_file) as xray_dataset:
with create_tmp_file() as tmp_file2:
xray_dataset.dump(tmp_file2)
xray_dataset.to_netcdf(tmp_file2)
with nc4.Dataset(tmp_file2, 'r') as ds:
self.assertEqual(ds.variables['time'].getncattr('units'), units)
self.assertArrayEqual(ds.variables['time'], np.arange(10) + 4)
Expand Down Expand Up @@ -495,53 +495,6 @@ def test_default_to_char_arrays(self):
self.assertDatasetIdentical(data, actual)
self.assertEqual(actual['x'].dtype, np.dtype('S4'))

def test_open_encodings(self):
# Create a netCDF file with explicit time units
# and make sure it makes it into the encodings
# and survives a round trip
with create_tmp_file() as tmp_file:
with nc4.Dataset(tmp_file, 'w') as ds:
ds.createDimension('time', size=10)
ds.createVariable('time', np.int32, dimensions=('time',))
units = 'days since 1999-01-01'
ds.variables['time'].setncattr('units', units)
ds.variables['time'][:] = np.arange(10) + 4

expected = Dataset()

time = pd.date_range('1999-01-05', periods=10)
encoding = {'units': units, 'dtype': np.dtype('int32')}
expected['time'] = ('time', time, {}, encoding)

with open_dataset(tmp_file) as actual:
self.assertVariableEqual(actual['time'], expected['time'])
actual_encoding = dict((k, v) for k, v
in iteritems(actual['time'].encoding)
if k in expected['time'].encoding)
self.assertDictEqual(actual_encoding,
expected['time'].encoding)

def test_dump_and_open_encodings(self):
# Create a netCDF file with explicit time units
# and make sure it makes it into the encodings
# and survives a round trip
with create_tmp_file() as tmp_file:
with nc4.Dataset(tmp_file, 'w') as ds:
ds.createDimension('time', size=10)
ds.createVariable('time', np.int32, dimensions=('time',))
units = 'days since 1999-01-01'
ds.variables['time'].setncattr('units', units)
ds.variables['time'][:] = np.arange(10) + 4

xray_dataset = open_dataset(tmp_file)

with create_tmp_file() as tmp_file2:
xray_dataset.to_netcdf(tmp_file2)

with nc4.Dataset(tmp_file2, 'r') as ds:
self.assertEqual(ds.variables['time'].getncattr('units'), units)
self.assertArrayEqual(ds.variables['time'], np.arange(10) + 4)

def test_coordinates_encoding(self):
def equals_latlon(obj):
return obj == 'lat lon' or obj == 'lon lat'
Expand Down
4 changes: 2 additions & 2 deletions xray/test/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def test_count(self):

actual = Variable(['x'], [True, False, True]).count()
self.assertVariableIdentical(expected, actual)
self.assertEqual(actual.dtype, 'int64')
self.assertEqual(actual.dtype, int)

expected = Variable(['x'], [2, 3])
actual = Variable(['x', 'y'], [[1, 0, np.nan], [1, 1, 1]]).count('y')
Expand Down Expand Up @@ -810,7 +810,7 @@ def test_converted_types(self):
actual = _as_compatible_data(input_array)
self.assertArrayEqual(np.asarray(input_array), actual)
self.assertEqual(NumpyArrayAdapter, type(actual))
self.assertEqual(np.dtype(np.int64), actual.dtype)
self.assertEqual(np.asarray(input_array).dtype, actual.dtype)

def test_masked_array(self):
original = np.ma.MaskedArray(np.arange(5))
Expand Down

0 comments on commit a8b5a5d

Please sign in to comment.