[tox]
envlist = py{36,37,38,39}-{linux,macos,windows}
skip_missing_interpreters = true
isolated_build = true
skipsdist = True

[gh-actions]
python =
    3.6: py36
    3.7: py37
    3.8: py38
    3.9: py39

[gh-actions:env]
PLATFORM =
    ubuntu-20.04: linux
    macos-latest: macos
    windows-2019: windows

[testenv]
passenv =
    pythonLocation
    CI
    PYTHONIOENCODING
    PIP_DOWNLOAD_CACHE

setenv = PYTHONPATH = {toxinidir}

allowlist_externals =
    bash
    diff

deps =
    pip>=20.3
    -rrequirements.txt
    pytest
    -e .

commands =
    # first generate some test output for pytest
    cp210x-program.py -pc -F testdata/cp2102-orig.hex -f testdata/test.out
    bash -c 'cp210x-program.py -pc -F testdata/cp2102-orig.hex > testdata/test2.out'
    pytest -v --capture=no test_platform_data.py

[testenv:lint]
passenv =
    pythonLocation
    CI
    PYTHONIOENCODING
    PIP_DOWNLOAD_CACHE

deps =
    pip>=20.3
    pylint
    -rrequirements.txt

commands =
    pylint --fail-under=7 cp210x/ scripts/

[testenv:deploy]
skip_install = true

passenv =
    pythonLocation
    CI
    PYTHONIOENCODING
    PIP_DOWNLOAD_CACHE

deps =
    pip>=20.3
    wheel
    twine

commands =
    python setup.py sdist
    python setup.py bdist_wheel
    twine check dist/*

[testenv:check]
passenv =
    PYTHON
    pythonLocation
    CI
    PYTHONIOENCODING
    PIP_DOWNLOAD_CACHE
skip_install = true

allowlist_externals =
    bash

deps =
    pip>=20.3
    -rrequirements.txt

commands =
    bash -c 'export WHL_FILE=$(ls dist/*.whl); \
        python -m pip install --force-reinstall $WHL_FILE'
    cp210x-program.py --version

[testenv:readhex]
passenv = CI PYTHON PYTHONIOENCODING
skip_install = true

allowlist_externals =
    bash

deps =
    pip>=20.3
    -rrequirements.txt

commands =
    bash -c 'export WHL_FILE=$(ls dist/*.whl); \
        python -m pip install --force-reinstall $WHL_FILE'
    #bash -c 'cp210x-program.py --read-cp210x || echo true'
    cp210x-program.py --read-cp210x -f readhex.out

[testenv:read]
passenv = CI PYTHON PYTHONIOENCODING
skip_install = true

allowlist_externals =
    bash

deps =
    pip>=20.3
    -rrequirements.txt

commands =
    python scripts/usb_read_cp210x.py

[testenv:badge]
envdir = {toxinidir}/.env
skip_install = true

passenv =
    pythonLocation
    CC
    CXX
    CI
    GITHUB*
    PIP_DOWNLOAD_CACHE

allowlist_externals =
    make
    cp

deps =
    pip>=20.3
    this-cli
    -rrequirements.txt

commands =
    # sadly this-cli cannot pass args to configure
    make -C ext/badge
    cp ext/badge/bin/cp2102 {envbindir}/
    cp2102 {posargs}

[testenv:clean]
envdir = {toxinidir}/.env
skip_install = true

passenv =
    pythonLocation
    CC
    CXX
    CI
    GITHUB*
    PIP_DOWNLOAD_CACHE

allowlist_externals =
    bash

deps =
    pip>=20.3

commands =
    bash -c 'rm -rf ./ext/badge/bin'
