Skip to content

[ty] Add support for Debian/Ubuntu dist-packages directories#22466

Merged
carljm merged 1 commit intomainfrom
claude/fix-issue-1323-XMlQh
Jan 31, 2026
Merged

[ty] Add support for Debian/Ubuntu dist-packages directories#22466
carljm merged 1 commit intomainfrom
claude/fix-issue-1323-XMlQh

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Jan 8, 2026

This change adds support for discovering dist-packages directories alongside site-packages directories. On Debian/Ubuntu systems, system-installed Python packages are placed in dist-packages rather than site-packages.

The implementation adds:

  • A relative_dist_packages_path method mirroring relative_site_packages_path
  • Checks for version-specific dist-packages (e.g., /usr/lib/python3.12/dist-packages)
  • Support for Debian's version-agnostic /usr/lib/python3/dist-packages path
  • Updated fallback enumeration to discover dist-packages when iterating directories

This PR is mostly Claude, but I checked the paths used in the PR on a real Debian system and everything seems to line up; several users also report that this PR fixes their use case.

Closes astral-sh/ty#1323

@carljm carljm added the ty Multi-file analysis & type inference label Jan 8, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 8, 2026

Typing conformance results

No changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 8, 2026

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 47 diagnostics
+ Found 46 diagnostics

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/decoding/tools.py:96:44: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- rotkehlchen/chain/decoding/tools.py:97:13: error[invalid-argument-type] Argument to function `decode_transfer_direction` is incorrect: Expected `BTCAddress | ChecksumAddress | SubstrateAddress | SolanaAddress`, found `A@BaseDecoderTools`
+ rotkehlchen/chain/decoding/tools.py:99:13: error[invalid-argument-type] Argument to function `decode_transfer_direction` is incorrect: Expected `Sequence[A@BaseDecoderTools]`, found `Unknown | tuple[BTCAddress, ...] | tuple[ChecksumAddress, ...] | tuple[SubstrateAddress, ...] | tuple[SolanaAddress, ...]`
- rotkehlchen/chain/decoding/tools.py:98:13: error[invalid-argument-type] Argument to function `decode_transfer_direction` is incorrect: Expected `BTCAddress | ChecksumAddress | SubstrateAddress | SolanaAddress | None`, found `A@BaseDecoderTools | None`
+ rotkehlchen/chain/decoding/tools.py:100:62: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- Found 2053 diagnostics
+ Found 2054 diagnostics

core (https://github.com/home-assistant/core)
+ homeassistant/util/variance.py:47:12: error[invalid-return-type] Return type does not match returned value: expected `(**_P@ignore_variance) -> _R@ignore_variance`, found `_Wrapped[_P@ignore_variance, int | _R@ignore_variance | float | datetime, _P@ignore_variance, _R@ignore_variance | int | float | datetime]`
- Found 14514 diagnostics
+ Found 14515 diagnostics

No memory usage changes detected ✅

@carljm
Copy link
Contributor Author

carljm commented Jan 8, 2026

This is a Claude PR, which I haven't had time to validate yet (thus it's still in draft). I'm putting it up as a starting point for contribution by anyone motivated to help get this issue fixed faster. Contributions needed:

  • Validate (on a real Debian/Ubuntu system) that this change does allow Debian-installed Python packages to be discovered.
  • Validate (on a real Debian/Ubuntu system) that the assertions made in the PR about Debian's behavior (e.g. the existence of the minor-version-agnostic python3 directory, the dist-packages layout for Debian-bundled PyPy) are accurate.
  • Code review.

@Hyask
Copy link

Hyask commented Jan 9, 2026

Tested that on my Ubuntu Resolute machine.

Versions (ty is the local build with the patch):

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11 took 29s
❯ /snap/bin/astral-ty.ty --version
ty 0.0.1-alpha.30 (d5754d3b5 2025-12-03)

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❯ ty --version
ty 0.0.10

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❯ which ty
/home/skia/.local/bin/ty

Showing all the broken cases before the final one that works (as expected):

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❯ cat test-dist-package.py
from apport import Report

report = Report()
report["Hello"] = "There"
print(report)

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❯ /snap/bin/astral-ty.ty check test-dist-package.py
error[unresolved-import]: Cannot resolve imported module `apport`
 --> test-dist-package.py:1:6
  |
1 | from apport import Report
  |      ^^^^^^
2 |
3 | report = Report()
  |
info: Searched in the following paths during module resolution:
info:   1. /home/skia/workspace/skia/ty/python (first-party code)
info:   2. /home/skia/workspace/skia/ty (first-party code)
info:   3. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info:   4. /snap/astral-ty/562/lib/python3.12/site-packages (site-packages)
info:   5. /snap/astral-ty/562/lib64/python3.12/site-packages (site-packages)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
info: rule `unresolved-import` is enabled by default

Found 1 diagnostic

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❌1 ❯ /snap/bin/astral-ty.ty check --python /usr/bin/python3 test-dist-package.py
ty failed
  Cause: Failed to discover the site-packages directory
  Cause: Invalid `--python` argument `/usr`: Could not find a `site-packages` directory for this Python installation/executable

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❌2 ❯ ty check test-dist-package.py
error[unresolved-import]: Cannot resolve imported module `apport`
 --> test-dist-package.py:1:6
  |
1 | from apport import Report
  |      ^^^^^^
2 |
3 | report = Report()
  |
info: Searched in the following paths during module resolution:
info:   1. /home/skia/workspace/skia/ty/python (first-party code)
info:   2. /home/skia/workspace/skia/ty (first-party code)
info:   3. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
info: rule `unresolved-import` is enabled by default

Found 1 diagnostic

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❌1 ❯ ty check --python /usr/bin/python3 test-dist-package.py
All checks passed!

It seems to work fine.

Also working fine as an LSP plugged to helix with the following configuration:

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11 took 4s
❯ cat ~/.config/ty/ty.toml
[environment]
python = "/usr/bin/python3"

Obviously the above configuration makes the check to pass without extra CLI arguments:

skia@kiffex:workspace/skia/ty on  skia/test_dist_package [?] is 📦 v0.0.10 via 🐍 v3.13.11
❯ ty check test-dist-package.py
All checks passed!

Thanks for that work! 💚

@sillydan1
Copy link

Just tried this patch - seems to solve my issue described in astral-sh/ty#2412 as well 😄 🥳

@carljm carljm force-pushed the claude/fix-issue-1323-XMlQh branch from b85fe60 to ea6393e Compare January 29, 2026 23:21
@carljm
Copy link
Contributor Author

carljm commented Jan 29, 2026

I fired up a Debian VM and double-checked this PR against the paths I found there; it all looks good to me.

@carljm
Copy link
Contributor Author

carljm commented Jan 29, 2026

Thanks @Hyask and @sillydan1 for confirmation that this fixes your use cases!

This change adds support for discovering `dist-packages` directories
alongside `site-packages` directories. On Debian/Ubuntu systems,
system-installed Python packages are placed in `dist-packages` rather
than `site-packages`.

The implementation adds:
- A `relative_dist_packages_path` method mirroring `relative_site_packages_path`
- Checks for version-specific dist-packages (e.g., `/usr/lib/python3.12/dist-packages`)
- Support for Debian's version-agnostic `/usr/lib/python3/dist-packages` path
- Updated fallback enumeration to discover dist-packages when iterating directories

Closes astral-sh/ty#1323
@carljm carljm force-pushed the claude/fix-issue-1323-XMlQh branch from ea6393e to bdd9cad Compare January 29, 2026 23:54
@carljm carljm marked this pull request as ready for review January 29, 2026 23:55
@Hyask
Copy link

Hyask commented Jan 30, 2026

Additionally: I've been daily-driving this patch for the last 3 weeks, in many different codebases. So far so good. I can't say that I've hit every corner cases, but at least the test coverage has definitely expanded!

@carljm carljm requested a review from charliermarsh January 30, 2026 20:38
@carljm carljm merged commit 8d4d782 into main Jan 31, 2026
49 checks passed
@carljm carljm deleted the claude/fix-issue-1323-XMlQh branch January 31, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support finding packages installed into Debian dist-packages directories

4 participants