Skip to content

Commit da186a0

Browse files
committed
Migrate to uv
1 parent e67e748 commit da186a0

9 files changed

Lines changed: 2072 additions & 112 deletions

File tree

.github/workflows/test.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,25 @@ jobs:
5353

5454
steps:
5555
- uses: actions/checkout@v2
56-
- name: Set up Python ${{ matrix.python-version }}
57-
uses: actions/setup-python@v2
58-
with:
59-
python-version: ${{ matrix.python-version }}
56+
- name: Install uv and set the python version
57+
uses: astral-sh/setup-uv@v6
58+
with:
59+
python-version: ${{ matrix.python-version }}
6060
- name: Install dependencies
6161
run: |
62-
python -m pip install --upgrade uv
63-
uv pip install --system pytest pytest-cov
64-
uv pip install --system torch==${{ matrix.pytorch-version }} torchvision transformers
62+
uv add torch==${{ matrix.pytorch-version }}
63+
uv sync
6564
- name: mypy
66-
if: ${{ matrix.pytorch-version == '2.2' }}
65+
if: ${{ matrix.python-version >= 3.11 && matrix.pytorch-version == '2.2' }}
6766
run: |
68-
uv pip install --system mypy==1.9.0
69-
mypy --install-types --non-interactive .
67+
uv run mypy --install-types --non-interactive .
7068
- name: pytest
7169
if: ${{ matrix.pytorch-version == '2.2' }}
7270
run: |
73-
pytest --cov=torchinfo --cov-report= --durations=0
71+
uv run pytest --cov=torchinfo --cov-report= --durations=0
7472
- name: pytest
7573
if: ${{ matrix.pytorch-version != '2.2' }}
7674
run: |
77-
pytest --no-output -k "not test_eval_order_doesnt_matter and not test_google and not test_uninitialized_tensor and not test_input_size_half_precision and not test_recursive_with_missing_layers and not test_flan_t5_small"
75+
uv run pytest --no-output -k "not test_eval_order_doesnt_matter and not test_google and not test_uninitialized_tensor and not test_input_size_half_precision and not test_recursive_with_missing_layers and not test_flan_t5_small"
7876
- name: codecov
7977
uses: codecov/codecov-action@v1

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ ci:
22
skip: [mypy, pytest]
33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
5-
rev: v0.9.10
5+
rev: v0.12.8
66
hooks:
7-
- id: ruff
7+
- id: ruff-check
88
args: [--fix]
99
- id: ruff-format
1010

1111
- repo: local
1212
hooks:
1313
- id: mypy
1414
name: mypy
15-
entry: mypy
15+
entry: uv run mypy
1616
language: python
1717
types: [python]
1818
require_serial: true
1919

2020
- id: pytest
2121
name: pytest
22-
entry: pytest --cov=torchinfo --cov-report=html --durations=0
22+
entry: uv run pytest --cov=torchinfo --cov-report=html --durations=0
2323
language: python
2424
types: [python]
2525
always_run: true

pyproject.toml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
[project]
2+
name = "torchinfo"
3+
description = "Model summary in PyTorch, based off of the original torchsummary."
4+
authors = [
5+
{ name = "Tyler Yep @tyleryep", email = "tyep@cs.stanford.edu" },
6+
]
7+
readme = "README.md"
8+
classifiers = [
9+
"Operating System :: OS Independent",
10+
"Programming Language :: Python :: 3",
11+
"Programming Language :: Python :: 3.6",
12+
"Programming Language :: Python :: 3.7",
13+
"Programming Language :: Python :: 3.8",
14+
"Programming Language :: Python :: 3.9",
15+
"Programming Language :: Python :: 3.10",
16+
"Programming Language :: Python :: 3.11",
17+
"Programming Language :: Python :: 3.12",
18+
]
19+
keywords = [
20+
"torch pytorch torchsummary torch-summary summary keras deep-learning ml torchinfo torch-info visualize model statistics layer stats",
21+
]
22+
dynamic = [
23+
"version",
24+
]
25+
requires-python = ">=3.8"
26+
dependencies = [
27+
"torch",
28+
"torchvision",
29+
"numpy",
30+
]
31+
32+
[dependency-groups]
33+
dev = [
34+
"codecov",
35+
"mypy",
36+
"pre-commit",
37+
"pytest",
38+
"pytest-cov",
39+
"ruff",
40+
"transformers",
41+
"types-setuptools",
42+
"types-tqdm",
43+
]
44+
45+
[project.urls]
46+
Homepage = "https://github.com/tyleryep/torchinfo"
47+
48+
[build-system]
49+
requires = [
50+
"setuptools>=61.2",
51+
]
52+
build-backend = "setuptools.build_meta"
53+
54+
[tool.setuptools]
55+
packages = [
56+
"torchinfo",
57+
]
58+
include-package-data = true
59+
60+
[tool.setuptools.package-data]
61+
torchinfo = [
62+
"py.typed",
63+
]
64+
65+
[tool.setuptools.dynamic.version]
66+
attr = "torchinfo.__version__"
67+
68+
[tool.mypy]
69+
strict = true
70+
warn_unreachable = true
71+
disallow_any_unimported = true
72+
extra_checks = true
73+
enable_error_code = "ignore-without-code"
74+
75+
[tool.ruff]
76+
target-version = "py38"
77+
lint.select = ["ALL"]
78+
lint.ignore = [
79+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
80+
"C901", # function is too complex (12 > 10)
81+
"COM812", # Trailing comma missing
82+
"D", # Docstring rules
83+
"EM101", # Exception must not use a string literal, assign to variable first
84+
"EM102", # Exception must not use an f-string literal, assign to variable first
85+
"ERA001", # Found commented-out code
86+
"FBT001", # Boolean positional arg in function definition
87+
"FBT002", # Boolean default value in function definition
88+
"FBT003", # Boolean positional value in function call
89+
"FIX002", # Line contains TODO
90+
"PLR0911", # Too many return statements (11 > 6)
91+
"PLR2004", # Magic value used in comparison, consider replacing 2 with a constant variable
92+
"PLR0912", # Too many branches
93+
"PLR0913", # Too many arguments to function call
94+
"PLR0915", # Too many statements
95+
"S101", # Use of `assert` detected
96+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
97+
"T201", # print() found
98+
"T203", # pprint() found
99+
"TD002", # Missing author in TODO; try: `# TODO(<author_name>): ...`
100+
"TD003", # Missing issue link on the line following this TODO
101+
"TD005", # Missing issue description after `TODO`
102+
"TRY003", # Avoid specifying long messages outside the exception class
103+
104+
# torchinfo-specific ignores
105+
"N803", # Argument name `A_i` should be lowercase
106+
"N806", # Variable `G` in function should be lowercase
107+
"BLE001", # Do not catch blind exception: `Exception`
108+
"PLW0602", # Using global for `_cached_forward_pass` but no assignment is done
109+
"PLW0603", # Using the global statement to update `_cached_forward_pass` is discouraged
110+
"PLW2901", # `for` loop variable `name` overwritten by assignment target
111+
"RUF005", # Consider unpack instead of concatenation
112+
"SIM108", # [*] Use ternary operator `model_mode = Mode.EVAL if mode is None else Mode(mode)` instead of `if`-`else`-block
113+
"SLF001", # Private member accessed: `_modules`
114+
"TC002", # Move third-party import into a type-checking block
115+
"TRY004", # Prefer `TypeError` exception for invalid type
116+
"TRY301", # Abstract `raise` to an inner function
117+
]
118+
exclude = ["tests"] # TODO: check tests too

requirements-dev.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

ruff.toml

Lines changed: 0 additions & 46 deletions
This file was deleted.

setup.cfg

Lines changed: 0 additions & 39 deletions
This file was deleted.

torchinfo/torchinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def get_total_memory_used(data: CORRECTED_INPUT_DATA_TYPE) -> int:
514514
else sum
515515
),
516516
)
517-
return cast(int, result)
517+
return cast("int", result)
518518

519519

520520
def get_input_tensor(

0 commit comments

Comments
 (0)