[project]
name = "tinygrad"
version = "0.14.0"
description = "You like pytorch? You like micrograd? You love tinygrad! <3"
authors = [{ name = "George Hotz" }]

classifiers = ["Programming Language :: Python :: 3"]

license = 'MIT'
readme = "README.md"
requires-python = ">=3.11"
dependencies = []

[build-system]
requires = ["setuptools>=77"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true
packages = [
  'tinygrad',
  'tinygrad.codegen',
  'tinygrad.codegen.decomp',
  'tinygrad.codegen.opt',
  'tinygrad.codegen.late',
  'tinygrad.engine',
  'tinygrad.llm',
  'tinygrad.mixin',
  'tinygrad.nn',
  'tinygrad.renderer',
  'tinygrad.renderer.amd',
  'tinygrad.renderer.isa',
  'tinygrad.runtime',
  'tinygrad.runtime.autogen',
  'tinygrad.runtime.autogen.am',
  'tinygrad.runtime.autogen.amd',
  'tinygrad.runtime.autogen.amd.rdna3',
  'tinygrad.runtime.autogen.amd.rdna4',
  'tinygrad.runtime.autogen.amd.cdna',
  'tinygrad.runtime.autogen.nv_regs',
  'tinygrad.runtime.graph',
  'tinygrad.runtime.support',
  'tinygrad.runtime.support.am',
  'tinygrad.runtime.support.mlx',
  'tinygrad.runtime.support.nv',
  'tinygrad.schedule',
  'tinygrad.uop',
  'tinygrad.viz',
]

[tool.setuptools.package-data]
tinygrad = ["py.typed"]
"tinygrad.llm" = ["chat.html"]
"tinygrad.viz" = ["index.html", "assets/**/*", "js/*"]


[project.optional-dependencies]
# arm = ["unicorn"]
# triton = ["triton-nightly>=2.1.0.dev20231014192330"]
linting = [
  "pylint",
  "mypy==1.19.1",
  "typing-extensions",
  "pre-commit",
  "ruff==0.14.10",
  "numpy",
  "typeguard",
]
# mlperf = [
#   "mlperf-logging @ git+https://github.com/mlperf/logging.git@5.0.0-rc3",
# ]
testing_minimal = [
  "numpy",
  "torch==2.9.1",
  "pytest",
  "pytest-xdist",
  "pytest-split",
  "hypothesis>=6.148.9",
  "z3-solver<4.15.4",  # 4.15.4 has a segfault when creating many z3.Context()
]
testing_unit = ["tinygrad[testing_minimal]", "tqdm", "safetensors", "tabulate", "openai", "gguf>=0.18", "capstone"]
testing = [
  "tinygrad[testing_unit]",
  "pillow",
  "onnx==1.19.0",
  "onnx2torch",
  "onnxruntime==1.24.1",
  "opencv-python",
  "transformers",
  "sentencepiece",
  "tiktoken",
  "blobfile",
  "librosa",
  # librosa needs numba but uv ignores python upper bounds and some numba versions require <python3.10
  "numba>=0.55",
  "networkx",
  "nibabel",
  "bottle",
  "pycocotools",
  "boto3",
  "pandas",
  "influxdb3-python",
]
docs = [
  "mkdocs",
  "mkdocs-material",
  "mkdocstrings[python]",
  "markdown-callouts",
  "markdown-exec[ansi]",
  "black",
  "numpy",
]
mesa = ["tinymesa==25.2.7.2"]
autogen = [
  "pyyaml",
  "mako",
]


[tool.mutmut]
paths_to_mutate = ["tinygrad/"]
do_not_mutate = [
  "tinygrad/codegen/*",
  "tinygrad/engine/*",
  "tinygrad/llm/*",
  "tinygrad/nn/*",
  "tinygrad/renderer/*",
  "tinygrad/runtime/*",
  "tinygrad/schedule/*",
  "tinygrad/uop/*",
  "tinygrad/viz/*",
  "tinygrad/device.py",
  "tinygrad/dtype.py",
  "tinygrad/helpers.py",
  "tinygrad/mixin/gradient.py",
  "tinygrad/tensor.py",
]
tests_dir = ["test/test_tiny.py", "test/backend/test_ops.py"]
debug = true


[tool.mypy]
warn_unused_configs = true
files = ["tinygrad", "test/mockgpu"]
ignore_missing_imports = true
check_untyped_defs = true
explicit_package_bases = true
warn_unreachable = true
warn_redundant_casts = true
strict_equality = true
# NOTE: had to comment this out to make mypy pass on both CI and OSX
#warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "extra.*"
follow_imports = "skip"



[tool.pytest.ini_options]
norecursedirs = [
  "extra",
  ".hypothesis",
  ".git",
]
testpaths = ["test"]
filterwarnings = [
  # Ignore SWIG warnings from importlib
  "ignore:builtin type SwigPy.*has no __module__ attribute:DeprecationWarning",
  "ignore:builtin type swigvarlink has no __module__ attribute:DeprecationWarning",
  # Ignore torch.distributed deprecation warning
  "ignore:.*torch.distributed.reduce_op.*is deprecated:FutureWarning",
  # Ignore numpy warnings from transcendental tests (testing edge cases)
  "ignore:invalid value encountered in log2:RuntimeWarning",
  "ignore:overflow encountered in cast:RuntimeWarning",
  "ignore:divide by zero encountered in log2:RuntimeWarning",
  # Ignore multiprocessing fork warning (known pytest-xdist issue)
  "ignore:.*multi-threaded, use of fork.*may lead to deadlocks:DeprecationWarning",
  # Ignore torch tar extraction warning
  "ignore:.*Python 3.14 will.*filter extracted tar archives:DeprecationWarning",
  # Ignore audio library warnings (Python 3.13 removed aifc and sunau)
  "ignore:aifc was removed in Python 3.13.*:DeprecationWarning",
  "ignore:sunau was removed in Python 3.13.*:DeprecationWarning",
]

[tool.ruff]
preview = true
target-version = "py311"
line-length = 150
indent-width = 2
exclude = [
  ".git/",
  "docs/",
  "extra/",
  "test/external/mlperf_resnet",
  "test/external/mlperf_unet3d",
]

[tool.ruff.lint]
select = [
  "F",  # Pyflakes
  "W6",
  "E71",
  "E72",
  "E112",   # no-indented-block
  "E113",   # unexpected-indentation
  "E203",   # whitespace-before-punctuation
  "E272",   # multiple-spaces-before-keyword
  "E275",   # missing-whitespace-after-keyword
  "E303",   # too-many-blank-lines
  "E304",   # blank-line-after-decorator
  "E501",   # line-too-long
  # "E502",
  "E702",   # multiple-statements-on-one-line-semicolon
  "E703",   # useless-semicolon
  "E731",   # lambda-assignment
  "W191",   # tab-indentation
  "W291",   # trailing-whitespace
  "W293",   # blank-line-with-whitespace
  "UP039",  # unnecessary-class-parentheses
  "C416",   # unnecessary-comprehension
  "RET506", # superfluous-else-raise
  "RET507", # superfluous-else-continue
  "A",      # builtin-variable-shadowing, builtin-argument-shadowing, builtin-attribute-shadowing
  "FURB110",# if-exp-instead-of-or-operator
  "RUF018", # assignment-in-assert
]

# detect unused imports in examples
[tool.ruff.lint.per-file-ignores]
"examples/**/*.py" = [
  "W6",
  "E71",
  "E72",
  "E112",
  "E113",
  "E203",
  "E272",
  "E275",
  "E303",
  "E304",
  "E501",
  "E702",
  "E703",
  "E731",
  "W191",
  "W291",
  "W293",
  "UP039",
  "C416",
  "RET506",
  "RET507",
  "A",
  "FURB110",
  "RUF018",
  "F541",
  "F841",
]
"tinygrad/runtime/autogen/**/*.py" = ["E501", "F401", "E731", "F821", "A006", "A002", "F811", "F822"]
"test/amd/**/*.py" = ["F403", "F405"]

[tool.ruff.format]
exclude = ["*"]
