
[tox]
envlist = py

[greenletextras]
extras=
     asyncio
     sqlite: aiosqlite
     sqlite_file: aiosqlite
     postgresql: postgresql_asyncpg
     mysql: asyncmy
     mysql: aiomysql
     mssql: aioodbc

     # not greenlet, but tends to not have packaging until the py version
     # has been fully released
     mssql: mssql_pymssql

[testenv]
cov_args=--cov=sqlalchemy --cov-report term --cov-append --cov-report xml --exclude-tag memory-intensive --exclude-tag timing-intensive -k "not aaa_profiling"

# this needs to be set as of tox 4.4.0 *if* we have extras (e.g. .[aiosqlite])
# inside of deps.  But we put them in extras now.
# see https://github.com/tox-dev/tox/issues/2898
# constrain_package_deps=false

usedevelop=
     cov: True

extras=
     py{3,37,38,39,310,311,312,313}: {[greenletextras]extras}

     py{37,38,39,310}-sqlite_file: sqlcipher
     postgresql: postgresql
     postgresql: postgresql_pg8000
     postgresql: postgresql_psycopg

     mysql: mysql
     mysql: pymysql
     mysql: mariadb_connector

     oracle: oracle
     oracle: oracle_oracledb
     mssql: mssql

install_command=
     # TODO: I can find no way to get pip / tox / anyone to have this
     # --only-binary option local to the pymssql install, rather than global
     # as it is here.
     python -I -m pip install --only-binary=pymssql {opts} {packages}

deps=
     pytest>=7.0.0,<8.4
     # tracked by https://github.com/pytest-dev/pytest-xdist/issues/907
     pytest-xdist!=3.3.0

     py313: git+https://github.com/python-greenlet/greenlet.git\#egg=greenlet

     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

     py313-mssql: git+https://github.com/mkleehammer/pyodbc.git\#egg=pyodbc
     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"

    # ensure older pip is installed for EOL python versions
    py37: VIRTUALENV_PIP=24.0

    PYTEST_COLOR={tty:--color=yes}
    MYPY_COLOR={tty:--color-output}

    BASECOMMAND=python -m pytest {env:PYTEST_COLOR} --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}

    oracle: EXTRA_ORACLE_DRIVERS={env:EXTRA_ORACLE_DRIVERS:--dbdriver cx_oracle --dbdriver oracledb --dbdriver oracledb_async}
    py{313,314}-oracle: EXTRA_ORACLE_DRIVERS={env:EXTRA_ORACLE_DRIVERS:--dbdriver cx_oracle --dbdriver oracledb}

    sqlite: SQLITE={env:TOX_SQLITE:--db sqlite}
    sqlite_file: SQLITE={env:TOX_SQLITE_FILE:--db sqlite_file}

    sqlite: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver pysqlite_numeric --dbdriver aiosqlite}
    py{313,314}-sqlite: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver pysqlite_numeric}

    sqlite-nogreenlet: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver pysqlite_numeric}

    py{37,38,39}-sqlite_file: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite --dbdriver pysqlcipher}

    # omit pysqlcipher for Python 3.10
    py{3,310,311,312}-sqlite_file: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite}

    postgresql: POSTGRESQL={env:TOX_POSTGRESQL:--db postgresql}

    postgresql: EXTRA_PG_DRIVERS={env:EXTRA_PG_DRIVERS:--dbdriver psycopg2 --dbdriver asyncpg --dbdriver pg8000 --dbdriver psycopg --dbdriver psycopg_async}
    postgresql-nogreenlet: EXTRA_PG_DRIVERS={env:EXTRA_PG_DRIVERS:--dbdriver psycopg2 --dbdriver pg8000 --dbdriver psycopg}

    # limit driver list for memusage target
    memusage: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite}
    memusage: EXTRA_PG_DRIVERS={env:EXTRA_PG_DRIVERS:--dbdriver psycopg2}
    # limit workers for memusage
    memusage: WORKERS={env:TOX_WORKERS:-n2}

    mysql: MYSQL={env:TOX_MYSQL:--db mysql}
    mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver asyncmy --dbdriver aiomysql --dbdriver mariadbconnector}
    mysql-nogreenlet: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver mariadbconnector}

    mssql: MSSQL={env:TOX_MSSQL:--db mssql}
    mssql: EXTRA_MSSQL_DRIVERS={env:EXTRA_MSSQL_DRIVERS:--dbdriver pyodbc --dbdriver aioodbc --dbdriver pymssql}
    py{313,314}-mssql: EXTRA_MSSQL_DRIVERS={env:EXTRA_MSSQL_DRIVERS:--dbdriver pyodbc  --dbdriver aioodbc}

    mssql-nogreenlet: EXTRA_MSSQL_DRIVERS={env:EXTRA_MSSQL_DRIVERS:--dbdriver pyodbc --dbdriver pymssql}
    py{313,314}-mssql-nogreenlet: EXTRA_MSSQL_DRIVERS={env:EXTRA_MSSQL_DRIVERS:--dbdriver pyodbc}

    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
    EXTRA_ORACLE_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"
  nogreenlet: pip uninstall -y greenlet
  {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:EXTRA_ORACLE_DRIVERS:} {env:MSSQL:} {env:EXTRA_MSSQL_DRIVERS:} {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 >= 1.14.0
     types-greenlet
commands =
    mypy  {env:MYPY_COLOR} ./lib/sqlalchemy
    # pyright changes too often with not-exactly-correct errors
    # suddently appearing for it to be stable enough for CI
    # pyright

extras =
     {[greenletextras]extras}

[testenv:mypy]
deps=
     pytest>=7.0.0rc1,<8.4
     pytest-xdist
     greenlet != 0.4.17
     importlib_metadata; python_version < '3.8'
     mypy >= 1.2.0,<1.11.0
     patch==1.*
extras=
     {[greenletextras]extras}

commands =
    pytest {env:PYTEST_COLOR} -m mypy {posargs}

[testenv:mypy-cov]

deps=
     {[testenv:mypy]deps}
     pytest-cov

extras=
     {[greenletextras]extras}

commands =
    pytest {env:PYTEST_COLOR} -m mypy {env:COVERAGE} {posargs}

setenv=
    COVERAGE={[testenv]cov_args}

# thanks to https://julien.danjou.info/the-best-flake8-extensions/
[testenv:lint]
basepython = python3

extras=
     {[greenletextras]extras}

deps=
      flake8==6.1.0
      flake8-import-order
      flake8-builtins
      flake8-future-annotations>=0.0.5
      flake8-docstrings>=1.6.0
      flake8-import-single==0.1.5
      flake8-unused-arguments
      flake8-rst-docstrings
      # flake8-rst-docstrings dependency, leaving it here
      # in case it requires a version pin
      pydocstyle
      pygments
      black==24.10.0
      slotscheck>=0.17.0

      # required by generate_tuple_map_overloads
      zimports
allowlist_externals =
    env
    git
    sh
commands =
     flake8 ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs}
     # run flake8-unused-arguments only on some files / modules
     flake8  --extend-ignore='' ./lib/sqlalchemy/ext/asyncio ./lib/sqlalchemy/orm/scoping.py
     black --check ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py
     # test with cython and without cython exts running
     slotscheck -m sqlalchemy
     env DISABLE_SQLALCHEMY_CEXT_RUNTIME=1 slotscheck -m sqlalchemy
     python ./tools/format_docs_code.py --check
     python ./tools/generate_tuple_map_overloads.py --check
     python ./tools/generate_proxy_methods.py --check
     python ./tools/sync_test_files.py --check
     python ./tools/generate_sql_functions.py --check
     python ./tools/normalize_file_headers.py --check
     python ./tools/walk_packages.py


# "pep8" env was renamed to "lint".
# Kept for backwards compatibility until rename is completed elsewhere.
[testenv:pep8]
basepython = {[testenv:lint]basepython}
deps = {[testenv:lint]deps}
allowlist_externals = {[testenv:lint]allowlist_externals}
commands = {[testenv:lint]commands}
extras = {[testenv:lint]extras}



# command run in the github action when cext are active.
[testenv:github-cext]
extras=
     {[greenletextras]extras}

deps = {[testenv]deps}
       .[aiosqlite]
commands=
  python -m pytest {env:PYTEST_COLOR} {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]
extras=
     {[greenletextras]extras}

deps = {[testenv]deps}
       .[aiosqlite]
commands=
  python -m pytest {env:PYTEST_COLOR} {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
