Skip to content

Commit ff60056

Browse files
committed
Replace mypy with ty
1 parent b459afe commit ff60056

9 files changed

Lines changed: 3484 additions & 24 deletions

File tree

.github/workflows/tests.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ on:
55
branches:
66
- main
77
paths:
8+
- ".pre-commit-config.yaml"
89
- ".github/workflows/tests.yml"
910
- "conda_self/**"
1011
- "pixi.lock"
1112
- "pyproject.toml"
1213
- "recipe/**"
1314
- "tests/**"
1415
pull_request:
15-
branches:
16-
- main
1716
paths:
17+
- ".pre-commit-config.yaml"
1818
- ".github/workflows/tests.yml"
1919
- "conda_self/**"
2020
- "pixi.lock"
@@ -32,6 +32,16 @@ concurrency:
3232
cancel-in-progress: true
3333

3434
jobs:
35+
typecheck:
36+
name: Type check
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
40+
- uses: prefix-dev/setup-pixi@f00437f565399d418b0acc85936d12c1fb668347 # v0.10.1
41+
with:
42+
environments: typecheck
43+
- run: pixi run --environment typecheck typecheck
44+
3545
tests:
3646
name: ${{ matrix.os }}, py${{ matrix.python-version }}, ${{ matrix.channel }}
3747
runs-on: ${{ matrix.os }}

.pre-commit-config.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# disable autofixing PRs, commenting "pre-commit.ci autofix" on a pull request triggers a autofix
22
ci:
33
autofix_prs: false
4+
# GitHub Actions runs ty because pre-commit.ci does not provide Pixi.
5+
skip: [ty]
46
# generally speaking we ignore all vendored code as well as tests data
57
# TODO: Restore index and solver exclude lines before merge
68
exclude: |
@@ -41,11 +43,6 @@ repos:
4143
args: [--fix]
4244
# compatible replacement for black
4345
- id: ruff-format
44-
- repo: https://github.com/pre-commit/mirrors-mypy
45-
rev: 'v2.3.1' # Use the sha / tag you want to point at
46-
hooks:
47-
- id: mypy
48-
exclude: ^docs/.*$
4946
- repo: https://github.com/python-jsonschema/check-jsonschema
5047
rev: 0.38.0
5148
hooks:
@@ -57,6 +54,12 @@ repos:
5754
- id: check-useless-excludes
5855
- repo: local
5956
hooks:
57+
- id: ty
58+
name: ty
59+
entry: pixi run --environment typecheck typecheck
60+
language: system
61+
pass_filenames: false
62+
always_run: true
6063
- id: git-diff
6164
name: git diff
6265
entry: git diff --exit-code

conda_self/health_checks/base_protection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def fix(prefix: str, args: Namespace, confirm: ConfirmCallback) -> int:
137137
)
138138
if not context.quiet:
139139
print(f"Saving snapshot to {snapshot_file}")
140-
snapshot_file.write_text(explicit_exporter.export(env))
140+
export = explicit_exporter.export
141+
assert export is not None
142+
snapshot_file.write_text(export(env))
141143
except CondaValueError:
142144
if not context.quiet:
143145
print(

conda_self/package_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# This is required for reading entry point info from an extracted package
1919
# ref: https://packaging.python.org/en/latest/specifications/entry-points/#file-format
2020
class CaseSensitiveConfigParser(configparser.ConfigParser):
21-
optionxform = staticmethod(str) # type: ignore
21+
optionxform = staticmethod(str)
2222

2323

2424
class PackageInfo:

conda_self/query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from conda.core.prefix_data import PrefixData
1010
from conda.models.prefix_graph import PrefixGraph
1111

12-
from .constants import PERMANENT_PACKAGES
12+
from .constants import PERMANENT_PACKAGES, SELF_PERMANENT_PACKAGES_SETTING
1313
from .exceptions import NoDistInfoDirFound
1414
from .package_info import PackageInfo
1515

@@ -22,7 +22,10 @@ def permanent_dependencies(add_plugins: bool = False) -> set[str]:
2222
installed = list(PrefixData(sys.prefix, interoperability=True).iter_records())
2323
prefix_graph = PrefixGraph(installed)
2424

25-
protect = [*PERMANENT_PACKAGES, *context.plugins.self_permanent_packages]
25+
protect = [
26+
*PERMANENT_PACKAGES,
27+
*getattr(context.plugins, SELF_PERMANENT_PACKAGES_SETTING),
28+
]
2629

2730
if add_plugins:
2831
for record in installed:

conda_self/reset.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from os.path import dirname, isfile
66
from typing import TYPE_CHECKING
77

8-
from boltons.setutils import IndexedSet
98
from conda import CondaError, CondaExitZero, CondaMultiError
109
from conda.base.constants import EXPLICIT_MARKER
1110
from conda.base.context import context
@@ -30,7 +29,7 @@
3029

3130
def records_from_snapshot(
3231
prefix: str, snapshot_content: list[str]
33-
) -> tuple[IndexedSet, tuple[MatchSpec, ...]]:
32+
) -> tuple[tuple[PackageRecord, ...], tuple[MatchSpec, ...]]:
3433
"""Return package records for the snapshot and MatchSpecs to install or relink."""
3534
entries = tuple(line for line in snapshot_content if line != EXPLICIT_MARKER)
3635
try:
@@ -140,9 +139,9 @@ def records_from_snapshot(
140139
for index, record in zip(unresolved_indices, fetched_records, strict=True):
141140
records[index] = record
142141

143-
return IndexedSet(record for record in records if record is not None), tuple(
144-
unresolved_specs
145-
)
142+
return tuple(
143+
dict.fromkeys(record for record in records if record is not None)
144+
), tuple(unresolved_specs)
146145

147146

148147
def names_from_explicit(path: Path) -> set[str]:

0 commit comments

Comments
 (0)