[tasks.check-venv]
description = "Check if a virtual environment is activated"
script = [
    '''
    if [ -z "$VIRTUAL_ENV" ]; then
        echo "No virtual environment activated. Please activate one."
        exit 1
    else
        echo "Virtual environment is active."
    fi
    '''
]

[tasks.upgrade-pip]
dependencies = ["check-venv"]
description = "Upgrade pip to ensure it supports depency groups"
command = "pip"
args = ["install", "--upgrade", "pip"]

[tasks.install-uv]
dependencies = ["check-venv", "upgrade-pip"]
description = "Install dependencies using uv"
command = "pip"
args = ["install", "uv"]

[tasks.install-deps]
dependencies = ["install-uv"]
description = "Install dependencies using uv"
command = "uv"
args = ["pip", "install", "--group", "dev", "."]

[tasks.install-python-package]
dependencies = ["install-deps"]
description = "Build the qcs-api-client-common python package and install it in the current virtual environment."
command = "maturin"
args = ["develop"]

[tasks.generate-stubs]
description = "Generate Python stub files."
command = "cargo"
args = ["run", "-p", "qcs-api-client-common", "--features", "stubs", "--bin", "stub_gen"]
install_crate = false

[tasks.stubtest]
dependencies = ["generate-stubs", "install-python-package"]
description = "Validate type stubs using stubtest"
cwd = "python"
command = "stubtest"
args = [
    "--allowlist", "stubtest-allowlist",
    "--ignore-unused-allowlist",
    "--ignore-disjoint-bases",
    "qcs_api_client_common",
]

[tasks.pytest]
dependencies = ["install-python-package"]
description = "Run the Python unit test suite."
command = "pytest"
args = ["tests_py", "-vv"]

[tasks.pytest-integration]
dependencies = ["install-python-package"]
description = "Run the integration tests in the Python test suite. Requires a valid QCS configuration."
command = "pytest"
args = ["tests_py", "--integration"]

[tasks.build-python-docs]
dependencies = ["install-python-package", "generate-stubs"]
description = "Build the Sphinx documentation."
cwd = "docs"
script = [
    '''
    make html
    '''
]

[tasks.ruff-check]
dependencies = ["install-uv"]
command = "ruff"
args = ["check"]

[tasks.check-python-api]
description = "Check if Python API has breaking changes."
dependencies = ["generate-stubs", "install-python-package"]
script = { file = "./scripts/check-py-api.sh" }

[tasks.check-python-bindings]
description = "Find errors in the Python-related Rust code."
command = "uv"
args = [
    "run",
    "--group", "dev",
    "python",
    "./scripts/lint-bindings.py",
    "--base", "src",
    "--show-mistakes",
]

[tasks.show-python-layout]
description = "Print the Python package layout as defined within the Rust code."
command = "uv"
args = [
    "run",
    "--group", "dev",
    "python",
    "./scripts/lint-bindings.py",
    "--base", "src",
    "--show-package",
]

[tasks.check-python]
dependencies = [
    "check-python-bindings",
    "check-python-api",
    "stubtest",
    "ruff-check",
]

[tasks.dev-flow]
dependencies = ["dev-test-flow", "check-python", "pytest"]

[tasks.test]
dependencies = ["test-in-ci"]

[tasks.test-in-ci]
description = "Tasks that only run when the CI environment variable is set."
condition = { env_set = ["CI"] }
run_task = [
  { name = "test-credentials" },
]

[tasks.test-credentials]
command = "cargo"
args = ["test", "test_client_credentials", "--", "--ignored"]

[tasks.default]
alias = "dev-flow"

