typedframes 0.14.0__tar.gz → 0.14.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. {typedframes-0.14.0 → typedframes-0.14.1}/PKG-INFO +12 -5
  2. {typedframes-0.14.0 → typedframes-0.14.1}/README.md +11 -4
  3. {typedframes-0.14.0 → typedframes-0.14.1}/pyproject.toml +3 -1
  4. {typedframes-0.14.0 → typedframes-0.14.1}/rust/Cargo.lock +79 -1
  5. {typedframes-0.14.0 → typedframes-0.14.1}/rust/Cargo.toml +5 -3
  6. typedframes-0.14.1/rust/python/Cargo.toml +23 -0
  7. typedframes-0.14.1/rust/python/build.rs +4 -0
  8. typedframes-0.14.1/rust/python/src/lib.rs +27 -0
  9. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/args.rs +10 -3
  10. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/check.rs +25 -10
  11. typedframes-0.14.1/rust/src/cli/mod.rs +178 -0
  12. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/report.rs +34 -0
  13. {typedframes-0.14.0 → typedframes-0.14.1}/rust/tests/cli.rs +20 -0
  14. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/__init__.py +1 -1
  15. typedframes-0.14.1/src/typedframes/_binary.py +115 -0
  16. typedframes-0.14.1/src/typedframes/_rust.pyi +2 -0
  17. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/mypy.py +1 -1
  18. typedframes-0.14.0/rust/src/cli/mod.rs +0 -62
  19. typedframes-0.14.0/src/typedframes/_binary.py +0 -57
  20. {typedframes-0.14.0 → typedframes-0.14.1}/.cargo/config.toml +0 -0
  21. {typedframes-0.14.0 → typedframes-0.14.1}/LICENSE +0 -0
  22. {typedframes-0.14.0 → typedframes-0.14.1}/rust/README.md +0 -0
  23. {typedframes-0.14.0 → typedframes-0.14.1}/rust/benches/parser_bench.rs +0 -0
  24. {typedframes-0.14.0 → typedframes-0.14.1}/rust/build.rs +0 -0
  25. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/apply.rs +0 -0
  26. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/ast_extract.rs +0 -0
  27. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/call_usage.rs +0 -0
  28. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/cache.rs +0 -0
  29. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/collect.rs +0 -0
  30. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/config.rs +0 -0
  31. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/coverage.rs +0 -0
  32. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/pathutil.rs +0 -0
  33. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/pyfmt.rs +0 -0
  34. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/style.rs +0 -0
  35. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/cli/suggest.rs +0 -0
  36. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/column_consuming_methods.rs +0 -0
  37. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/column_usage.rs +0 -0
  38. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/config.rs +0 -0
  39. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/constants.rs +0 -0
  40. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/contract.rs +0 -0
  41. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/engine.rs +0 -0
  42. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/errors.rs +0 -0
  43. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/fast_hash.rs +0 -0
  44. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/frame_ops.rs +0 -0
  45. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/helpers.rs +0 -0
  46. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/index.rs +0 -0
  47. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/lib.rs +0 -0
  48. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/library_names.txt +0 -0
  49. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/linter.rs +0 -0
  50. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/main.rs +0 -0
  51. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/notebook.rs +0 -0
  52. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/parallel.rs +0 -0
  53. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/phrase.rs +0 -0
  54. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/report.rs +0 -0
  55. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/report_minimize.rs +0 -0
  56. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/report_names.rs +0 -0
  57. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/sql.rs +0 -0
  58. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/static_eval.rs +0 -0
  59. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/suggest.rs +0 -0
  60. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/typo.rs +0 -0
  61. {typedframes-0.14.0 → typedframes-0.14.1}/rust/src/words.txt +0 -0
  62. {typedframes-0.14.0 → typedframes-0.14.1}/rust/tests/integration_test.rs +0 -0
  63. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/__main__.py +0 -0
  64. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/base_schema.py +0 -0
  65. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/column.py +0 -0
  66. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/column_group.py +0 -0
  67. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/column_group_error.py +0 -0
  68. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/column_set.py +0 -0
  69. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/missing_dependency_error.py +0 -0
  70. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/pandera.py +0 -0
  71. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/py.typed +0 -0
  72. {typedframes-0.14.0 → typedframes-0.14.1}/src/typedframes/schema_algebra.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: typedframes
3
- Version: 0.14.0
3
+ Version: 0.14.1
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -44,7 +44,7 @@ Project-URL: Repository, https://github.com/w-martin/typedframes
44
44
 
45
45
  > ⚠️ **Project Status: Proof of Concept**
46
46
  >
47
- > `typedframes` (v0.14.0) is currently an experimental proof-of-concept. The core static analysis and mypy/Rust
47
+ > `typedframes` (v0.14.1) is currently an experimental proof-of-concept. The core static analysis and mypy/Rust
48
48
  > integrations work, but expect rough edges. The codebase prioritizes demonstrating the viability of static DataFrame
49
49
  > column checking over production-grade stability.
50
50
  >
@@ -140,6 +140,13 @@ pip install typedframes[pandas] # includes pandas
140
140
  pip install typedframes[polars] # includes polars
141
141
  ```
142
142
 
143
+ Where the Python interpreter may run code but no other executable may be started, set `TYPEDFRAMES_INPROC=1`. Then
144
+ `python -m typedframes` and the mypy plugin run the same checker inside the interpreter, through an extension module in
145
+ the wheel, instead of starting the `typedframes` executable. Results and exit status are the same; when the checker is
146
+ asked to capture its output (as the mypy plugin does), a usage error or a missing path comes back with it, and any
147
+ warning a command prints still goes to the terminal. Without the extension installed (for example from a source
148
+ distribution) `TYPEDFRAMES_INPROC=1` is an error.
149
+
143
150
  ---
144
151
 
145
152
  ## Quick Start
@@ -507,7 +514,7 @@ repos:
507
514
  name: typedframes check
508
515
  entry: typedframes check . --strict
509
516
  language: python
510
- additional_dependencies: ["typedframes==0.14.0"]
517
+ additional_dependencies: ["typedframes==0.14.1"]
511
518
  types_or: [python, jupyter]
512
519
  pass_filenames: false
513
520
  ```
@@ -556,7 +563,7 @@ The action installs the PyPI wheel into a throwaway virtualenv and runs the chec
556
563
  | Input | Default | |
557
564
  |-------|---------|-|
558
565
  | `path` | `.` | File or directory to check |
559
- | `version` | `latest` | PyPI version to install, e.g. `"0.14.0"` |
566
+ | `version` | `latest` | PyPI version to install, e.g. `"0.14.1"` |
560
567
  | `strict` | `true` | Fail the step on errors — `typedframes check` exits 0 without it |
561
568
  | `coverage-fail-under` | *(unset)* | Minimum DataFrame schema coverage, e.g. `"90"` |
562
569
  | `coverage-detail` | `summary` | Or `term-missing` for the per-file breakdown, `explain` to diagnose a lower-than-expected total |
@@ -584,7 +591,7 @@ and the files are written together or not at all. See the
584
591
 
585
592
  If `check` or `suggest` gets a site wrong and the code can't be shared, `typedframes report quiet-amber src/` prints a
586
593
  bug-report body with a redacted copy of the code around that site, checked against the checker so it reproduces the same
587
- result. `typedframes report --all src/` does this for every untyped site, grouped by why the checker decided as it did.
594
+ result. `typedframes report --all src/` does this for every untyped site, grouped by why the checker decided as it did; add `--format compact` for a few lines per group that fit in one screenshot.
588
595
  Redacted is not anonymous: read it before posting, and don't use it on code you aren't allowed to share. See
589
596
  [Reporting a problem](docs/usage.md#reporting-a-problem-report), and
590
597
  [Security and data handling](docs/security.md) for what the tool reads, writes and connects to.
@@ -8,7 +8,7 @@
8
8
 
9
9
  > ⚠️ **Project Status: Proof of Concept**
10
10
  >
11
- > `typedframes` (v0.14.0) is currently an experimental proof-of-concept. The core static analysis and mypy/Rust
11
+ > `typedframes` (v0.14.1) is currently an experimental proof-of-concept. The core static analysis and mypy/Rust
12
12
  > integrations work, but expect rough edges. The codebase prioritizes demonstrating the viability of static DataFrame
13
13
  > column checking over production-grade stability.
14
14
  >
@@ -104,6 +104,13 @@ pip install typedframes[pandas] # includes pandas
104
104
  pip install typedframes[polars] # includes polars
105
105
  ```
106
106
 
107
+ Where the Python interpreter may run code but no other executable may be started, set `TYPEDFRAMES_INPROC=1`. Then
108
+ `python -m typedframes` and the mypy plugin run the same checker inside the interpreter, through an extension module in
109
+ the wheel, instead of starting the `typedframes` executable. Results and exit status are the same; when the checker is
110
+ asked to capture its output (as the mypy plugin does), a usage error or a missing path comes back with it, and any
111
+ warning a command prints still goes to the terminal. Without the extension installed (for example from a source
112
+ distribution) `TYPEDFRAMES_INPROC=1` is an error.
113
+
107
114
  ---
108
115
 
109
116
  ## Quick Start
@@ -471,7 +478,7 @@ repos:
471
478
  name: typedframes check
472
479
  entry: typedframes check . --strict
473
480
  language: python
474
- additional_dependencies: ["typedframes==0.14.0"]
481
+ additional_dependencies: ["typedframes==0.14.1"]
475
482
  types_or: [python, jupyter]
476
483
  pass_filenames: false
477
484
  ```
@@ -520,7 +527,7 @@ The action installs the PyPI wheel into a throwaway virtualenv and runs the chec
520
527
  | Input | Default | |
521
528
  |-------|---------|-|
522
529
  | `path` | `.` | File or directory to check |
523
- | `version` | `latest` | PyPI version to install, e.g. `"0.14.0"` |
530
+ | `version` | `latest` | PyPI version to install, e.g. `"0.14.1"` |
524
531
  | `strict` | `true` | Fail the step on errors — `typedframes check` exits 0 without it |
525
532
  | `coverage-fail-under` | *(unset)* | Minimum DataFrame schema coverage, e.g. `"90"` |
526
533
  | `coverage-detail` | `summary` | Or `term-missing` for the per-file breakdown, `explain` to diagnose a lower-than-expected total |
@@ -548,7 +555,7 @@ and the files are written together or not at all. See the
548
555
 
549
556
  If `check` or `suggest` gets a site wrong and the code can't be shared, `typedframes report quiet-amber src/` prints a
550
557
  bug-report body with a redacted copy of the code around that site, checked against the checker so it reproduces the same
551
- result. `typedframes report --all src/` does this for every untyped site, grouped by why the checker decided as it did.
558
+ result. `typedframes report --all src/` does this for every untyped site, grouped by why the checker decided as it did; add `--format compact` for a few lines per group that fit in one screenshot.
552
559
  Redacted is not anonymous: read it before posting, and don't use it on code you aren't allowed to share. See
553
560
  [Reporting a problem](docs/usage.md#reporting-a-problem-report), and
554
561
  [Security and data handling](docs/security.md) for what the tool reads, writes and connects to.
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "typedframes"
7
- version = "0.14.0"
7
+ version = "0.14.1"
8
8
  description = "Static analysis for pandas and polars DataFrames. Catch column errors at lint-time, not runtime."
9
9
  keywords = ["pandas", "polars", "type-checking", "static-analysis", "dataframe", "linter", "mypy-plugin"]
10
10
  readme = "README.md"
@@ -49,6 +49,8 @@ bindings = "bin"
49
49
  module-name = "typedframes"
50
50
  # The cargo config carries the allocator tuning, so a build from the sdist is tuned too.
51
51
  include = [
52
+ { path = "src/typedframes/_rust.*", format = "wheel" },
53
+ { path = "rust/python/**/*", format = "sdist" },
52
54
  { path = "LICENSE", format = "sdist" },
53
55
  { path = ".cargo/config.toml", format = "sdist" },
54
56
  ]
@@ -792,6 +792,12 @@ dependencies = [
792
792
  "plotters-backend",
793
793
  ]
794
794
 
795
+ [[package]]
796
+ name = "portable-atomic"
797
+ version = "1.15.0"
798
+ source = "registry+https://github.com/rust-lang/crates.io-index"
799
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
800
+
795
801
  [[package]]
796
802
  name = "ppv-lite86"
797
803
  version = "0.2.21"
@@ -831,6 +837,63 @@ dependencies = [
831
837
  "cc",
832
838
  ]
833
839
 
840
+ [[package]]
841
+ name = "pyo3"
842
+ version = "0.30.1"
843
+ source = "registry+https://github.com/rust-lang/crates.io-index"
844
+ checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
845
+ dependencies = [
846
+ "libc",
847
+ "once_cell",
848
+ "portable-atomic",
849
+ "pyo3-build-config",
850
+ "pyo3-ffi",
851
+ "pyo3-macros",
852
+ ]
853
+
854
+ [[package]]
855
+ name = "pyo3-build-config"
856
+ version = "0.30.1"
857
+ source = "registry+https://github.com/rust-lang/crates.io-index"
858
+ checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
859
+ dependencies = [
860
+ "target-lexicon",
861
+ ]
862
+
863
+ [[package]]
864
+ name = "pyo3-ffi"
865
+ version = "0.30.1"
866
+ source = "registry+https://github.com/rust-lang/crates.io-index"
867
+ checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
868
+ dependencies = [
869
+ "libc",
870
+ "pyo3-build-config",
871
+ ]
872
+
873
+ [[package]]
874
+ name = "pyo3-macros"
875
+ version = "0.30.1"
876
+ source = "registry+https://github.com/rust-lang/crates.io-index"
877
+ checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
878
+ dependencies = [
879
+ "proc-macro2",
880
+ "pyo3-macros-backend",
881
+ "quote",
882
+ "syn 3.0.3",
883
+ ]
884
+
885
+ [[package]]
886
+ name = "pyo3-macros-backend"
887
+ version = "0.30.1"
888
+ source = "registry+https://github.com/rust-lang/crates.io-index"
889
+ checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
890
+ dependencies = [
891
+ "heck",
892
+ "proc-macro2",
893
+ "quote",
894
+ "syn 3.0.3",
895
+ ]
896
+
834
897
  [[package]]
835
898
  name = "quote"
836
899
  version = "1.0.47"
@@ -1275,6 +1338,12 @@ dependencies = [
1275
1338
  "unicode-ident",
1276
1339
  ]
1277
1340
 
1341
+ [[package]]
1342
+ name = "target-lexicon"
1343
+ version = "0.13.5"
1344
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1345
+ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
1346
+
1278
1347
  [[package]]
1279
1348
  name = "tempfile"
1280
1349
  version = "3.27.0"
@@ -1400,7 +1469,7 @@ checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
1400
1469
 
1401
1470
  [[package]]
1402
1471
  name = "typedframes_checker"
1403
- version = "0.14.0"
1472
+ version = "0.14.1"
1404
1473
  dependencies = [
1405
1474
  "anyhow",
1406
1475
  "clap",
@@ -1421,6 +1490,15 @@ dependencies = [
1421
1490
  "toml",
1422
1491
  ]
1423
1492
 
1493
+ [[package]]
1494
+ name = "typedframes_python"
1495
+ version = "0.14.1"
1496
+ dependencies = [
1497
+ "pyo3",
1498
+ "pyo3-build-config",
1499
+ "typedframes_checker",
1500
+ ]
1501
+
1424
1502
  [[package]]
1425
1503
  name = "unicode-ident"
1426
1504
  version = "1.0.24"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "typedframes_checker"
3
- version = "0.14.0"
3
+ version = "0.14.1"
4
4
  edition = "2021"
5
5
  description = "A high-performance Rust-based checker for typedframes DataFrame column schemas"
6
6
  license = "MIT"
@@ -16,7 +16,8 @@ path = "src/main.rs"
16
16
  [profile.release]
17
17
  lto = true
18
18
  codegen-units = 1
19
- panic = "abort"
19
+ # Panics unwind (the default): this profile also builds the extension module, where a panic must become
20
+ # a Python exception and not end the interpreter that loaded it.
20
21
  strip = "symbols"
21
22
 
22
23
  [lints.rust]
@@ -44,7 +45,8 @@ regex = "1.13.1"
44
45
  # has no MSVC support), the platform allocator elsewhere. Keep the `cfg`s in `src/lib.rs` in
45
46
  # step with these. jemalloc is tuned for a short run on many threads in `../.cargo/config.toml`.
46
47
  [target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), not(target_os = "aix"), not(target_os = "android"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64", target_arch = "riscv64")))'.dependencies]
47
- tikv-jemallocator = "0.7"
48
+ # No initial-exec TLS: that model fails to `dlopen` into a process that did not link jemalloc at start (the extension module).
49
+ tikv-jemallocator = { version = "0.7", features = ["disable_initial_exec_tls"] }
48
50
 
49
51
  [target.'cfg(target_os = "windows")'.dependencies]
50
52
  mimalloc = { version = "0.1.52", default-features = false }
@@ -0,0 +1,23 @@
1
+ [package]
2
+ name = "typedframes_python"
3
+ version = "0.14.1"
4
+ edition = "2021"
5
+ description = "The typedframes checker as a Python extension module, for interpreters that may not start new executables"
6
+ license = "MIT"
7
+ repository = "https://github.com/w-martin/typedframes"
8
+
9
+ [lib]
10
+ name = "_rust"
11
+ crate-type = ["cdylib"]
12
+
13
+ [lints.clippy]
14
+ all = { level = "deny", priority = -1 }
15
+ unwrap_used = "warn"
16
+
17
+ [dependencies]
18
+ typedframes_checker = { path = ".." }
19
+ # abi3: one build serves every supported Python, so the wheel stays one per platform.
20
+ pyo3 = { version = "0.30.1", features = ["abi3-py311", "extension-module"] }
21
+
22
+ [build-dependencies]
23
+ pyo3-build-config = "0.30.1"
@@ -0,0 +1,4 @@
1
+ fn main() {
2
+ // Leaves the interpreter's symbols undefined at link time on macOS and Windows, as an extension module must.
3
+ pyo3_build_config::add_extension_module_link_args();
4
+ }
@@ -0,0 +1,27 @@
1
+ //! `typedframes._rust`: the command line, run inside the Python interpreter.
2
+
3
+ use pyo3::prelude::*;
4
+
5
+ /// Run the `typedframes` command line with `argv` (the program name first); returns the exit status.
6
+ #[pyfunction]
7
+ fn main(py: Python<'_>, argv: Vec<String>) -> u8 {
8
+ // The checker uses its own threads and no Python objects, so the interpreter can run meanwhile.
9
+ py.detach(|| typedframes_checker::cli::run(argv))
10
+ }
11
+
12
+ /// Like `main`, but returns the exit status, standard output and the failure message instead of writing them.
13
+ #[pyfunction]
14
+ fn run_captured(py: Python<'_>, argv: Vec<String>) -> (u8, String, String) {
15
+ let (status, out, err) = py.detach(|| typedframes_checker::cli::run_captured(argv));
16
+ (
17
+ status,
18
+ String::from_utf8_lossy(&out).into_owned(),
19
+ String::from_utf8_lossy(&err).into_owned(),
20
+ )
21
+ }
22
+
23
+ #[pymodule]
24
+ fn _rust(module: &Bound<'_, PyModule>) -> PyResult<()> {
25
+ module.add_function(wrap_pyfunction!(main, module)?)?;
26
+ module.add_function(wrap_pyfunction!(run_captured, module)?)
27
+ }
@@ -3,6 +3,7 @@
3
3
  use super::cache::CacheAction;
4
4
  use super::config::CoverageDetail;
5
5
  use clap::{Args, Parser, Subcommand, ValueEnum};
6
+ use std::ffi::OsString;
6
7
  use std::path::PathBuf;
7
8
 
8
9
  const CACHE_HELP: &str = "\
@@ -174,6 +175,7 @@ pub(crate) enum Outcome {
174
175
  pub(crate) enum ReportFormat {
175
176
  Markdown,
176
177
  Json,
178
+ Compact,
177
179
  }
178
180
 
179
181
  #[derive(Args, Debug)]
@@ -215,9 +217,14 @@ pub(crate) struct CacheArgs {
215
217
  pub(crate) cache_dir: Option<PathBuf>,
216
218
  }
217
219
 
218
- /// Parses the process arguments, exiting with clap's usage error (status 2) on a bad command line.
219
- pub(crate) fn parse() -> Cli {
220
- Cli::parse()
220
+ /// Parses `args` (program name first). A bad command line, `--help` and `--version` come back as
221
+ /// the clap error for the caller to print, so nothing here ends the process.
222
+ pub(crate) fn parse_from<I, T>(args: I) -> Result<Cli, clap::Error>
223
+ where
224
+ I: IntoIterator<Item = T>,
225
+ T: Into<OsString> + Clone,
226
+ {
227
+ Cli::try_parse_from(args)
221
228
  }
222
229
 
223
230
  #[cfg(test)]
@@ -451,22 +451,29 @@ pub(crate) fn build_index(
451
451
  }
452
452
  }
453
453
 
454
- /// Resolves a command's path argument; a path that doesn't exist is reported and exit status 2.
455
- pub(crate) fn resolve_existing_path(original: &Path) -> Result<PathBuf, i32> {
454
+ /// Resolves a command's path argument; `Err` is the message for a path that doesn't exist.
455
+ fn resolve_or_explain(original: &Path) -> Result<PathBuf, String> {
456
456
  let path = resolve(original);
457
457
  if path.exists() {
458
458
  return Ok(path);
459
459
  }
460
460
  if original.is_absolute() {
461
- eprintln!("Error: path does not exist: {}", path.display());
461
+ Err(format!("Error: path does not exist: {}", path.display()))
462
462
  } else {
463
- eprintln!(
463
+ Err(format!(
464
464
  "Error: path does not exist: {} (resolved to {})",
465
465
  repr(original),
466
466
  path.display()
467
- );
467
+ ))
468
468
  }
469
- Err(2)
469
+ }
470
+
471
+ /// Resolves a command's path argument; a path that doesn't exist is reported and exit status 2.
472
+ pub(crate) fn resolve_existing_path(original: &Path) -> Result<PathBuf, i32> {
473
+ resolve_or_explain(original).map_err(|message| {
474
+ eprintln!("{message}");
475
+ 2
476
+ })
470
477
  }
471
478
 
472
479
  fn print_coverage_failures(
@@ -495,12 +502,20 @@ fn print_coverage_failures(
495
502
  Ok(())
496
503
  }
497
504
 
498
- /// Runs `check`, writing its report to `out`; returns the exit status.
499
- pub(crate) fn run_check(args: &CheckArgs, out: &mut impl Write) -> io::Result<i32> {
505
+ /// Runs `check`, writing its report to `out` and the reason for a path that doesn't exist to `err`;
506
+ /// returns the exit status.
507
+ pub(crate) fn run_check(
508
+ args: &CheckArgs,
509
+ out: &mut impl Write,
510
+ err: &mut impl Write,
511
+ ) -> io::Result<i32> {
500
512
  let start = Instant::now();
501
- let path = match resolve_existing_path(&args.path) {
513
+ let path = match resolve_or_explain(&args.path) {
502
514
  Ok(path) => path,
503
- Err(code) => return Ok(code),
515
+ Err(message) => {
516
+ writeln!(err, "{message}")?;
517
+ return Ok(2);
518
+ }
504
519
  };
505
520
 
506
521
  // Loaded before the run so an unusable config is reported up front rather than after a long
@@ -0,0 +1,178 @@
1
+ //! The `typedframes` command line.
2
+
3
+ mod args;
4
+ mod cache;
5
+ mod check;
6
+ mod collect;
7
+ mod config;
8
+ mod coverage;
9
+ mod pathutil;
10
+ mod pyfmt;
11
+ mod report;
12
+ mod style;
13
+ mod suggest;
14
+
15
+ use args::Command;
16
+ use clap::CommandFactory;
17
+ use std::ffi::OsString;
18
+ use std::io::{self, BufWriter, IsTerminal, LineWriter, Write};
19
+ use std::process::ExitCode;
20
+
21
+ fn run_command(command: Command, out: &mut impl Write, err: &mut impl Write) -> io::Result<i32> {
22
+ match command {
23
+ Command::Check(args) => check::run_check(&args, out, err),
24
+ Command::Cache(args) => {
25
+ cache::run_cache(args.action, &args.path, args.cache_dir.as_deref(), out)?;
26
+ Ok(0)
27
+ }
28
+ Command::Suggest(args) => suggest::run_suggest(&args, out, &mut io::stdin().lock()),
29
+ Command::Report(args) => report::run_report(&args, out),
30
+ }
31
+ }
32
+
33
+ /// Parses `args` (program name first). A bad command line, `--help` and `--version` come back as
34
+ /// the clap error, with the status it asks for.
35
+ fn parse(
36
+ args: impl IntoIterator<Item = impl Into<OsString> + Clone>,
37
+ ) -> Result<args::Cli, (clap::Error, u8)> {
38
+ args::parse_from(args).map_err(|error| {
39
+ let status = u8::try_from(error.exit_code()).unwrap_or(2);
40
+ (error, status)
41
+ })
42
+ }
43
+
44
+ /// Runs the parsed command line, writing results to `out` and a failure's message to `err`;
45
+ /// returns the exit status.
46
+ fn execute(cli: args::Cli, out: &mut impl Write, err: &mut impl Write) -> u8 {
47
+ let status = match cli.command {
48
+ Some(command) => run_command(command, out, err),
49
+ None => {
50
+ let _ = args::Cli::command().print_help();
51
+ Ok(2)
52
+ }
53
+ };
54
+ // A closed pipe (`typedframes check | head`) is not an error worth a message.
55
+ let flushed = out.flush();
56
+ match (status, flushed) {
57
+ (Ok(code), Ok(())) => u8::try_from(code).unwrap_or(1),
58
+ (Err(error), _) | (_, Err(error)) if error.kind() == io::ErrorKind::BrokenPipe => 0,
59
+ (Err(error), _) | (_, Err(error)) => {
60
+ let _ = writeln!(err, "Error: {error}");
61
+ 1
62
+ }
63
+ }
64
+ }
65
+
66
+ /// Runs the command line `args` (program name first) and returns the exit status.
67
+ ///
68
+ /// Never ends the process, so an interpreter hosting the checker survives a usage error.
69
+ pub fn run<I, T>(args: I) -> u8
70
+ where
71
+ I: IntoIterator<Item = T>,
72
+ T: Into<OsString> + Clone,
73
+ {
74
+ let cli = match parse(args) {
75
+ Ok(cli) => cli,
76
+ Err((error, status)) => {
77
+ let _ = error.print();
78
+ return status;
79
+ }
80
+ };
81
+ // On a terminal output appears line by line, in step with stderr; to a pipe or file it is
82
+ // written in large blocks.
83
+ let stdout = io::stdout();
84
+ let mut out: Box<dyn Write> = if stdout.is_terminal() {
85
+ Box::new(LineWriter::new(stdout.lock()))
86
+ } else {
87
+ Box::new(BufWriter::new(stdout.lock()))
88
+ };
89
+ execute(cli, &mut out, &mut io::stderr())
90
+ }
91
+
92
+ /// Runs the command line `args` and returns the exit status with what it wrote to standard output
93
+ /// and, for a usage error or a failed command, to standard error. Anything else a command prints to
94
+ /// standard error (progress, warnings) still goes to the process's own.
95
+ pub fn run_captured<I, T>(args: I) -> (u8, Vec<u8>, Vec<u8>)
96
+ where
97
+ I: IntoIterator<Item = T>,
98
+ T: Into<OsString> + Clone,
99
+ {
100
+ let (mut out, mut err) = (Vec::new(), Vec::new());
101
+ let status = match parse(args) {
102
+ Ok(cli) => execute(cli, &mut out, &mut err),
103
+ Err((error, status)) => {
104
+ let target = if error.use_stderr() {
105
+ &mut err
106
+ } else {
107
+ &mut out
108
+ };
109
+ let _ = write!(target, "{}", error.render());
110
+ status
111
+ }
112
+ };
113
+ (status, out, err)
114
+ }
115
+
116
+ /// Runs the process's own command line.
117
+ pub fn main() -> ExitCode {
118
+ ExitCode::from(run(std::env::args_os()))
119
+ }
120
+
121
+ #[cfg(test)]
122
+ mod tests {
123
+ use super::*;
124
+
125
+ #[test]
126
+ fn captured_run_returns_the_output_instead_of_printing_it() {
127
+ let dir = tempfile::tempdir().unwrap();
128
+ std::fs::write(dir.path().join("a.py"), "x = 1\n").unwrap();
129
+ let path = dir.path().to_str().unwrap();
130
+
131
+ let (status, out, err) = run_captured([
132
+ "typedframes",
133
+ "check",
134
+ path,
135
+ "--no-cache",
136
+ "--output-format",
137
+ "json",
138
+ ]);
139
+
140
+ assert_eq!(status, 0);
141
+ assert!(String::from_utf8(out).unwrap().contains("\"errors\""));
142
+ assert!(err.is_empty());
143
+ }
144
+
145
+ #[test]
146
+ fn a_bad_command_line_is_a_status_and_a_message_not_an_exit() {
147
+ let (status, out, err) = run_captured(["typedframes", "no-such-command"]);
148
+
149
+ assert_eq!(status, 2);
150
+ assert!(out.is_empty());
151
+ assert!(String::from_utf8(err).unwrap().contains("no-such-command"));
152
+ }
153
+
154
+ #[test]
155
+ fn help_is_a_success_written_to_standard_output() {
156
+ let (status, out, err) = run_captured(["typedframes", "--help"]);
157
+
158
+ assert_eq!(status, 0);
159
+ assert!(!out.is_empty());
160
+ assert!(err.is_empty());
161
+ }
162
+
163
+ #[test]
164
+ fn a_failed_command_leaves_its_message_in_the_captured_error() {
165
+ let (status, out, err) = run_captured([
166
+ "typedframes",
167
+ "check",
168
+ "/no/such/path/anywhere",
169
+ "--no-cache",
170
+ ]);
171
+
172
+ assert_eq!(status, 2);
173
+ assert!(out.is_empty());
174
+ assert!(String::from_utf8(err)
175
+ .unwrap()
176
+ .contains("path does not exist"));
177
+ }
178
+ }
@@ -196,6 +196,38 @@ fn format_report_groups(groups: &[Group]) -> String {
196
196
  lines.join("\n")
197
197
  }
198
198
 
199
+ // A few lines per group, so a whole report fits in one screenshot.
200
+ fn format_report_groups_compact(groups: &[Group]) -> String {
201
+ let total: usize = groups.iter().map(Vec::len).sum();
202
+ let mut lines = vec![format!(
203
+ "typedframes {} {}/{}: {total} {}, {} {}",
204
+ env!("CARGO_PKG_VERSION"),
205
+ std::env::consts::OS,
206
+ std::env::consts::ARCH,
207
+ if total == 1 { "site" } else { "sites" },
208
+ groups.len(),
209
+ if groups.len() == 1 { "group" } else { "groups" }
210
+ )];
211
+ for (number, group) in groups.iter().enumerate() {
212
+ let best = representative(group);
213
+ lines.push(format!(
214
+ "{}. x{} {}",
215
+ number + 1,
216
+ group.len(),
217
+ group_title(group)
218
+ ));
219
+ match snippet(best).filter(|s| !s.is_empty()) {
220
+ Some(code) => lines.extend(
221
+ code.lines()
222
+ .filter(|l| !l.trim().is_empty())
223
+ .map(|l| format!(" {l}")),
224
+ ),
225
+ None => lines.push(format!(" no snippet: {}", text(best, "refusal"))),
226
+ }
227
+ }
228
+ lines.join("\n")
229
+ }
230
+
199
231
  fn report_groups_json(groups: &[Group]) -> String {
200
232
  let entries: Vec<Value> = groups
201
233
  .iter()
@@ -314,6 +346,8 @@ fn run_report_all(args: &ReportArgs, path: &Path, out: &mut impl Write) -> io::R
314
346
  }
315
347
  } else if args.report_format == ReportFormat::Json {
316
348
  writeln!(out, "{}", report_groups_json(&groups))?;
349
+ } else if args.report_format == ReportFormat::Compact {
350
+ writeln!(out, "{}", format_report_groups_compact(&groups))?;
317
351
  } else {
318
352
  writeln!(out, "{}", format_report_groups(&groups))?;
319
353
  }
@@ -636,6 +636,26 @@ fn test_should_group_every_untyped_site_with_report_all_and_write_one_file_per_g
636
636
  assert!(written.stdout.contains("01-"), "{}", written.stdout);
637
637
  }
638
638
 
639
+ #[test]
640
+ fn test_should_print_one_short_entry_per_group_with_report_all_compact() {
641
+ // arrange
642
+ let project = Project::new();
643
+ project.write("job.py", PRIVATE_SITE);
644
+
645
+ // act
646
+ let output = project.run(&["report", "--all", ".", "--no-index", "--format", "compact"]);
647
+
648
+ // assert
649
+ assert!(
650
+ output.stdout.contains("1 site, 1 group"),
651
+ "{}",
652
+ output.stdout
653
+ );
654
+ assert!(output.stdout.contains("1. x1 "), "{}", output.stdout);
655
+ assert!(!output.stdout.contains("<!--"), "{}", output.stdout);
656
+ assert!(output.stdout.lines().count() < 20, "{}", output.stdout);
657
+ }
658
+
639
659
  #[test]
640
660
  fn test_should_say_there_are_no_untyped_sites_when_there_are_none() {
641
661
  // arrange
@@ -33,7 +33,7 @@ Usage:
33
33
  df.filter(UserSchema.user_id.col > 10) # ✓ Refactor-safe polars expression
34
34
  """
35
35
 
36
- __version__ = "0.14.0"
36
+ __version__ = "0.14.1"
37
37
 
38
38
  from .base_schema import BaseSchema as BaseSchema
39
39
  from .column import Column as Column
@@ -0,0 +1,115 @@
1
+ """Running the `typedframes` command line: as the executable installed alongside this package, or in this process.
2
+
3
+ The in-process mode runs the same checker from the `typedframes._rust` extension module. It is for
4
+ environments where the Python interpreter may run code but no other executable may be started.
5
+ """
6
+
7
+ import os
8
+ import shutil
9
+ import subprocess
10
+ import sys
11
+ from importlib import import_module
12
+ from pathlib import Path
13
+ from sysconfig import get_config_var, get_path, get_preferred_scheme
14
+ from types import ModuleType
15
+
16
+ IN_PROCESS_VARIABLE = "TYPEDFRAMES_INPROC"
17
+ _OFF_VALUES = frozenset({"", "0", "false", "no", "off"})
18
+
19
+
20
+ class BinaryNotFoundError(FileNotFoundError):
21
+ """Raised when the `typedframes` executable is not installed."""
22
+
23
+
24
+ def find_binary() -> Path:
25
+ """The `typedframes` executable: next to the interpreter's scripts, then the user's, then on PATH.
26
+
27
+ Raises:
28
+ BinaryNotFoundError: If none of those hold it, e.g. the package was installed without it.
29
+ """
30
+ name = f"typedframes{get_config_var('EXE') or ''}"
31
+ scripts = Path(get_path("scripts")) / name
32
+ user_scripts = Path(get_path("scripts", scheme=get_preferred_scheme("user"))) / name
33
+ # `pip install --target` puts scripts in a `bin` directory beside the package.
34
+ target = Path(__file__).resolve().parents[1] / "bin" / name
35
+ for candidate in (scripts, user_scripts, target):
36
+ if candidate.is_file():
37
+ return candidate
38
+ on_path = shutil.which("typedframes")
39
+ if on_path is not None:
40
+ return Path(on_path)
41
+ msg = (
42
+ f"The typedframes executable was not found (looked for {scripts}). "
43
+ "Reinstall typedframes from a wheel, or build it from source with: uv run inv build"
44
+ )
45
+ raise BinaryNotFoundError(msg)
46
+
47
+
48
+ def _requested_in_process() -> bool:
49
+ """Whether the environment asks for the checker to run inside this process."""
50
+ return os.environ.get(IN_PROCESS_VARIABLE, "").strip().lower() not in _OFF_VALUES
51
+
52
+
53
+ def _extension() -> ModuleType:
54
+ """The `typedframes._rust` extension module.
55
+
56
+ Raises:
57
+ BinaryNotFoundError: If the package was installed without it.
58
+ """
59
+ try:
60
+ return import_module("typedframes._rust")
61
+ except ImportError as e:
62
+ msg = (
63
+ "The typedframes extension module (typedframes._rust) was not found. "
64
+ "Reinstall typedframes from a wheel, or build it from source with: uv run inv build"
65
+ )
66
+ raise BinaryNotFoundError(msg) from e
67
+
68
+
69
+ def _executable_missing() -> bool:
70
+ try:
71
+ find_binary()
72
+ except BinaryNotFoundError:
73
+ return True
74
+ return False
75
+
76
+
77
+ def _in_process() -> bool:
78
+ """Whether to run in this process: when asked to, or when the executable is missing but the extension is not."""
79
+ if _requested_in_process():
80
+ return True
81
+ if not _executable_missing():
82
+ return False
83
+ try:
84
+ _extension()
85
+ except BinaryNotFoundError:
86
+ return False
87
+ return True
88
+
89
+
90
+ def run_binary(arguments: list[str], *, capture: bool = False) -> subprocess.CompletedProcess[str]:
91
+ """Run the command line with `arguments`; with `capture`, its standard output is returned instead of shared.
92
+
93
+ Raises:
94
+ BinaryNotFoundError: If neither the executable nor the extension module is installed.
95
+ """
96
+ if _in_process():
97
+ extension = _extension()
98
+ if capture:
99
+ status, stdout, stderr = extension.run_captured(["typedframes", *arguments])
100
+ return subprocess.CompletedProcess(args=arguments, returncode=status, stdout=stdout, stderr=stderr)
101
+ return subprocess.CompletedProcess(args=arguments, returncode=extension.main(["typedframes", *arguments]))
102
+ return subprocess.run([str(find_binary()), *arguments], capture_output=capture, text=True, check=False)
103
+
104
+
105
+ def main() -> None:
106
+ """Entry point for `python -m typedframes`: the command line, with this process's arguments.
107
+
108
+ Where the platform allows it the executable takes this process's place, so no Python process
109
+ is left waiting; Windows has no such call, and runs it as a child instead. Set `TYPEDFRAMES_INPROC=1`
110
+ to run in this process instead of starting the executable.
111
+ """
112
+ if sys.platform == "win32" or _in_process():
113
+ sys.exit(run_binary(sys.argv[1:]).returncode)
114
+ binary = str(find_binary())
115
+ os.execv(binary, [binary, *sys.argv[1:]])
@@ -0,0 +1,2 @@
1
+ def main(argv: list[str]) -> int: ...
2
+ def run_captured(argv: list[str]) -> tuple[int, str, str]: ...
@@ -71,7 +71,7 @@ class TypedFramesPlugin(Plugin):
71
71
  completed = run_binary(["check", key, "--output-format", "json"], capture=True)
72
72
  except BinaryNotFoundError as e:
73
73
  msg = (
74
- "typedframes checker executable not found. "
74
+ "typedframes checker not found. "
75
75
  "Ensure the package is properly installed with 'uv add typedframes' "
76
76
  "or build from source with 'uv run inv build'."
77
77
  )
@@ -1,62 +0,0 @@
1
- //! The `typedframes` command line.
2
-
3
- mod args;
4
- mod cache;
5
- mod check;
6
- mod collect;
7
- mod config;
8
- mod coverage;
9
- mod pathutil;
10
- mod pyfmt;
11
- mod report;
12
- mod style;
13
- mod suggest;
14
-
15
- use args::Command;
16
- use clap::CommandFactory;
17
- use std::io::{self, BufWriter, IsTerminal, LineWriter, Write};
18
- use std::process::ExitCode;
19
-
20
- fn run_command(command: Command, out: &mut impl Write) -> io::Result<i32> {
21
- match command {
22
- Command::Check(args) => check::run_check(&args, out),
23
- Command::Cache(args) => {
24
- cache::run_cache(args.action, &args.path, args.cache_dir.as_deref(), out)?;
25
- Ok(0)
26
- }
27
- Command::Suggest(args) => suggest::run_suggest(&args, out, &mut io::stdin().lock()),
28
- Command::Report(args) => report::run_report(&args, out),
29
- }
30
- }
31
-
32
- /// Parses the process arguments, runs the command and returns the exit status.
33
- pub fn main() -> ExitCode {
34
- let cli = args::parse();
35
- // On a terminal output appears line by line, in step with stderr; to a pipe or file it is
36
- // written in large blocks.
37
- let stdout = io::stdout();
38
- let mut out: Box<dyn Write> = if stdout.is_terminal() {
39
- Box::new(LineWriter::new(stdout.lock()))
40
- } else {
41
- Box::new(BufWriter::new(stdout.lock()))
42
- };
43
- let status = match cli.command {
44
- Some(command) => run_command(command, &mut out),
45
- None => {
46
- let _ = args::Cli::command().print_help();
47
- Ok(2)
48
- }
49
- };
50
- // A closed pipe (`typedframes check | head`) is not an error worth a message.
51
- let flushed = out.flush();
52
- match (status, flushed) {
53
- (Ok(code), Ok(())) => ExitCode::from(u8::try_from(code).unwrap_or(1)),
54
- (Err(error), _) | (_, Err(error)) if error.kind() == io::ErrorKind::BrokenPipe => {
55
- ExitCode::SUCCESS
56
- }
57
- (Err(error), _) | (_, Err(error)) => {
58
- eprintln!("Error: {error}");
59
- ExitCode::from(1)
60
- }
61
- }
62
- }
@@ -1,57 +0,0 @@
1
- """Finding and running the `typedframes` executable that was installed alongside this package."""
2
-
3
- import os
4
- import shutil
5
- import subprocess
6
- import sys
7
- from pathlib import Path
8
- from sysconfig import get_config_var, get_path, get_preferred_scheme
9
-
10
-
11
- class BinaryNotFoundError(FileNotFoundError):
12
- """Raised when the `typedframes` executable is not installed."""
13
-
14
-
15
- def find_binary() -> Path:
16
- """The `typedframes` executable: next to the interpreter's scripts, then the user's, then on PATH.
17
-
18
- Raises:
19
- BinaryNotFoundError: If none of those hold it, e.g. the package was installed without it.
20
- """
21
- name = f"typedframes{get_config_var('EXE') or ''}"
22
- scripts = Path(get_path("scripts")) / name
23
- user_scripts = Path(get_path("scripts", scheme=get_preferred_scheme("user"))) / name
24
- # `pip install --target` puts scripts in a `bin` directory beside the package.
25
- target = Path(__file__).resolve().parents[1] / "bin" / name
26
- for candidate in (scripts, user_scripts, target):
27
- if candidate.is_file():
28
- return candidate
29
- on_path = shutil.which("typedframes")
30
- if on_path is not None:
31
- return Path(on_path)
32
- msg = (
33
- f"The typedframes executable was not found (looked for {scripts}). "
34
- "Reinstall typedframes from a wheel, or build it from source with: uv run inv build"
35
- )
36
- raise BinaryNotFoundError(msg)
37
-
38
-
39
- def run_binary(arguments: list[str], *, capture: bool = False) -> subprocess.CompletedProcess[str]:
40
- """Run the executable with `arguments`; with `capture`, its output is returned instead of shared.
41
-
42
- Raises:
43
- BinaryNotFoundError: If the executable is not installed.
44
- """
45
- return subprocess.run([str(find_binary()), *arguments], capture_output=capture, text=True, check=False)
46
-
47
-
48
- def main() -> None:
49
- """Entry point for `python -m typedframes`: the executable, with this process's arguments.
50
-
51
- Where the platform allows it the executable takes this process's place, so no Python process
52
- is left waiting; Windows has no such call, and runs it as a child instead.
53
- """
54
- if sys.platform == "win32":
55
- sys.exit(run_binary(sys.argv[1:]).returncode)
56
- binary = str(find_binary())
57
- os.execv(binary, [binary, *sys.argv[1:]])
File without changes
File without changes