content: # Package ######################################################################
  
  [build-system]
  requires = ["setuptools >= 77.0", "pybind11 >= 2.12"]
  build-backend = "setuptools.build_meta"
  
  [project]
  name = "optree"
  description = "Optimized PyTree Utilities."
  readme = "README.md"
  requires-python = ">= 3.9"
  authors = [{ name = "OpTree Contributors" }]
  license = "Apache-2.0"
  keywords = [
      "PyTree",
      "Tree Manipulation",
      "Tree Traversal",
      "Functional Programming",
  ]
  classifiers = [
      "Development Status :: 4 - Beta",
      "Programming Language :: C++",
      "Programming Language :: Python :: 3",
      "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 :: 3.14",
      "Programming Language :: Python :: Implementation :: CPython",
      "Programming Language :: Python :: Implementation :: PyPy",
      "Operating System :: Microsoft :: Windows",
      "Operating System :: POSIX :: Linux",
      "Operating System :: MacOS",
      "Intended Audience :: Developers",
      "Intended Audience :: Education",
      "Intended Audience :: Science/Research",
      "Topic :: Utilities",
  ]
  dependencies = ["typing-extensions >= 4.6.0"]
  dynamic = ["version"]
  
  [project.urls]
  Homepage = "https://github.com/metaopt/optree"
  Repository = "https://github.com/metaopt/optree"
  Documentation = "https://optree.readthedocs.io"
  "Bug Report" = "https://github.com/metaopt/optree/issues"
  
  [project.optional-dependencies]
  jax = ["jax"]
  numpy = ["numpy"]
  torch = ["torch"]
  lint = [
      "ruff",
      "pylint[spelling]",
      "mypy",
      "doc8",
      "pyenchant",
      "xdoctest",
      "cpplint",
      "pre-commit",
  ]
  test = [
      "pytest",
      "pytest-cov",
      "covdefaults",
      "rich",
  ]
  docs = [
      "sphinx",
      "sphinx-autoapi",
      "sphinx-autobuild",
      "sphinx-copybutton",
      "sphinx-rtd-theme",
      "sphinxcontrib-bibtex",
      "sphinx-autodoc-typehints",
      "docutils",
      "jax[cpu]",
      "numpy",
      "torch",
  ]
  
  [tool.setuptools]
  include-package-data = true
  
  [tool.setuptools.packages.find]
  include = ["optree", "optree.*"]
  
  [tool.setuptools.package-data]
  optree = ["*.so", "*.pyd", "*.pyi", "*.typed"]
  
  # Wheel builder ################################################################
  # Reference: https://cibuildwheel.pypa.io
  [tool.cibuildwheel]
  archs = ["native"]
  enable = ["pypy", "cpython-freethreading"]
  skip = "*musllinux*"
  build-frontend = "build"
  environment = { PYTHONDEVMODE = "1", PYTHONUNBUFFERED = "1" }
  environment-pass = [
      "CMAKE_MINIMUM_VERSION",
      "CMAKE_CXX_STANDARD",
      "OPTREE_CXX_WERROR",
      "_GLIBCXX_USE_CXX11_ABI",
      "COLUMNS",
      "FORCE_COLOR",
      "CLICOLOR_FORCE",
  ]
  xbuild-tools = ["cmake"]
  before-build = "env -0 | sort -z | tr '\\0' '\\n'"
  windows.before-build = "set"
  test-extras = ["test"]
  test-sources = ["pyproject.toml", "tests"]
  test-command = [
      '''python -m pytest --version''',
      '''python -Walways -Werror -c "import optree"''',
      '''python -Walways -Werror -c "import rich, optree._C; rich.inspect(optree._C, value=True, methods=True)"''',
      '''python -m pytest -Walways --color=yes --showlocals --no-cov --exitfirst tests''',
  ]
  
  [tool.cibuildwheel.android]
  environment = { PYTHONDEVMODE = "1", PYTHONUNBUFFERED = "1", ANDROID_API_LEVEL = "24" }
  
  [tool.cibuildwheel.ios]
  environment = { PYTHONDEVMODE = "1", PYTHONUNBUFFERED = "1", CMAKE_SYSTEM_NAME = "iOS" }
  test-command = '''python -m pytest -Walways --color=yes --showlocals --no-cov --exitfirst tests'''
  
  [[tool.cibuildwheel.overrides]]
  select = "*iphoneos*"
  inherit.environment = "append"
  environment = { CMAKE_OSX_SYSROOT = "iphoneos" }
  
  [[tool.cibuildwheel.overrides]]
  select = "*iphonesimulator*"
  inherit.environment = "append"
  environment = { CMAKE_OSX_SYSROOT = "iphonesimulator" }
  
  # Linter tools #################################################################
  
  [tool.mypy]
  python_version = "3.9"
  exclude = ['^tests/.*\.py$', '^(third|3rd)[_\-]?party/.*$', '^\.?venv/.*$']
  pretty = true
  show_column_numbers = true
  show_error_codes = true
  show_error_context = true
  show_traceback = true
  allow_redefinition = true
  check_untyped_defs = true
  disallow_incomplete_defs = true
  disallow_untyped_defs = true
  ignore_missing_imports = true
  no_implicit_optional = true
  strict_equality = true
  strict_optional = true
  warn_no_return = true
  warn_redundant_casts = true
  warn_unreachable = true
  warn_unused_configs = true
  warn_unused_ignores = true
  no_site_packages = true
  
  [tool.pylint]
  main.py-version = "3.9"
  main.extension-pkg-allow-list = ["optree._C"]
  main.ignore-paths = ['^tests/$', '^(third|3rd)[_\-]?party/$']
  basic.good-names = []
  design.max-args = 7
  format.max-line-length = 120
  messages-control.disable = [
      "consider-using-from-import",
      "duplicate-code",
      "unpacking-non-sequence",
      "unsubscriptable-object",
      "wrong-import-order",
  ]
  messages-control.enable = ["c-extension-no-member"]
  spelling.spelling-dict = "en_US"
  spelling.spelling-private-dict-file = "docs/source/spelling_wordlist.txt"
  typecheck.generated-members = ["numpy.*", "torch.*"]
  
  [tool.doc8]
  max-line-length = 500
  
  [tool.codespell]
  builtin = "clear,rare,en-GB_to_en-US"
  ignore-words = "docs/source/spelling_wordlist.txt"
  
  [tool.ruff]
  target-version = "py39"
  line-length = 100
  output-format = "full"
  src = ["optree", "tests"]
  
  [tool.ruff.format]
  quote-style = "single"
  docstring-code-format = false
  skip-magic-trailing-comma = false
  
  [tool.ruff.lint]
  select = [
      "E", "W",  # pycodestyle
      "F",       # pyflakes
      "I",       # isort
      "C90",     # mccabe
      "N",       # pep8-naming
      "UP",      # pyupgrade
      "D",       # pydocstyle
      "ANN",     # flake8-annotations
      "S",       # flake8-bandit
      "BLE",     # flake8-blind-except
      "B",       # flake8-bugbear
      "COM",     # flake8-commas
      "C4",      # flake8-comprehensions
      "EXE",     # flake8-executable
      "FA",      # flake8-future-annotations
      "ISC",     # flake8-implicit-str-concat
      "LOG",     # flake8-logging
      "INP",     # flake8-no-pep420
      "PIE",     # flake8-pie
      "PYI",     # flake8-pyi
      "PT",      # flake8-pytest-style
      "Q",       # flake8-quotes
      "RSE",     # flake8-raise
      "RET",     # flake8-return
      "SIM",     # flake8-simplify
      "SLOT",    # flake8-slots
      "TID",     # flake8-tidy-imports
      "TC",      # flake8-type-checking
      "NPY",     # numpy
      "PERF",    # perflint
      "FURB",    # refurb
      "TRY",     # tryceratops
      "RUF",     # ruff
  ]
  ignore = [
      # E501: line too long
      # W505: doc line too long
      # too long docstring due to long example blocks
      "E501",
      "W505",
      # ANN401: dynamically typed expressions (typing.Any) are disallowed
      "ANN401",
      # N999: invalid module name
      # optree._C is not snake_cased
      "N999",
      # S101: use of `assert` detected
      # internal use and may never raise at runtime
      "S101",
      # TRY003: avoid specifying long messages outside the exception class
      # long messages are necessary for clarity
      "TRY003",
      # RUF022: `__all__` is not ordered according to an "isort-style" sort
      # `__all__` contains comments to group names
      "RUF022",
  ]
  typing-modules = ["optree.typing"]
  
  [tool.ruff.lint.per-file-ignores]
  "__init__.py" = [
      "F401",    # unused-import
  ]
  "setup.py" = [
      "D",       # pydocstyle
  ]
  "tests/**/*.py" = [
      "D",       # pydocstyle
      "ANN",     # flake8-annotations
      "S",       # flake8-bandit
      "SIM",     # flake8-simplify
      "INP001",  # flake8-no-pep420
  ]
  "docs/source/conf.py" = [
      "D",       # pydocstyle
      "ANN",     # flake8-annotations
      "INP001",  # flake8-no-pep420
  ]
  ".github/workflows/**/*.py" = [
      "D",       # pydocstyle
  ]
  
  [tool.ruff.lint.isort]
  known-first-party = ["optree"]
  extra-standard-library = ["typing_extensions"]
  lines-after-imports = 2
  
  [tool.ruff.lint.pydocstyle]
  convention = "google"
  
  [tool.ruff.lint.flake8-annotations]
  allow-star-arg-any = true
  
  [tool.ruff.lint.flake8-quotes]
  docstring-quotes = "double"
  multiline-quotes = "double"
  inline-quotes = "single"
  
  [tool.ruff.lint.flake8-tidy-imports]
  ban-relative-imports = "all"
  
  [tool.pytest.ini_options]
  verbosity_assertions = 3
  filterwarnings = ["always", "error"]
  