# *****************************************************************************
# Copyright (c) 2025 AISS Group at Harbin Institute of Technology. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# *****************************************************************************

[build-system]
requires = [
  "scikit-build-core>=0.12.1",
  "pybind11>=3.0.0",
  "numpy>=2.0",
  "setuptools-scm==9.2.2",
  "towncrier>=24",
]
build-backend = "scikit_build_core.build"

[project]
name = "asnumpy"
dynamic = ["version"]
description = "A NumPy-like library accelerated by Ascend NPU"
readme = "README.md"
authors = [{ name = "神里绫华的狗", email = "wuzhenqing@stu.hit.edu.cn" }]
license = { text = "Apache-2.0" }
classifiers = [
    "Programming Language :: Python :: 3",
    "Programming Language :: C++",
    "Intended Audience :: Developers",
    "Operating System :: POSIX :: Linux"
]
requires-python = ">=3.10"
dependencies = [
    "numpy>=2.0",
    "loguru>=0.7.0"
]

[project.optional-dependencies]
dev = [
    "ruff>=0.15.0",
    "mypy>=1.19.0",
    "pre-commit>=4.0.0",
]
test = [
    "pytest>=9.0.0",
    "pytest-cov>=7.1.0",
    "pytest-xdist>=3.8.0",
]

[project.urls]
Homepage = "https://gitcode.com/cann/asnumpy"
Repository = "https://gitcode.com/cann/asnumpy"

# scikit-build-core configuration
[tool.scikit-build.wheel]
packages = ["src/asnumpy"]
exclude = ["**/*.pyc", "**/__pycache__", "**/test", "**/tests"]

[tool.scikit-build.install]
components = ["python"]

# CMake configuration
[tool.scikit-build.cmake]
version = ">=3.22"
build-type = "Release"

[tool.scikit-build.cmake.define]
CMAKE_EXPORT_COMPILE_COMMANDS = "ON"

# Ninja configuration
[tool.scikit-build.ninja]
make-fallback = true

# Development mode configuration (pip install -e .)
[tool.scikit-build.editable]
mode = "redirect"
verbose = true

# scikit-build-core metadata configuration
[tool.scikit-build]
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["src/asnumpy/_version.py"]

# setuptools-scm configuration (version from git tags)
[tool.setuptools_scm]
write_to = "src/asnumpy/_version.py"
tag_regex = '^v?(?P<version>[0-9]+\.[0-9]+\.[0-9]+)$'

# towncrier configuration (fragment-based CHANGELOG management)
[tool.towncrier]
directory = "changes"
filename = "CHANGELOG.md"
package = "asnumpy"
package_dir = "src"

# pytest configuration
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = [
    "--import-mode=importlib",
    "-v",
    "--strict-markers",
    "--strict-config",
]

# Coverage configuration (Python layer only; C++ coverage via gcov/lcov post-1.0)
[tool.coverage.run]
source = ["src/asnumpy"]

[tool.coverage.report]
exclude_lines = [
    "pragma: no cover",
    "raise NotImplementedError",
    "if TYPE_CHECKING:",
]

# Ruff configuration (linter + formatter)
[tool.ruff]
target-version = "py310"
line-length = 100
src = ["src", "tests"]

[tool.ruff.lint]
select = [
    "E",      # pycodestyle errors
    "W",      # pycodestyle warnings
    "F",      # Pyflakes
    "I",      # isort
    "UP",     # pyupgrade
    "B",      # flake8-bugbear
    "C4",     # flake8-comprehensions
]
ignore = [
    "E501",   # line too long (handled by formatter)
    "B008",   # function call in default argument (common in NumPy API)
    "B017",   # pytest.raises(Exception) is intentional for NPU operator error diversity
    "UP038",  # isinstance(X, Y) with | syntax not available on Python 3.10
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]

[tool.ruff.lint.isort]

# MyPy configuration
[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
ignore_missing_imports = true
exclude = [
    "build/",
    "dist/",
    "tests/",
]