# derivative-dist-compare, Debian package tracker for derivative distributions
# Copyright (C) 2024-2026 IKUS Software <patrik@ikus-soft.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

[tox]
envlist = py3,lint

# This is not working in all environment.
[testenv]
deps =
  pytest-cov
extras = test
allowlist_externals =
  ln
commands =
  ln -sf /usr/lib/python3/dist-packages/apt_pkg.cpython-311-x86_64-linux-gnu.so {envsitepackagesdir}
  ln -sf /usr/lib/python3/dist-packages/apt {envsitepackagesdir}
  pytest -v --debug --ignore=debian --override-ini junit_family=xunit1 --junit-xml=xunit.xml --cov=derivative_dist_compare --cov-report xml:coverage.xml

[testenv:lint]
deps = .[dev]
allowlist_externals = sh
commands = 
  black --check --diff src
  isort --check --diff src
  flake8 src
  sh -c 'djlint --check src/derivative_dist_compare/**.html'
skip_install = true

[testenv:format]
deps = .[dev]
allowlist_externals = sh
commands =
  black src
  isort src
  sh -c 'djlint --reformat src/derivative_dist_compare/**.html'
skip_install = true

# Update CHANGELOG.md and debian/changelog
[testenv:changelog]
deps = 
  git-changelog==2.9.1
commands =
  git-changelog
  git-changelog --template "debian" --output "debian/changelog"
skip_install = true

# Bump version and git tag
[testenv:bump]
deps = 
  git-changelog==2.9.1
allowlist_externals =
  bash
  git
commands =
  git-changelog --bump auto {posargs}
  git-changelog --bump auto --template "debian" --output "debian/changelog" {posargs}
  # Create git tag
  git add CHANGELOG.md debian/changelog
  bash -c 'git commit -m "Release version $(git-changelog --bumped-version)"'
  bash -c 'git tag $(git-changelog --bumped-version)'
skip_install = true

[flake8]
ignore =
  # whitespace before ':'
  E203
  # line too long (86 > 79 characters)
  E501
   # line break before binary operator
  W503
   # ambiguous variable name 'I'
  E741
filename =
  *.py
max-complexity = 20
copyright-check = True
copyright-min-file-size = 5

[coverage:paths]
source = src/derivative_dist_compare
    */.tox/*/lib/python*/site-packages/derivative_dist_compare
    */src/derivative_dist_compare
