[build-system]
requires = [
    "hatchling",
    "hatch-build-scripts",
    "hatch-requirements-txt",
    "hatch-sphinx",
    "hatch-vcs",
    # For documentation
    "bumps",
    "dominate",
    "html2text",
    "numpy",
    "periodictable",
    "pyopengl",
    "pyside6",
    "qtconsole",
    "scipy",
    "superqt",
    "sasdata",
    "sasmodels",
    "twisted",
    "uncertainties",
]
build-backend = "hatchling.build"


[project]
name = "sasview"
dynamic = [
    "version",
    "dependencies",
    "optional-dependencies",
]
description = "SasView application"
readme = "README.md"
requires-python = ">=3.12"
license = { text = "BSD-3-Clause" }
authors = [
    {name = "SasView Team", email = "developers@sasview.org"},
]
classifiers = [
  "Development Status :: 5 - Production/Stable",
  "Programming Language :: Python",
  "Intended Audience :: Science/Research",
  "License :: OSI Approved :: BSD License",
]
keywords = [
  "small-angle",
  "scattering",
  "data analysis",
  "neutron",
  "X-ray",
]


[project.urls]
Homepage = "http://sasview.org"
Documentation = "https://www.sasview.org/docs/"
Repository = "https://github.com/SasView/sasview/"
Issues = "https://github.com/SasView/sasview/issues"
Changelog = "https://github.com/SasView/sasview/releases"

[project.scripts]
sasview = "sas.cli:main"

[project.entry-points.pyinstaller40]
hook-dirs = "sas.__pyinstaller:get_hook_dirs"


[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.metadata.hooks.requirements_txt]
files = [ "build_tools/requirements.txt" ]

[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
test = [ "build_tools/requirements-test.txt" ]
dev = [ "build_tools/requirements-dev.txt" ]


[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "src/sas/system/_version.py"


[tool.hatch.build.targets.sdist]
include = [
  "build_tools",
  "build/lib/doc/build",
  "docs/sphinx-docs/source",
  "docs/sphinx-docs/*.py",
  "src",
  "test",
]
exclude = [
  "docs/sphinx-docs/source-temp",
  "downloads",
]
ignore-vcs = true


[tool.hatch.build.targets.wheel]
sources = ["src"]
packages = ["src/sas"]
include = [
]
exclude = [
  "**/media/**",
  "*.ui",
  "*.bat",
  "*.sh",
]
artifacts = [
  "**/UI/*py",
]

[tool.hatch.build.targets.wheel.force-include]
"build/doc/html/" = "sas/docs"
"src/sas/example_data/" = "sas/example_data"


[[tool.hatch.build.targets.wheel.hooks.build-scripts.scripts]]
# Perform Qt UI conversion steps (uic, rcc etc)
commands = [
    "python src/sas/qtgui/convertUI.py",
]
# out_dir = "GUI-output"
artifacts = [
    # "**/UI/*py",
]


[[tool.hatch.build.targets.wheel.hooks.sphinx.tools]]
tool = "custom"
doc_dir = "."
out_dir = "tmp"
commands = [
  # sphinx commands work within the "doc_dir" directory
  "{python} src/sas/system/resources.py -r sasmodels docs-source docs/sphinx-docs/tmp/sasmodels/docs",
  "{python} src/sas/system/resources.py -r sasdata docs-source docs/sphinx-docs/tmp/sasdata/docs",
  "{python} src/sas/system/resources.py -r sasdata example_data src/sas/example_data/",
]


[[tool.hatch.build.targets.wheel.hooks.sphinx.tools]]
tool = "custom"
doc_dir = "docs/sphinx-docs"
out_dir = "source-temp"
environment = { PYTHONPATH = "../../src" }
commands = [
  "{python} collect_sphinx_sources.py",
]

[[tool.hatch.build.targets.wheel.hooks.sphinx.tools]]
tool = "apidoc"
doc_dir = "docs/sphinx-docs"
source = "../../src"
out_dir = "source-temp/dev/sasview-api"
depth = 8
private = false
separate = false
header = "SasView"
exclude = [
    "*/UnitTesting/*",
    "sas/webfit*",
    "sas/qtgui/Perspectives/ParticleEditor/calculations*",
    "sas/qtgui/Perspectives/ParticleEditor/Plots*",
    "sas/qtgui/Utilities/WhatsNew/messages*",
    "sas/sascalc/calculator/ausaxs*",
]

[[tool.hatch.build.targets.wheel.hooks.sphinx.tools]]
tool = "build"
format = "html"
doc_dir = "docs/sphinx-docs/source-temp"
out_dir = "../../../build/doc/html"
warnings = false
keep_going = true
sphinx_opts = "-d ../../../build/doc/html/doctrees"
environment = { PYTHONPATH = "../../../src" }


[tool.pytest.ini_options]
minversion = "6.0"
python_files = [
    "u*py",
    "*Test*py",
]
python_classes = [
    "*Test",
    "Test*",
]
qt_api = "pyside6"
addopts = [
    "-v",
    "-rsx",
]
log_level = "DEBUG"
filterwarnings = [
]
testpaths = [
    "src",
    "tests",
]
pythonpath = "src"
norecursedirs = [
    "test/sasrealspace",
    "test/calculatorview",
    "src/sas/qtgui/MainWindow/UnitTesting/Quarantine",
    "src/sas/qtgui/Perspectives/Fitting/UnitTesting/Quarantine",
    "src/sas/qtgui/Perspectives/Inversion",
    "src/sas/qtgui/Perspectives/ParticleEditor",
    "src/sas/qtgui/Utilities/UnitTesting/Quarantine"
]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
# The ruff rules are available at: https://docs.astral.sh/ruff/rules/
select = ["E",       # pycodestyle errors
          "F",       # pyflakes
          "I",       # isort
          "UP",      # pyupgrade
          "W",       # pycodestyle warnings
          "SIM118",  # Use `key in dict` instead of `key in dict.keys()`
          "SIM300"]  # Yoda condition detected

ignore = ["E501",  # line too long (leave to formatter)
          "UP008", # Use `super()` instead of `super(__class__, self)`
          "UP031"] # Use format specifiers instead of percent format

[tool.ruff.lint.isort.sections]
# Group all SasData and SasModels imports into a separate section.
"sas" = ["sasdata", "sasmodels"]

[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "third-party", "sas", "first-party", "local-folder"]