Skip to content

Commit

Permalink
Merge pull request #12 from cloudify-cosmo/fix-windows-requirements-f…
Browse files Browse the repository at this point in the history
…ile-installation

fixed windows related bugs and added appveyor config
  • Loading branch information
nir0s committed Oct 22, 2015
2 parents 8724d38 + 2010cba commit 40e17e0
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 75 deletions.
44 changes: 0 additions & 44 deletions CHANGELOG

This file was deleted.

7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ all:
@echo "make dev - prepares a development environment (includes tests)"
@echo "make instdev - prepares a development environment (no tests)"
@echo "make install - install on local system"
@echo "make files - update changelog and todo files"
@echo "make test - run tox"
@echo "make docs - build docs"
@echo "prepare - prepare module for release (CURRENTLY IRRELEVANT)"
@echo "make publish - upload to pypi"

release: files docs publish
release: docs publish

dev: instdev test

Expand All @@ -22,10 +21,6 @@ instdev:
install:
python setup.py install

files:
grep '# TODO' -rn * --exclude-dir=docs --exclude-dir=build --exclude=TODO.md | sed 's/: \+#/: # /g;s/:#/: # /g' | sed -e 's/^/- /' | grep -v Makefile > TODO.md
git log --oneline --decorate --color > CHANGELOG

test:
pip install tox
tox
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ or.. it is just a set of (Python) Wheels.
Cloudify Plugins are packaged as sets of Python [Wheels](https://packaging.python.org/en/latest/distributing.html#wheels) in tar.gz archives and so we needed a tool to create such entities; hence, Wagon.

* Wagon currently supports Python 2.6.x and Python 2.7.x.
* Wagon is currently only tested on Linux but might work on other platforms.
* Wagon is currently tested on both Linux and Windows (via Travis and AppVeyor).
* To be able to create Wagons of Wheels which include C extensions, you must have the [C++ Compiler for Python](http://www.microsoft.com/en-us/download/details.aspx?id=44266) installed.


## Installation
Expand Down Expand Up @@ -216,4 +217,3 @@ tox

* Support Python 3.x
* Provide the most statistically robust way of identification and installation of Linux compiled Wheels.
* Test on Windows (AppVeyor to come...)
5 changes: 0 additions & 5 deletions TODO.md

This file was deleted.

40 changes: 40 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
environment:

TOX_ENV: pywin

matrix:
- PYTHON: C:\Python27
PYTHON_VERSION: 2.7.8
PYTHON_ARCH: 32

install:

#################################
# Change Python Registry
#################################

- reg ADD HKCU\Software\Python\PythonCore\2.7\InstallPath /ve /d "C:\Python27" /t REG_SZ /f
- reg ADD HKLM\Software\Python\PythonCore\2.7\InstallPath /ve /d "C:\Python27" /t REG_SZ /f

#################################
# Installing Inno Setup
#################################

- choco install -y InnoSetup
- set PATH="C:\\Program Files (x86)\\Inno Setup 5";%PATH%

- SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%

- echo Upgrading pip...
- ps: (new-object System.Net.WebClient).Downloadfile('https://bootstrap.pypa.io/get-pip.py', 'C:\Users\appveyor\get-pip.py')
- ps: Start-Process -FilePath "C:\Python27\python.exe" -ArgumentList "C:\Users\appveyor\get-pip.py" -Wait -Passthru
- pip --version

build: false # Not a C# project, build stuff at the test step instead.

before_test:
- echo Installing tox (2.0.0)
- pip install tox==2.0.0

test_script:
- tox -e %TOX_ENV%
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(*parts):

setup(
name='wagon',
version='0.2.4',
version='0.2.5',
url='https://github.com/cloudify-cosmo/wagon',
author='Gigaspaces',
author_email='[email protected]',
Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ deps =
-rdev-requirements.txt
commands=nosetests --with-cov --cov-report term-missing --cov wagon wagon/tests -v

[testenv:pywin]
deps =
-rdev-requirements.txt
commands=nosetests -v --nocapture --nologcapture --with-cov --cov-report term-missing --cov wagon wagon/tests
basepython = {env:PYTHON:}\python.exe
passenv=ProgramFiles APPVEYOR LOGNAME USER LNAME USERNAME HOME USERPROFILE

[testenv:flake8]
deps =
flake8
Expand Down
29 changes: 23 additions & 6 deletions wagon/tests/test_wagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_run(self):

def test_run_bad_command(self):
p = utils.run('suname')
self.assertEqual(127, p.returncode)
self.assertEqual(1 if utils.IS_WIN else 127, p.returncode)

def test_download_file(self):
utils.download_file(TEST_FILE, 'file')
Expand All @@ -72,14 +72,20 @@ def test_download_file_missing(self):
def test_download_bad_url(self):
e = self.assertRaises(
IOError, utils.download_file, 'something', 'file')
self.assertIn("No such file or directory: 'something'", str(e))
if utils.IS_WIN:
self.assertIn("The system cannot find the file "
"specified: 'something'", str(e))
else:
self.assertIn("No such file or directory: 'something'", str(e))

def test_download_missing_path(self):
e = self.assertRaises(
IOError, utils.download_file, TEST_FILE, 'x/file')
self.assertIn('No such file or directory', e)

def test_download_no_permissions(self):
if utils.IS_WIN:
self.skipTest('Irrelevant on Windows.')
e = self.assertRaises(IOError, utils.download_file, TEST_FILE, '/file')
self.assertIn('Permission denied', str(e))

Expand All @@ -96,6 +102,8 @@ def test_tar(self):
os.remove('tar.file')

def test_tar_no_permissions(self):
if utils.IS_WIN:
self.skipTest("Irrelevant on Windows.")
tmpdir = tempfile.mkdtemp()
try:
e = self.assertRaises(IOError, utils.tar, tmpdir, '/file')
Expand All @@ -105,7 +113,11 @@ def test_tar_no_permissions(self):

def test_tar_missing_source(self):
e = self.assertRaises(OSError, utils.tar, 'missing', 'file')
self.assertIn("No such file or directory: 'missing'", str(e))
if utils.IS_WIN:
self.assertIn("The system cannot find the "
"file specified: 'missing'", str(e))
else:
self.assertIn("No such file or directory: 'missing'", str(e))
os.remove('file')

def test_wheel_nonexisting_package(self):
Expand All @@ -116,9 +128,11 @@ def test_wheel_nonexisting_package(self):
finally:
shutil.rmtree('package')

# non-windows
def test_machine_platform(self):
self.assertEqual(utils.get_machine_platform(), 'linux_x86_64')
if utils.IS_WIN:
self.assertIn('win32', utils.get_platform())
else:
self.assertEqual(utils.get_platform(), 'linux_x86_64')


class TestCreateBadSources(testtools.TestCase):
Expand Down Expand Up @@ -228,7 +242,10 @@ def test_create_archive_from_pypi_with_additional_wheel_args(self):
os.close(fd)

def test_create_archive_from_url_with_requirements(self):
self.wagon.platform = utils.get_machine_platform()
if utils.IS_WIN:
self.wagon.platform = 'win32'
else:
self.wagon.platform = utils.get_platform()
self.archive_name = self.wagon.set_archive_name(
TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)
params = {
Expand Down
14 changes: 7 additions & 7 deletions wagon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
from contextlib import closing
import platform

from wheel import pep425tags as wheel_tags

import codes
import logger


IS_VIRTUALENV = hasattr(sys, 'real_prefix')

PLATFORM = sys.platform
IS_WIN = (PLATFORM == 'win32')
IS_WIN = (os.name == 'nt')
IS_DARWIN = (PLATFORM == 'darwin')
IS_LINUX = (PLATFORM == 'linux2')

Expand Down Expand Up @@ -223,10 +225,8 @@ def get_python_version():
return 'py{0}{1}'.format(version[0], version[1])


def get_machine_platform():
id = '{0}_{1}'.format(platform.system().lower(), platform.machine())
lgr.info('Identified machine platform: {0}'.format(id))
return id
def get_platform():
return wheel_tags.get_platform()


def get_os_properties():
Expand Down Expand Up @@ -261,11 +261,11 @@ def check_installed(package, virtualenv):
return False


def make_virtualenv(virtualenv_dir, python_path='python'):
def make_virtualenv(virtualenv_dir):
"""This will create a virtualenv.
"""
lgr.debug('Creating Virtualenv {0}...'.format(virtualenv_dir))
result = run('virtualenv -p {0} {1}'.format(python_path, virtualenv_dir))
result = run('virtualenv {0}'.format(virtualenv_dir))
if not result.returncode == 0:
lgr.error('Could not create virtualenv: {0}'.format(virtualenv_dir))
sys.exit(codes.errors['failed_to_create_virtualenv'])
10 changes: 6 additions & 4 deletions wagon/wagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def install(self, virtualenv=None, requirements_file=None, upgrade=False,
if not ignore_platform and supported_platform != 'any':
lgr.debug('Validating Platform {0} is supported...'.format(
supported_platform))
machine_platform = utils.get_machine_platform()
machine_platform = utils.get_platform()
if machine_platform != supported_platform:
lgr.error('Platform unsupported for package ({0}).'.format(
machine_platform))
Expand Down Expand Up @@ -355,9 +355,9 @@ def get_source_name_and_version(self, source):
lgr.debug('setup.py file found. Retrieving name and version...')
setuppy_path = os.path.join(source, 'setup.py')
self.name = utils.run('python {0} --name'.format(
setuppy_path)).aggr_stdout.strip('\n')
setuppy_path)).aggr_stdout.rstrip('\r\n')
self.version = utils.run('python {0} --version'.format(
setuppy_path)).aggr_stdout.strip('\n')
setuppy_path)).aggr_stdout.rstrip('\r\n')
# TODO: maybe we don't want to be that explicit and allow using >=
# TODO: or just a package name...
elif '==' in source:
Expand All @@ -384,7 +384,9 @@ def handle_output_file(self, archive, force):
def handle_output_directory(self, wheels_path, force):
if os.path.isdir(wheels_path):
if force:
shutil.rmtree(wheels_path)
# Ignore errors is currently a workaround for shutil failing
# on Windows when the directory is not empty.
shutil.rmtree(wheels_path, ignore_errors=True)
else:
lgr.error('Directory {0} already exists. Please remove it and '
'run this again.'.format(wheels_path))
Expand Down

0 comments on commit 40e17e0

Please sign in to comment.