From a7abe51cc23c4061d3b3e31691bb1dd237232e99 Mon Sep 17 00:00:00 2001 From: Stefano Borini <sborini@enthought.com> Date: Tue, 19 Jun 2018 14:11:02 +0100 Subject: [PATCH] Modified travis for CI package --- .travis.yml | 23 ++++------- ci/__init__.py | 0 ci/__main__.py | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 ci/__init__.py create mode 100644 ci/__main__.py diff --git a/.travis.yml b/.travis.yml index aef368d..4a92a6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,21 +11,14 @@ before_install: - export PATH=/usr/lib/ccache:${PATH} - wget https://package-data.enthought.com/edm/rh5_x86_64/1.9/edm_1.9.2_linux_x86_64.sh && bash ./edm_1.9.2_linux_x86_64.sh -b -f -p $HOME - export PATH=${HOME}/edm/bin:${PATH} - - edm environments create --version ${PYTHON_VERSION} force - - . $HOME/.edm/envs/force/bin/activate -install: - - pip install -r requirements/requirements.txt - - pip install -e . + - edm install -y -e force-bootstrap click setuptools + - edm run -e force-bootstrap -- python -m ci build-env --python-version ${PYTHON_VERSION} script: - - pip install -r requirements/dev_requirements.txt - - flake8 . - - python -m unittest discover - - pip install -r requirements/doc_requirements.txt - - pushd doc - - make html - - popd + - edm run -e force-bootstrap -- python -m ci flake8 + - edm run -e force-bootstrap -- python -m ci test + - edm run -e force-bootstrap -- python -m ci docs after_success: - - coverage run -m unittest discover - - pip install codecov - - codecov + - edm run -e force-bootstrap -- python -m ci coverage + - edm run -e force-bootstrap -- pip install codecov + - edm run -e force-bootstrap -- codecov - bash <(curl -s https://codecov.io/bash) diff --git a/ci/__init__.py b/ci/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ci/__main__.py b/ci/__main__.py new file mode 100644 index 0000000..a6e04c7 --- /dev/null +++ b/ci/__main__.py @@ -0,0 +1,109 @@ +import click +from subprocess import check_call + +DEFAULT_PYTHON_VERSION = "2.7" +PYTHON_VERSIONS = ["2.7", "3.6"] + +CORE_DEPS = [ + "envisage==4.6.0-1", + "click==6.7-1", + "six==1.10.0-1", + "stevedore==1.2.0-22" +] + +DOCS_DEPS = [ + "sphinx==1.5.5-5" +] + +DEV_DEPS = [ + "flake8==3.3.0-2", + "coverage==4.3.4-1", + "mock==2.0.0-1", + "testfixtures==4.10.0-1", +] + +PIP_DEPS = [ +] + + +@click.group() +def cli(): + pass + + +python_version_option = click.option( + '--python-version', + default=DEFAULT_PYTHON_VERSION, + type=click.Choice(PYTHON_VERSIONS), + show_default=True, + help="Python version for the environment") + + +@cli.command(name="build-env", help="Creates the execution environment") +@python_version_option +def build_env(python_version): + env_name = get_env_name(python_version) + check_call([ + "edm", "environments", "remove", "--purge", "--force", + "--yes", env_name]) + check_call( + ["edm", "environments", "create", env_name]) + + check_call([ + "edm", "install", "-e", env_name, + "--yes"] + CORE_DEPS + DEV_DEPS + DOCS_DEPS) + + if len(PIP_DEPS): + check_call([ + "edm", "run", "-e", env_name, "--", + "pip", "install"] + PIP_DEPS) + + check_call([ + "edm", "run", "-e", env_name, "--", + "pip", "install", "-e", "."]) + + +@cli.command(help="Run the tests") +@python_version_option +def test(python_version): + env_name = get_env_name(python_version) + + check_call([ + "edm", "run", "-e", env_name, "--", "python", "-m", "unittest", + "discover" + ]) + + +@cli.command(help="Run flake") +@python_version_option +def flake(python_version): + env_name = get_env_name(python_version) + + check_call(["edm", "run", "-e", env_name, "--", "flake8", "."]) + + +@cli.command(help="Builds the documentation") +@python_version_option +def coverage(python_version): + env_name = get_env_name(python_version) + + check_call(["edm", "run", "-e", env_name, "--", + "coverage", "run", "-m", "unittest", "discover"]) + + +@cli.command(help="Builds the documentation") +@python_version_option +def docs(python_version): + check_call(["make", "html"], cwd="doc") + + +def get_env_name(python_version): + return "force-py{}".format(remove_dot(python_version)) + + +def remove_dot(python_version): + return "".join(python_version.split('.')) + + +if __name__ == "__main__": + cli() -- GitLab