Skip to content

Commit

Permalink
Merge pull request #5 from scikit-build/update-test-to-use-ci_addons
Browse files Browse the repository at this point in the history
Update test to use ci addons
  • Loading branch information
jcfr committed Oct 27, 2016
2 parents 33212e3 + 458a601 commit 76807d1
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 25 deletions.
26 changes: 22 additions & 4 deletions _tests/test_scikit_ci_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ def test_path(addon):
assert ci_addons.path(addon) == expected_path


def test_list(capsys):
ci_addons.list_addons()
output_lines, _ = captured_lines(capsys)
assert 'anyci' + os.path.sep + 'noop.py' in output_lines
def test_addons():
addons = ci_addons.addons()
assert 'anyci' + os.path.sep + 'noop.py' in addons


@pytest.mark.parametrize("addon", ['anyci/noop', 'anyci/noop.py'])
Expand All @@ -33,6 +32,25 @@ def test_execute(addon, capfd):
assert os.path.join(ci_addons.home(), 'anyci/noop.py foo bar') in output_lines


def test_install(tmpdir, capfd):
noop = tmpdir.mkdir('anyci').join('noop.py')
noop.write("")

ci_addons.install(str(tmpdir))
output_lines, _ = captured_lines(capfd)

for addon in ci_addons.addons():
assert tmpdir.join(addon).exists()

assert str(noop) + ' (skipped)' in output_lines
assert str(tmpdir.join('appveyor', 'patch_vs2008.py')) in output_lines

ci_addons.install(str(tmpdir), force=True)
output_lines, _ = captured_lines(capfd)

assert str(noop) + ' (overwritten)' in output_lines


def test_cli():

root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ on_finish:
)
}"

artifacts:
- path: dist\*

on_failure:
- ps: "Get-EventLog AppVeyor -newest 10 | Format-List"

Expand Down
43 changes: 38 additions & 5 deletions ci_addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import os
import shutil
import sys

from subprocess import check_call
Expand All @@ -15,8 +16,10 @@
__version__ = '0.2.0'


def list_addons():
"""List all available addons."""
def addons():
"""Return all available addons."""

addons = []

for dirname, dirnames, filenames in os.walk(home()):

Expand All @@ -27,12 +30,13 @@ def list_addons():
if dirname == home():
continue

print("")

for filename in filenames:
if filename in ['__init__.py']:
continue
print(os.path.relpath(os.path.join(dirname, filename), home()))
addon_path = os.path.join(dirname, filename)
addons.append(os.path.relpath(addon_path, home()))

return addons


def home():
Expand All @@ -54,6 +58,35 @@ def path(addon_name):
return tmp_addon_path


def install(dst_path, force=False):
"""Copy addons into ``dst_path``.
By default, existing addons are *NOT* overwritten. Specifying ``force``
allow to overwrite them.
"""
dst_path = os.path.normpath(os.path.abspath(dst_path))
if dst_path == os.path.normpath(home()):
print("skipping install: target directory already contains addons")
exit()
for addon in addons():
dst_addon_path = os.path.join(dst_path, addon)
dst_addon_dir = os.path.split(dst_addon_path)[0]
if not os.path.exists(dst_addon_dir):
os.makedirs(dst_addon_dir)
src_addon_path = os.path.join(home(), addon)
extra = ""
do_copy = True
if os.path.exists(dst_addon_path):
extra = " (skipped)"
do_copy = False
if force:
extra = " (overwritten)"
do_copy = True
if do_copy:
shutil.copy(src_addon_path, dst_addon_path)
print(dst_addon_path + extra)


def execute(addon_name, arguments=[]):
"""Execute ``addon_name`` with ``arguments``.
Expand Down
18 changes: 16 additions & 2 deletions ci_addons/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def main():
"--path", type=str,
help="display addon path"
)
parser.add_argument(
"--install", type=str,
help="install addons in the selected directory"
)
parser.add_argument(
"--version", action="version",
version=version_str,
Expand All @@ -51,15 +55,25 @@ def main():
exit()

if args.list:
ci_addons.list_addons()
previous_collection = ""
for addon in ci_addons.addons():
current_collection = addon.split(os.path.sep)[0]
if previous_collection != current_collection:
print("")
print(addon)
previous_collection = current_collection
exit()

if args.path is not None:
print(ci_addons.path(args.path))
exit()

if args.install is not None:
ci_addons.install(args.install)
exit()

if all([not getattr(args, arg)
for arg in ['addon', 'home', 'list', 'path']]):
for arg in ['addon', 'home', 'install', 'list', 'path']]):
parser.print_usage()
exit()

Expand Down
3 changes: 2 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ deployment:
master:
branch: master
commands:
- ci after_test
- ci after_test
- mv dist/* $CIRCLE_ARTIFACTS/
28 changes: 26 additions & 2 deletions docs/addons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@
Add-ons
=======

Each directory contains scripts (or add-ons) designed to be executed on the CI
worker named after the directory.
Each category is named after a CI worker (e.g appveyor) and references add-ons
designed to be used on the associated continuous integration service.

An add-on is a file that could either directly be executed or used as a
parameter for an other tool.


Anyci
-----

This a special category containing scripts that could be executed on a broad
range of CI services.


``noop.py``
^^^^^^^^^^^

Display name of script and associated argument (basically the value of
``sys.argv``).


``run.sh``
^^^^^^^^^^

Wrapper script executing command and arguments passed as parameters.


Appveyor
--------
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Usage
=====

The scikit-ci-addons command line executable allows to execute any of the
distributed :doc:`add-ons </addons>`.
The scikit-ci-addons command line executable allows to discover, execute and
get the path of any of the distributed :doc:`add-ons </addons>`.

For example:

Expand Down
20 changes: 11 additions & 9 deletions scikit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ before_install:

environment:
PYTHON: python
RUN_ENV: ./anyci/run.sh
RUN_ENV: ../anyci/run.sh

command:
- python anyci/noop.py foo bar
commands:
- python -m ci_addons --install ..
- python ../anyci/noop.py foo bar
- python -m ci_addons anyci/noop foo bar

appveyor:
environment:
PYTHON: $<PYTHON_DIR>\\python.exe
RUN_ENV: .\\appveyor\\run-with-visual-studio.cmd
RUN_ENV: ..\\appveyor\\run-with-visual-studio.cmd
commands:
- python appveyor/patch_vs2008.py
- python appveyor/tweak_environment.py
- python -m ci_addons appveyor/patch_vs2008
- python -m ci_addons appveyor/tweak_environment

travis:
osx:
environment:
RUN_ENV: travis/run-with-pyenv.sh
RUN_ENV: ../travis/run-with-pyenv.sh
commands:
- python travis/install_pyenv.py
- python -m ci_addons travis/install_pyenv

install:
commands:
- python ./$<CI_NAME>/install_cmake.py 3.6.2
- python -m ci_addons $<CI_NAME>/install_cmake 3.6.2
- $<RUN_ENV> $<PYTHON> -m pip install --disable-pip-version-check --upgrade pip
- $<RUN_ENV> $<PYTHON> -m pip install -r requirements.txt
- $<RUN_ENV> $<PYTHON> -m pip install -r requirements-dev.txt
Expand Down

0 comments on commit 76807d1

Please sign in to comment.