Skip to content
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

Added files needed to run tests on appveyor. #315

Merged
merged 2 commits into from
Dec 29, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
PyDy
====

|pypi| |anaconda| |rtd-docs| |travis-build| |Gitter Badge|
|pypi| |anaconda| |rtd-docs| |travis-build| |appveyor| |gitter|

.. |pypi| image:: https://img.shields.io/pypi/v/pydy.svg
:target: https://pypi.python.org/pypi/pydy
Expand All @@ -18,7 +18,10 @@ PyDy
.. |travis-build| image:: https://travis-ci.org/pydy/pydy.png?branch=master
:target: https://travis-ci.org/pydy/pydy

.. |Gitter Badge| image:: https://badges.gitter.im/Join%20Chat.svg
.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/orj87gyb0c1wqc6j/branch/master?svg=true
:targety: https://ci.appveyor.com/project/moorepants/pydy/branch/master

.. |gitter| image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/pydy/pydy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

PyDy_, short for Python Dynamics, is a tool kit written in the Python
Expand Down
47 changes: 47 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
environment:

global:
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
# /E:ON and /V:ON options are not enabled in the batch script intepreter
# See: http://stackoverflow.com/a/13751649/163740
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"

matrix:
- PYTHON: "C:\\Miniconda-x64"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "64"
CONDA_PY: "27"

- PYTHON: "C:\\Miniconda3-x64"
PYTHON_VERSION: "3.4"
PYTHON_ARCH: "64"
CONDA_PY: "34"

- PYTHON: "C:\\Miniconda35-x64"
PYTHON_VERSION: "3.5"
PYTHON_ARCH: "64"
CONDA_PY: "35"

install:
- ECHO "Filesystem root:"
- ps: "ls \"C:/\""

- ECHO "Installed SDKs:"
- ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\""

# This upates conda and installs the necessary packages.
- powershell .\\appveyor\\install.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)\""

build: false

test_script:
- "%CMD_IN_ENV% nosetests -v --with-coverage --cover-package=pydy"
25 changes: 25 additions & 0 deletions appveyor/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Sample script to install Miniconda under Windows
# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner, Robert McGibbon
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
#
function UpdateConda ($python_home) {
$conda_path = $python_home + "\Scripts\conda.exe"
Write-Host "Updating conda..."
$args = "update --yes conda"
Write-Host $conda_path $args
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
}

function InstallCondaPackages ($python_home, $spec) {
$conda_path = $python_home + "\Scripts\conda.exe"
$args = "install --yes " + $spec
Write-Host ("conda " + $args)
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
}

function main () {
UpdateConda $env:PYTHON
InstallCondaPackages $env:PYTHON "numpy scipy sympy cython nose coverage"
}

main
89 changes: 89 additions & 0 deletions appveyor/run_with_env.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
:: To build extensions for 64 bit Python 3, we need to configure environment
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
::
:: To build extensions for 64 bit Python 2, we need to configure environment
:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
::
:: 32 bit builds, and 64-bit builds for 3.5 and beyond, do not require specific
:: environment configurations.
::
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
:: cmd interpreter, at least for (SDK v7.0)
::
:: More details at:
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
:: http://stackoverflow.com/a/13751649/163740
::
:: Author: Olivier Grisel
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
::
:: Notes about batch files for Python people:
::
:: Quotes in values are literally part of the values:
:: SET FOO="bar"
:: FOO is now five characters long: " b a r "
:: If you don't want quotes, don't include them on the right-hand side.
::
:: The CALL lines at the end of this file look redundant, but if you move them
:: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y
:: case, I don't know why.
@ECHO OFF

SET COMMAND_TO_RUN=%*
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf

:: Extract the major and minor versions, and allow for the minor version to be
:: more than 9. This requires the version number to have two dots in it.
SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1%
IF "%PYTHON_VERSION:~3,1%" == "." (
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
) ELSE (
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2%
)

:: Based on the Python version, determine what SDK version to use, and whether
:: to set the SDK for 64-bit.
IF %MAJOR_PYTHON_VERSION% == 2 (
SET WINDOWS_SDK_VERSION="v7.0"
SET SET_SDK_64=Y
) ELSE (
IF %MAJOR_PYTHON_VERSION% == 3 (
SET WINDOWS_SDK_VERSION="v7.1"
IF %MINOR_PYTHON_VERSION% LEQ 4 (
SET SET_SDK_64=Y
) ELSE (
SET SET_SDK_64=N
IF EXIST "%WIN_WDK%" (
:: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/
REN "%WIN_WDK%" 0wdf
)
)
) ELSE (
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
EXIT 1
)
)

IF %PYTHON_ARCH% == 64 (
IF %SET_SDK_64% == Y (
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
) ELSE (
ECHO Using default MSVC build environment for 64 bit architecture
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
)
) ELSE (
ECHO Using default MSVC build environment for 32 bit architecture
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
)

24 changes: 13 additions & 11 deletions pydy/codegen/cython_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,17 @@ def write(self, path=None):
with open(os.path.join(path, self.prefix + '.pyx'), 'w') as f:
f.write(pyx)

def compile(self, tmp_dir=None):
def compile(self, tmp_dir=None, verbose=False):
"""Returns a function which evaluates the matrices.

Parameters
==========
tmp_dir : string
The path to an existing or non-existing directory where all of
the generated files will be stored.
verbose : boolean
If true the output of the completed compilation steps will be
printed.

"""

Expand All @@ -213,15 +216,9 @@ def compile(self, tmp_dir=None):
self.write()
cmd = [sys.executable, self.prefix + '_setup.py', 'build_ext',
'--inplace']
try:
DEVNULL = subprocess.DEVNULL
except AttributeError:
DEVNULL = open(os.devnull, 'wb')
subprocess.check_call(cmd, stdout=DEVNULL, stderr=subprocess.STDOUT)
try:
DEVNULL.close()
except Exception:
pass
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
if verbose:
print(output.decode())
cython_module = importlib.import_module(self.prefix)
except:
raise Exception('Failed to compile and import Cython module.')
Expand All @@ -230,7 +227,12 @@ def compile(self, tmp_dir=None):
CythonMatrixGenerator._module_counter += 1
os.chdir(workingdir)
if tmp_dir is None:
shutil.rmtree(codedir)
# rmtree fails on Windows with permissions errors, so skip the
# removal on Windows.
try:
shutil.rmtree(codedir)
except OSError:
pass

self.prefix = base_prefix

Expand Down
20 changes: 17 additions & 3 deletions pydy/codegen/tests/test_ode_function_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from random import choice
import warnings

import numpy as np
import scipy as sp
Expand All @@ -14,6 +15,9 @@
LambdifyODEFunctionGenerator,
CythonODEFunctionGenerator,
TheanoODEFunctionGenerator)
from ...utils import PyDyImportWarning

warnings.simplefilter('once', PyDyImportWarning)


class TestODEFunctionGenerator(object):
Expand Down Expand Up @@ -113,9 +117,19 @@ def test_set_linear_system_solver(self):

class TestODEFunctionGeneratorSubclasses(object):

ode_function_subclasses = [LambdifyODEFunctionGenerator,
CythonODEFunctionGenerator,
TheanoODEFunctionGenerator]
ode_function_subclasses = [LambdifyODEFunctionGenerator]

if Cython:
ode_function_subclasses.append(CythonODEFunctionGenerator)
else:
warnings.warn("Cython was not found so the related tests are being"
" skipped.", PyDyImportWarning)

if theano:
ode_function_subclasses.append(TheanoODEFunctionGenerator)
else:
warnings.warn("Theano was not found so the related tests are being"
" skipped.", PyDyImportWarning)

def setup(self):

Expand Down
18 changes: 13 additions & 5 deletions pydy/tests/test_system.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/usr/bin/env python

import warnings

import numpy as np
from numpy import testing
import sympy as sm
from sympy.physics.mechanics import dynamicsymbols
from scipy.integrate import odeint
theano = sm.external.import_module('theano')

from ..system import System
from ..models import multi_mass_spring_damper, n_link_pendulum_on_cart
from ..utils import sympy_equal_to_or_newer_than
from ..utils import sympy_equal_to_or_newer_than, PyDyImportWarning

SYMPY_VERSION = sm.__version__

warnings.simplefilter('once', PyDyImportWarning)

class TestSystem():

Expand Down Expand Up @@ -385,10 +389,14 @@ def test_integrate(self):

# Test a generator other than lambdify.
# -------------------------------------
sys.generate_ode_function(generator='theano')
sys.times = times
x_06 = sys.integrate()
testing.assert_allclose(x_04, x_06)
if theano:
sys.generate_ode_function(generator='theano')
sys.times = times
x_06 = sys.integrate()
testing.assert_allclose(x_04, x_06)
else:
warnings.warn("Theano was not found so the related tests are being"
" skipped.", PyDyImportWarning)

# Unrecognized generator.
# -----------------------
Expand Down