scikit-build / scikit-ci-addons

Command line tool and a set of scripts useful to help drive CI
http://scikit-ci-addons.readthedocs.org/
Apache License 2.0
5 stars 9 forks source link

Add "anyci/conditional_exec.py" addon #59

Open jcfr opened 6 years ago

jcfr commented 6 years ago

This add-on will be adapted from https://stackoverflow.com/a/33012308/1539918 and will allow to conditionally execute a command based on the value of env. variable.

Motivation

Perform conditional execution of command with tox. See https://github.com/NeurodataWithoutBorders/pynwb/pull/245

Usage

Usage:
  python conditional_exec.py ENVVAR1==ENVVALUE1 ... -- command arg1 ...

Example of use:

ci_addons --install ../addons
python ../addons/anyci/conditional_exec.py DO_COVERAGE==true -- coverage run --source src test.py --pynwb
python ../addons/anyci/conditional_exec.py DO_COVERAGE==true -- codecov -F pynwb
thewtex commented 6 years ago

@jcfr I think this would be useful :+1: . Environmental variables are a standard, cross-platform way for passing state / settings in these CI systems.

A tweak to the syntax that would be helpful:

  python ../addons/anyci/conditional_exec.py DO_COVERAGE -- codecov -F pynwb

Where DO_COVERAGE is evaluated, and used if "truthy". Expression evaluation gets tricky. If supported, it should probably be based on Python expressions so it is cross platform. In this case true -> True.

dorukozturk commented 6 years ago

Since tox have more of a "declarative" syntax it is not really feasible to do condtionals based on environment variables. Instead creating a new environment in tox and selecting that environment on the appropriate platform (such as CI or local) with -e flag, is easier. See this as an example implementation.