[tox]
minversion = 3.21
# relies on the correct version of Python installed
envlist = ruff,tests,mypy-core,mypy-misc
# NOTE: we don't run end2end by default since it requires elaborate setup
# https://github.com/tox-dev/tox/issues/20#issuecomment-247788333
# hack to prevent .tox from crapping to the project directory
toxworkdir = {env:TOXWORKDIR_BASE:}{toxinidir}/.tox

[testenv]
# TODO how to get package name from setuptools?
package_name = "promnesia"
passenv =
# useful for tests to know they are running under ci
    CI
    CI_*
    CIRCLE*
# respect user's cache dirs to prevent tox from crapping into project dir
    PYTHONPYCACHEPREFIX
    MYPY_CACHE_DIR
    RUFF_CACHE_DIR
#
    MY_CONFIG
    # by default we don't run browser tests to avoid confusing people when they run locally
    # but we want them on CI, so we allow to pass through the variable when we do want to run them
    WITH_BROWSER_TESTS
    # todo ugh this is all so confusing... need to simplify


[testenv:ruff]
commands =
    {envpython} -m pip install --use-pep517 -e .[testing]
    {envpython} -m ruff check src/


[testenv:tests]
commands =
    {envpython} -m pip install --use-pep517 -e .[testing]

    {envpython} -m pip install --use-pep517 -e .[all]
    {envpython} -m pip install --use-pep517 -e .[HPI,org]

    # used in some tests
    {envpython} -m my.core module install my.google.takeout.parser
    {envpython} -m my.core module install my.hypothesis
    {envpython} -m pytest --pyargs {[testenv]package_name}.tests


[testenv:end2end]
setenv =
    WITH_BROWSER_TESTS=true
    PYTEST_TIMEOUT=120
commands =
    {envpython} -m pip install --use-pep517 -e .[testing,HPI]
    {envpython} -m my.core module install my.hypothesis
    {envpython} -m pytest tests/end2end_test.py {posargs}


[testenv:mypy-core]
commands =
    {envpython} -m pip install --use-pep517 -e .[testing]
    {envpython} -m mypy --install-types --non-interactive \
        # note: sources are tested separately, below
        -p {[testenv]package_name} --exclude 'sources/*' \
        # txt report is a bit more convenient to view on CI
        --txt-report  .coverage.mypy-core  \
        --html-report .coverage.mypy-core  \
        {posargs}


[testenv:mypy-misc]
commands =
    {envpython} -m pip install --use-pep517 -e .[testing]
    {envpython} -m pip install --use-pep517 -e .[HPI,org]
    # todo install from HPI[all] or something?

    {envpython} -m my.core module install my.github.ghexport
    {envpython} -m my.core module install my.hypothesis
    {envpython} -m my.core module install my.instapaper
    {envpython} -m my.core module install my.pocket
    {envpython} -m my.core module install my.reddit
    {envpython} -m my.core module install my.fbmessenger
    {envpython} -m my.core module install my.google.takeout.parser
    {envpython} -m my.core module install my.browser.export

    {envpython} -m mypy --install-types --non-interactive \
        -p {[testenv]package_name}.sources \
        # txt report is a bit more convenient to view on CI
        --txt-report  .coverage.mypy-misc \
        --html-report .coverage.mypy-misc \
        {posargs}

    {envpython} -m pip install --use-pep517 -e .[testing]
    # ugh. a bit crap to run it separately
    # but first will need to move tests inside the package if we want otherwise?
    # and I recall it was problematic at times..
    {envpython} -m mypy --install-types --non-interactive \
                   tests --exclude 'testdata/*' \
                   {posargs}
