
[tox]
envlist = py

[testenv]
# note that we have a .coveragerc file that points coverage specifically
# at ./lib/sqlalchemy, and *not* at the build that tox might create under .tox.
# See the notes below for setenv for more detail.
# also using --cov-append so that we can aggregate multiple runs together.
# Jenkins etc. need to call "coverage erase" externally.
cov_args=--cov=sqlalchemy --cov-report term --cov-append --cov-report xml --exclude-tag memory-intensive --exclude-tag timing-intensive -k "not aaa_profiling"

install_command=python -m pip install {env:TOX_PIP_OPTS:} {opts} {packages}

usedevelop=
     cov: True

deps=
     pytest>=7.0.0rc1,<8
     pytest-xdist

     # note cython not working for 3.11 at all right now
     git+https://github.com/python-greenlet/greenlet.git#egg=greenlet; python_version >= '3.11'

     sqlite: .[aiosqlite]
     sqlite_file: .[aiosqlite]
     sqlite_file: .[sqlcipher]; python_version < '3.10'
     postgresql: .[postgresql]
     postgresql: .[postgresql_asyncpg]
     postgresql: .[postgresql_pg8000]
     postgresql: .[postgresql_psycopg]

     mysql: .[mysql]
     mysql: .[pymysql]
     mysql: .[asyncmy]
     mysql: .[mariadb_connector]

     oracle: .[oracle]

     mssql: .[mssql]

     dbapimain-sqlite: git+https://github.com/omnilib/aiosqlite.git#egg=aiosqlite
     dbapimain-sqlite: git+https://github.com/coleifer/sqlcipher3.git#egg=sqlcipher3

     dbapimain-postgresql: git+https://github.com/psycopg/psycopg2.git#egg=psycopg2
     dbapimain-postgresql: git+https://github.com/MagicStack/asyncpg.git#egg=asyncpg
     dbapimain-postgresql: git+https://github.com/tlocke/pg8000.git#egg=pg8000
     dbapimain-postgresql: git+https://github.com/psycopg/psycopg.git#egg=psycopg&subdirectory=psycopg
     dbapimain-postgresql: git+https://github.com/psycopg/psycopg.git#egg=psycopg-c&subdirectory=psycopg_c

     dbapimain-mysql: git+https://github.com/PyMySQL/mysqlclient-python.git#egg=mysqlclient
     dbapimain-mysql: git+https://github.com/PyMySQL/PyMySQL.git#egg=pymysql
     dbapimain-mysql: git+https://github.com/mariadb-corporation/mariadb-connector-python#egg=mariadb

     dbapimain-oracle: git+https://github.com/oracle/python-cx_Oracle.git#egg=cx_Oracle

     dbapimain-mssql: git+https://github.com/mkleehammer/pyodbc.git#egg=pyodbc

     cov: pytest-cov

allowlist_externals=sh

# PYTHONPATH - erased so that we use the build that's present
# in .tox as the SQLAlchemy library to be imported
#
# PYTHONUSERSITE - this *MUST* be set so that the ./lib/ import
# set up explicitly in test/conftest.py is *disabled*, again so that
# when SQLAlchemy is built into the .tox area, we use that and not the
# local checkout, at least when usedevelop=False
#
# BASECOMMAND - using an env variable here so we can use it
# as a substitution in a command (see https://bitbucket.org/hpk42/tox/issues/307/)
#
# only use --dropfirst option if we're *not* using -n;
# if -n is used, we're working in brand new DBs anyway, dropfirst
# will collide on CI environments
setenv=
    PYTHONPATH=
    PYTHONNOUSERSITE=1
    PYTEST_EXCLUDES=-m "not memory_intensive and not mypy"

    BASECOMMAND=python -m pytest --rootdir {toxinidir} --log-info=sqlalchemy.testing

    WORKERS={env:TOX_WORKERS:-n4  --max-worker-restart=5}

    nocext: DISABLE_SQLALCHEMY_CEXT=1
    cext: REQUIRE_SQLALCHEMY_CEXT=1
    cov: COVERAGE={[testenv]cov_args}
    backendonly: PYTEST_EXCLUDES="-m backend"
    memusage: PYTEST_EXCLUDES="-m memory_intensive"

    oracle: WORKERS={env:TOX_WORKERS:-n2  --max-worker-restart=5}
    oracle: ORACLE={env:TOX_ORACLE:--db oracle}

    sqlite: SQLITE={env:TOX_SQLITE:--db sqlite}
    sqlite_file: SQLITE={env:TOX_SQLITE_FILE:--db sqlite_file}
    py3{,7,8,9,10,11}-sqlite: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite}
    py3{,7,8,9}-sqlite_file: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite --dbdriver pysqlcipher}
    # omit pysqlcipher for Python 3.10
    py3{,10,11}-sqlite_file: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite}

    postgresql: POSTGRESQL={env:TOX_POSTGRESQL:--db postgresql}
    py3{,7,8,9,10,11}-postgresql: EXTRA_PG_DRIVERS={env:EXTRA_PG_DRIVERS:--dbdriver psycopg2 --dbdriver asyncpg --dbdriver pg8000 --dbdriver psycopg --dbdriver psycopg_async}

    mysql: MYSQL={env:TOX_MYSQL:--db mysql}
    py2{,7}-mysql: MYSQL={env:TOX_MYSQL_PY2K:{env:TOX_MYSQL:--db mysql}}
    mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql}

    py3{,7,8,9,10,11}-mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver mariadbconnector --dbdriver asyncmy}


    mssql: MSSQL={env:TOX_MSSQL:--db mssql}

    oracle,mssql,sqlite_file: IDENTS=--write-idents db_idents.txt

# tox as of 2.0 blocks all environment variables from the
# outside, unless they are here (or in TOX_TESTENV_PASSENV,
# wildcards OK).  Need at least these
passenv=ORACLE_HOME NLS_LANG TOX_POSTGRESQL TOX_POSTGRESQL_PY2K TOX_MYSQL TOX_MYSQL_PY2K TOX_ORACLE TOX_MSSQL TOX_SQLITE TOX_SQLITE_FILE TOX_WORKERS EXTRA_SQLITE_DRIVERS EXTRA_PG_DRIVERS EXTRA_MYSQL_DRIVERS

commands=

  # this line is only meaningful when usedevelop=True is enabled.  we use
  # that flag for coverage mode.
  nocext: sh -c "rm -f lib/sqlalchemy/*.so"

  {env:BASECOMMAND} {env:WORKERS} {env:SQLITE:} {env:EXTRA_SQLITE_DRIVERS:} {env:POSTGRESQL:} {env:EXTRA_PG_DRIVERS:} {env:MYSQL:} {env:EXTRA_MYSQL_DRIVERS:} {env:ORACLE:} {env:MSSQL:} {env:IDENTS:} {env:PYTEST_EXCLUDES:} {env:COVERAGE:} {posargs}
  oracle,mssql,sqlite_file: python reap_dbs.py db_idents.txt


[testenv:pep484]
deps=
     greenlet != 0.4.17
     importlib_metadata; python_version < '3.8'
     mypy
     pyright
commands =
    mypy  ./lib/sqlalchemy
    pyright

[testenv:mypy]
deps=
     pytest>=7.0.0rc1,<8
     pytest-xdist
     greenlet != 0.4.17
     importlib_metadata; python_version < '3.8'
     mypy
     patch==1.*
     git+https://github.com/sqlalchemy/sqlalchemy2-stubs
commands =
    pytest -m mypy {posargs}

# thanks to https://julien.danjou.info/the-best-flake8-extensions/
[testenv:pep8]
basepython = python3
deps=
      flake8
      flake8-import-order
      flake8-builtins
      flake8-docstrings>=1.6.0
      flake8-rst-docstrings
      # flake8-rst-docstrings dependency, leaving it here
      # in case it requires a version pin
      pydocstyle
      pygments
      black==21.12b0
commands =
     flake8 ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs}
     black --check ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py


# command run in the github action when cext are active.
[testenv:github-cext]
deps = {[testenv]deps}
       .[aiosqlite]
commands=
  python -m pytest {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:IDENTS:} {env:PYTEST_EXCLUDES:} {env:COVERAGE:} {posargs}
  oracle,mssql,sqlite_file: python reap_dbs.py db_idents.txt

# command run in the github action when cext are not active.
[testenv:github-nocext]
deps = {[testenv]deps}
       .[aiosqlite]
commands=
  python -m pytest {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:IDENTS:} {env:PYTEST_EXCLUDES:} {env:COVERAGE:} {posargs}
  oracle,mssql,sqlite_file: python reap_dbs.py db_idents.txt
