[build-system]
requires = ["hatchling", "hatch-build-scripts"]
build-backend = "hatchling.build"

[project]
name = "wiki"
description = "A wiki system written for the Django framework."
readme = "README.rst"
requires-python = ">=3.9"
license = "GPL-3.0"
keywords = ["django", "wiki", "markdown"]
authors = [
    { name = "Benjamin Bach", email = "benjamin@overtag.dk" },
]
maintainers = [
    { name = "Oscar Cortez", email = "om.cortez.2010@gmail.com" },
]
classifiers = [
    "Development Status :: 5 - Production/Stable",
    "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
    "Environment :: Web Environment",
    "Framework :: Django",
    "Intended Audience :: Developers",
    "Operating System :: OS Independent",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
    "Programming Language :: Python :: 3.12",
    "Programming Language :: Python :: 3.13",
    "Programming Language :: Python :: Implementation :: CPython",
    "Programming Language :: Python :: Implementation :: PyPy",
    "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
    "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki",
    "Topic :: Software Development",
    "Topic :: Software Development :: Libraries :: Application Frameworks",
]
dependencies = [
    # Django version support is added one minor release at a time
    "Django>=4.0,<5.3",
    # bleach has been pretty stable, hence the loose pin
    "bleach[css]>=6,<7",
    # Pillow is used very little and has never broken
    "Pillow",
    # django-nyt is maintained by django-wiki maintainers, so we can
    # control breakage and pinning ourselves
    "django-nyt>=1.4.2,<1.5",
    # django-mptt has had several breaking changes
    "django-mptt>=0.13,<0.17",
    # django-sekizai is basically only releasing every time
    # it needs to restore support for a new Django/Python version
    "django-sekizai>=0.10",
    # sorl-thumbnail is maintained by jazzband so it might be
    # very stable but it might also suddenly invite breaking changes
    "sorl-thumbnail>=12.8,<13",
    # django-wiki's integration with Markdown is really detailed,
    # several extensions have imported internal APIs, so be very
    # careful here.
    "Markdown>=3.4,<3.10",
    # Set of extensions for Python Markdown.
    "pymdown-extensions>=10.5,<10.6",
]
dynamic = ["version"]

[project.optional-dependencies]
docs = [
    "sphinx>=6,<8",
    "sphinx_rtd_theme==2.0.0",
]

[project.urls]
Homepage = "http://www.django-wiki.org"
Documentation = "https://django-wiki.readthedocs.io/en/latest/"
Tracker = "https://github.com/django-wiki/django-wiki/issues"
Source = "https://github.com/django-wiki/django-wiki"

[[tool.hatch.build.hooks.build-scripts.scripts]]
out_dir = "."
commands = [
    """
    python -c "import os, subprocess, shutil;
readthedocs_env = os.environ.get('READTHEDOCS_VIRTUALENV_PATH');
print('Building SCSS files.');
if readthedocs_env:
    print('READTHEDOCS_VIRTUALENV_PATH is set, skipping SASS compilation');
elif shutil.which('pysassc') is None:
    print('pysassc not found, please install it to proceed.');
else:
    result = subprocess.run(
        [
            'pysassc',
            '--style',
            'compressed',
            'src/wiki/static/wiki/bootstrap/scss/wiki/wiki-bootstrap.scss',
            'src/wiki/static/wiki/bootstrap/css/wiki-bootstrap.min.css'
        ],
        check=False,
        capture_output=True,
        text=True,
    );
    if result.returncode != 0:
        print('Error during SASS compilation:', result.stderr);
        exit(result.returncode);
    "
    """
]
artifacts = [
#    "wiki-bootstrap.min.css",
]
clean_artifacts = false
# clean_out_dir = true

[tool.hatch.publish.index]
disable = true

[tool.hatch.version]
path = "src/wiki/__about__.py"

[tool.hatch.build.targets.sdist]
include = [
    "COPYING",
    "README.rst",
    "/src",
]
exclude = [
    "src/wiki/locale/en/LC_MESSAGES/django.mo",
]

[tool.hatch.envs.default]
dependencies = [
    "ruff==0.1.3",
    "ddt==1.6.0",
    "django-functest>=1.2,<1.6",
    "pre-commit==3.5.0",
    "pytest-cov",
    "pytest-django",
    "pytest-pythonpath",
    "pytest>=6.2.5,<7.3",
    "hatch-build-scripts==0.0.4",
]

[tool.hatch.envs.default.scripts]
lint = [
    "ruff check src/wiki tests/ {args}",
    "pre-commit install -f --install-hooks",
    "pre-commit run --all-files --show-diff-on-failure",
]
format = "ruff format src/wiki tests/ {args}"
clean = [
    "hatch run clean-build",
    "hatch run clean-pyc",
    "rm -fr htmlcov/",
]
clean-build = [
    "rm -fr build",
    "rm -fr dist",
    "rm -fr .eggs",
    "find . -name '*.egg-info' -exec rm -fr {{}} +",
    "find . -name '*.egg' -exec rm -f {{}} +",
]
clean-pyc = [
    "find . -name '*.pyc' -exec rm -f {{}} +",
    "find . -name '*.pyo' -exec rm -f {{}} +",
    "find . -name '*~' -exec rm -f {{}} +",
    "find . -name '__pycache__' -exec rm -fr {{}} +",
]
test = "pytest {args}"

[tool.hatch.envs.test.overrides]
matrix.django.dependencies = [
    { value = "django~={matrix:django}" },
]

[tool.hatch.envs.test]
matrix-name-format = "dj{value}"

[tool.hatch.envs.test.scripts]
all = [
    "sh -c 'testproject/manage.py makemigrations --check'",
    "pytest tests/ --cov=wiki {args}",
]

[[tool.hatch.envs.test.matrix]]
python = ["3.9", "3.10"]
django = ["4.0"]

[[tool.hatch.envs.test.matrix]]
python = ["3.9", "3.10", "3.11"]
django = ["4.1", "4.2"]

[[tool.hatch.envs.test.matrix]]
python = ["3.10", "3.11", "3.12", "3.13"]
django = ["5.0", "5.1", "5.2"]

[tool.hatch.envs.transifex]
dependencies = []

[tool.hatch.envs.transifex.scripts]
push = [
    "touch ~/.transifexrc",
    # Recipe: https://github.com/transifex/cli#running-from-docker-beta
    "docker run --rm -i -t -v `pwd`:/app -v ~/.transifexrc:/.transifexrc -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt transifex/txcli --root-config /.transifexrc push -s",
]
pull = [
    "touch ~/.transifexrc",
    # Recipe: https://github.com/transifex/cli#running-from-docker-beta
    "docker run --rm -i -t -v `pwd`:/app -v ~/.transifexrc:/.transifexrc -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt transifex/txcli --root-config /.transifexrc pull -a",
    # This can have permission errors because of Docker
    # In this case, run chown -R USERNAME:USERGROUP src/wiki/locale
    "cd src/wiki && django-admin compilemessages",
]

[tool.hatch.envs.docs]
dependencies = [
    "sphinx>=6,<8",
    "sphinx_rtd_theme==2.0.0",
]

[tool.hatch.envs.docs.scripts]
clean = "rm -rf docs/_build/*"
html = "sphinx-build -c docs -b html -d docs/_build/doctrees docs/ docs/_build/html"
dirhtml = "sphinx-build -c docs -b dirhtml -d docs/_build/doctrees docs/ docs/_build/dirhtml"
singlehtml = "sphinx-build -c docs -b singlehtml -d docs/_build/doctrees docs/ docs/_build/singlehtml"
pickle = "sphinx-build -c docs -b pickle -d docs/_build/doctrees docs/ docs/_build/pickle"
json = "sphinx-build -c docs -b json -d docs/_build/doctrees docs/ docs/_build/json"
htmlhelp = [
    "sphinx-build -c docs -b htmlhelp -d docs/_build/doctrees docs/ docs/_build/htmlhelp",
    "echo 'Build finished; now you can run HTML Help Workshop with the .hhp project file in docs/_build/htmlhelp.'",
]
qthelp = [
    "sphinx-build -c docs -b qthelp -d docs/_build/doctrees docs/ docs/_build/qthelp",
    "echo 'Build finished; now you can run qcollectiongenerator with the .qhcp project file in docs/_build/qthelp, like this:'",
    "echo '# qcollectiongenerator docs/_build/qthelp/django-wiki.qhcp'",
    "echo 'To view the help file:'",
    "echo '# assistant -collectionFile docs/_build/qthelp/django-wiki.qhc'",
]
devhelp = [
    "sphinx-build -c docs -b devhelp -d docs/_build/doctrees docs/ docs/_build/devhelp",
    "echo 'Build finished.'",
    "echo 'To view the help file:'",
    "echo '# mkdir -p $$HOME/.local/share/devhelp/django-wiki'",
    "echo '# ln -s docs/_build/devhelp $$HOME/.local/share/devhelp/django-wiki'",
    "echo '# devhelp'",
]
epub = "sphinx-build -c docs -b epub -d docs/_build/doctrees docs/ docs/_build/epub"
latex = [
    "sphinx-build -c docs -b latex -d docs/_build/doctrees -D latex_paper_size={args} docs/ docs/_build/latext",
    "echo 'Build finished; the LaTeX files are in docs/_build/latex.'",
    "echo 'Run `make` in that directory to run these through (pdf)latex'",
    "echo '(use `make latexpdf` here to do that automatically).'",
]
latexpdf = [
    "sphinx-build -c docs -b latex -d docs/_build/doctrees -D latex_paper_size={args} docs/ docs/_build/latext",
    "echo 'Running LaTeX files through pdflatex...'",
    "make -C docs/_build/latex all-pdf",
    "echo 'pdflatex finished; the PDF files are in docs/_build/latex.'",
]
text = "sphinx-build -c docs -b text -d docs/_build/doctrees  docs/ docs/_build/text"
man = "sphinx-build -c docs -b man -d docs/_build/doctrees  docs/ docs/_build/man"
texinfo = [
    "sphinx-build -c docs -b text -d docs/_build/doctrees  docs/ docs/_build/text",
    "echo 'Build finished. The Texinfo files are in docs/_build/texinfo.'",
    "echo 'Run `make` in that directory to run these through makeinfo'",
    "echo '(use `make info` here to do that automatically).'",
]
info = [
    "sphinx-build -c docs -b texinfo -d docs/_build/doctrees  docs/ docs/_build/texinfo",
    "echo 'Running Texinfo files through makeinfo...'",
    "make -C docs/_build/texinfo info",
    "echo 'makeinfo finished; the Info files are in docs/_build/texinfo.'",
]
gettext = "sphinx-build -c docs -b gettext  docs/_build/locale"
changes = "sphinx-build -c docs -b changes -d docs/_build/doctrees  docs/ docs/_build/changes"
link-check2 = "sphinx-build -c docs -b linkcheck -d docs/_build/doctrees  docs/ docs/_build/linkcheck"
doctest = "sphinx-build -c docs -b doctest -d docs/_build/doctrees  docs/ docs/_build/doctest"
build = [
    "hatch run docs:clean",
    "rm -f docs/wiki*.rst",
    "rm -f docs/modules.rst",
    "sphinx-apidoc -o docs/ src/wiki",
    "hatch run docs:html {args}",
    """
    python -c '
import os, webbrowser, sys
try:
  from urllib import pathname2url
except:
  from urllib.request import pathname2url

  webbrowser.open(\"file://\" + pathname2url(os.path.abspath(\"docs/_build/html/index.html\")))
    '"""
]
link-check = "sphinx-build -b linkcheck ./docs ./docs/_build"

[tool.coverage.run]
disable_warnings = ['no-data-collected']
branch = true
parallel = true
source = [
    "src/",
]
omit = [
    ".DS_Store",
    "*/tests/*",
    "src/wiki/__about__.py",
]

[tool.coverage.report]
exclude_lines = [
    "no cov",
    "if __name__ == .__main__.:",
    "if TYPE_CHECKING:",
]

[tool.ruff]
exclude = ["env", "_build", "CVS", "__pycache__", ".eggs", "*.egg", "*/*migrations", "testproject"]
extend-ignore = ["E203"]
line-length = 79

[tool.ruff.mccabe]
max-complexity = 10

[tool.pytest.ini_options]
django_find_project = false
testpaths = [
    "tests",
]
norecursedirs = [
    "testproject",
    ".svn",
    "_build",
    "tmp*",
    "dist",
    "*.egg-info",
]
DJANGO_SETTINGS_MODULE = "tests.settings"
