cloudpickle-rust 0.1.0__tar.gz → 0.3.0__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 (85) hide show
  1. cloudpickle_rust-0.3.0/.coveragerc +11 -0
  2. cloudpickle_rust-0.3.0/.github/workflows/testing.yml +168 -0
  3. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/.gitignore +5 -0
  4. cloudpickle_rust-0.3.0/CHANGES.md +84 -0
  5. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/Cargo.lock +1 -1
  6. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/Cargo.toml +1 -1
  7. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/LICENSE +3 -0
  8. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/PKG-INFO +111 -38
  9. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/README.md +110 -37
  10. cloudpickle_rust-0.3.0/ci/install_coverage_subprocess_pth.py +16 -0
  11. cloudpickle_rust-0.3.0/codecov.yml +7 -0
  12. cloudpickle_rust-0.3.0/dev/generate_upstream_docs.py +91 -0
  13. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/dev-requirements.txt +4 -0
  14. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/python/cloudpickle_rust/__init__.py +5 -1
  15. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/python/cloudpickle_rust/cloudpickle.pyi +3 -0
  16. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/code.rs +135 -58
  17. cloudpickle_rust-0.3.0/src/fallback.rs +728 -0
  18. cloudpickle_rust-0.3.0/src/functions.rs +250 -0
  19. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/lib.rs +71 -8
  20. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/lookup.rs +93 -34
  21. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/pickler.rs +286 -145
  22. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/reconstructors.rs +96 -49
  23. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/reducers.rs +92 -51
  24. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/state.rs +13 -5
  25. cloudpickle_rust-0.3.0/src/upstream/cloudpickle.py +1566 -0
  26. cloudpickle_rust-0.3.0/src/upstream_docs.rs +40 -0
  27. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/src/utils.rs +14 -33
  28. cloudpickle_rust-0.3.0/tests/cloudpickle_rust_test.py +794 -0
  29. cloudpickle_rust-0.1.0/.github/workflows/testing.yml +0 -81
  30. cloudpickle_rust-0.1.0/CHANGES.md +0 -35
  31. cloudpickle_rust-0.1.0/tests/cloudpickle_rust_test.py +0 -344
  32. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/.github/workflows/publish_to_pypi.yml +0 -0
  33. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/.pre-commit-config.yaml +0 -0
  34. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/NOTICE +0 -0
  35. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/benchmarks/bench.py +0 -0
  36. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/build.rs +0 -0
  37. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/licenses/LICENSE-cloudpickle.txt +0 -0
  38. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/pyproject.toml +0 -0
  39. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/python/cloudpickle_rust/cloudpickle_fast.py +0 -0
  40. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/python/cloudpickle_rust/py.typed +0 -0
  41. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/__init__.py +0 -0
  42. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/cloudpickle_file_test.py +0 -0
  43. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/cloudpickle_ipykernel_test.py +0 -0
  44. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/cloudpickle_test.py +0 -0
  45. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py +0 -0
  46. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/cloudpickle_testpkg/_cloudpickle_testpkg/mod.py +0 -0
  47. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/cloudpickle_testpkg/setup.py +0 -0
  48. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/generate_old_pickles.py +0 -0
  49. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/mock_local_folder/mod.py +0 -0
  50. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/mock_local_folder/subfolder/submod.py +0 -0
  51. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/class_with_type_hints.pkl +0 -0
  52. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/cloudpickle_version.txt +0 -0
  53. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/function_with_type_hints.pkl +0 -0
  54. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/nested_function.pkl +0 -0
  55. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/simple_class.pkl +0 -0
  56. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/simple_enum.pkl +0 -0
  57. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/simple_func.pkl +0 -0
  58. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_310/simple_module.pkl +0 -0
  59. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/class_with_type_hints.pkl +0 -0
  60. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/cloudpickle_version.txt +0 -0
  61. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/function_with_type_hints.pkl +0 -0
  62. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/nested_function.pkl +0 -0
  63. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/simple_class.pkl +0 -0
  64. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/simple_enum.pkl +0 -0
  65. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/simple_func.pkl +0 -0
  66. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_311/simple_module.pkl +0 -0
  67. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/class_with_type_hints.pkl +0 -0
  68. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/cloudpickle_version.txt +0 -0
  69. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/function_with_type_hints.pkl +0 -0
  70. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/nested_function.pkl +0 -0
  71. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/simple_class.pkl +0 -0
  72. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/simple_enum.pkl +0 -0
  73. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/simple_func.pkl +0 -0
  74. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_38/simple_module.pkl +0 -0
  75. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/class_with_type_hints.pkl +0 -0
  76. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/cloudpickle_version.txt +0 -0
  77. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/function_with_type_hints.pkl +0 -0
  78. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/nested_function.pkl +0 -0
  79. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/simple_class.pkl +0 -0
  80. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/simple_enum.pkl +0 -0
  81. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/simple_func.pkl +0 -0
  82. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/old_pickles/cpython_39/simple_module.pkl +0 -0
  83. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/test_backward_compat.py +0 -0
  84. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tests/testutils.py +0 -0
  85. {cloudpickle_rust-0.1.0 → cloudpickle_rust-0.3.0}/tox.ini +0 -0
@@ -0,0 +1,11 @@
1
+ [run]
2
+ branch = True
3
+ parallel = True
4
+ source = cloudpickle_rust
5
+
6
+ [report]
7
+ exclude_lines =
8
+ pragma: no cover
9
+ def __repr__
10
+ if __name__ == .__main__.:
11
+ ignore_errors = True
@@ -0,0 +1,168 @@
1
+ name: Automated Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+ branches: [main, master]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ lint:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+ - name: Set up Python 3.11
18
+ uses: actions/setup-python@v6
19
+ with:
20
+ python-version: 3.11
21
+ - name: Set up Rust
22
+ uses: dtolnay/rust-toolchain@stable
23
+ with:
24
+ components: rustfmt, clippy
25
+ - name: Install pre-commit
26
+ shell: bash
27
+ run: |
28
+ python -V
29
+ python -m pip install pre-commit
30
+ - name: Run pre-commit linters
31
+ shell: bash
32
+ run: |
33
+ pre-commit run --all-files
34
+ - name: Run clippy
35
+ run: cargo clippy --all-targets -- -D warnings
36
+
37
+ build:
38
+ strategy:
39
+ fail-fast: false
40
+ matrix:
41
+ os: [ubuntu-latest, windows-latest, macos-latest]
42
+ python_version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.13t", "3.14t", "pypy-3.11"]
43
+ exclude:
44
+ # Do not test all minor versions on all platforms, especially if they
45
+ # are not the oldest/newest supported versions
46
+ - os: windows-latest
47
+ python_version: 3.8
48
+ # as of 4/02/2020, psutil won't build under PyPy + Windows
49
+ - os: windows-latest
50
+ python_version: "pypy-3.11"
51
+ - os: macos-latest
52
+ python_version: 3.8
53
+ - os: macos-latest
54
+ # numpy triggers: RuntimeError: Polyfit sanity test emitted a
55
+ # warning
56
+ python_version: "pypy-3.11"
57
+
58
+ runs-on: ${{ matrix.os }}
59
+
60
+ steps:
61
+ - uses: actions/checkout@v6
62
+ - name: Set up Python ${{ matrix.python_version }}
63
+ uses: actions/setup-python@v6
64
+ with:
65
+ python-version: ${{ matrix.python_version }}
66
+ allow-prereleases: true
67
+ - name: Set up Rust
68
+ uses: dtolnay/rust-toolchain@stable
69
+ - name: Install project and dependencies
70
+ shell: bash
71
+ run: |
72
+ python -m pip install --upgrade pip
73
+ python -m pip install -e .
74
+ python -m pip install -r dev-requirements.txt
75
+ - name: Display Python version
76
+ shell: bash
77
+ run: python -c "import sys; print(sys.version)"
78
+ - name: Test with pytest
79
+ shell: bash
80
+ run: |
81
+ PYTHONPATH='.:tests' python -m pytest -r s -vs
82
+
83
+ coverage:
84
+ # Coverage of the Rust code, measured with cargo-llvm-cov (LLVM
85
+ # source-based code coverage) on an instrumented build of the extension
86
+ # module, and of the Python code, measured with coverage.py, in the pytest
87
+ # process and its Python subprocesses. It is measured with every version of
88
+ # Python and PyPy as the Rust code has version-specific code paths: Codecov
89
+ # merges the reports.
90
+ name: coverage (${{ matrix.python_version }})
91
+ runs-on: ubuntu-latest
92
+ permissions:
93
+ contents: read
94
+ # To upload the reports to Codecov with OpenID Connect (without token).
95
+ id-token: write
96
+ strategy:
97
+ fail-fast: false
98
+ matrix:
99
+ # PyPy 7.3 (pypy3.11-v7.3.x) and PyPy 8.0 (pypy-3.11) have different
100
+ # code objects.
101
+ python_version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.13t", "3.14t", "pypy3.11-v7.3.x", "pypy-3.11"]
102
+
103
+ steps:
104
+ - uses: actions/checkout@v6
105
+ with:
106
+ persist-credentials: false
107
+ - name: Set up Python ${{ matrix.python_version }}
108
+ uses: actions/setup-python@v6
109
+ with:
110
+ python-version: ${{ matrix.python_version }}
111
+ allow-prereleases: true
112
+ - name: Set up Rust
113
+ uses: dtolnay/rust-toolchain@stable
114
+ with:
115
+ components: llvm-tools-preview
116
+ - name: Install cargo-llvm-cov
117
+ uses: taiki-e/install-action@cargo-llvm-cov
118
+ - name: Install project (instrumented build) and dependencies
119
+ shell: bash
120
+ run: |
121
+ # Build the extension module with the coverage instrumentation.
122
+ eval "$(cargo llvm-cov show-env --sh)"
123
+ cargo llvm-cov clean --workspace
124
+ python -m pip install --upgrade pip
125
+ MATURIN_PEP517_ARGS="--profile dev" python -m pip install -e .
126
+ python -m pip install -r dev-requirements.txt
127
+ python ci/install_coverage_subprocess_pth.py
128
+ - name: Display Python version
129
+ shell: bash
130
+ run: python -c "import sys; print(sys.version)"
131
+ - name: Test with pytest
132
+ shell: bash
133
+ run: |
134
+ # The instrumented extension module writes its profile data where
135
+ # cargo llvm-cov reads it.
136
+ eval "$(cargo llvm-cov show-env --sh)"
137
+ COVERAGE_PROCESS_START=$GITHUB_WORKSPACE/.coveragerc \
138
+ PYTHONPATH='.:tests' python -m pytest -r s -vs
139
+ coverage combine --append
140
+ coverage xml -i
141
+ cargo llvm-cov report --lcov --output-path rust-coverage.lcov
142
+ - name: Write the coverage summary and HTML reports
143
+ shell: bash
144
+ run: |
145
+ eval "$(cargo llvm-cov show-env --sh)"
146
+ cargo llvm-cov report --html --output-dir coverage-report
147
+ coverage html -i -d coverage-report/python
148
+ {
149
+ echo "## Coverage (Python ${{ matrix.python_version }})"
150
+ echo "### Rust code"
151
+ echo '```'
152
+ cargo llvm-cov report --summary-only
153
+ echo '```'
154
+ echo "### Python code"
155
+ coverage report -i --format=markdown
156
+ } >> "$GITHUB_STEP_SUMMARY"
157
+ - name: Upload the HTML coverage reports
158
+ uses: actions/upload-artifact@v6
159
+ with:
160
+ name: coverage-report-${{ matrix.python_version }}
161
+ path: coverage-report
162
+ - name: Publish coverage results
163
+ uses: codecov/codecov-action@v7
164
+ with:
165
+ files: ./rust-coverage.lcov,./coverage.xml
166
+ disable_search: true
167
+ name: ${{ matrix.python_version }}
168
+ use_oidc: true
@@ -53,6 +53,11 @@ nosetests.xml
53
53
  coverage.xml
54
54
  *,cover
55
55
  .pytest_cache
56
+ # Coverage of the Rust code (cargo-llvm-cov)
57
+ *.profraw
58
+ *.profdata
59
+ *.lcov
60
+ /coverage-report/
56
61
 
57
62
  # Translations
58
63
  *.mo
@@ -0,0 +1,84 @@
1
+ 0.3.0
2
+ =====
3
+
4
+ - Add `cloudpickle_rust.cloudpickle.DYNAMIC_CODE_FILENAME`, the `co_filename`
5
+ given to the code pickled by value (`"<dynamic-code>"` by default, as
6
+ upstream). Setting it to `None` keeps the original filenames, as cloudpickle
7
+ 3.1 and earlier did, for the tracebacks and the profilers of the processes
8
+ that load the code, for instance the Python UDFs of Apache Spark.
9
+
10
+ - Like upstream's, the functions of `cloudpickle_rust.cloudpickle` and the
11
+ methods of `Pickler` (except `reducer_override`) are now Python functions,
12
+ with upstream's signatures (including `_make_cell(value=_empty_cell_value)`),
13
+ docstrings and globals, which call their Rust implementation: they are
14
+ `types.FunctionType` instances, so that `Pickler` subclasses see the same
15
+ calls to `_function_reduce` as with upstream cloudpickle, and warnings
16
+ raised while pickling are attributed to the module like upstream's.
17
+
18
+ - Replacing a global of `cloudpickle_rust.cloudpickle` (its state such as
19
+ `_PICKLE_BY_VALUE_MODULES`, its functions, the modules it imported) or an
20
+ attribute of a standard library module used by cloudpickle (such as
21
+ `types.FunctionType` or `uuid.uuid4`), for instance with `monkeypatch`, now
22
+ changes the behavior like with upstream cloudpickle: the affected functions
23
+ run upstream's code, from a copy of upstream's `cloudpickle.py` included in
24
+ the package.
25
+
26
+ - `_extract_code_globals_cache` is a `weakref.WeakKeyDictionary` and
27
+ `_empty_cell_value` is an instance of a Python class, like upstream's.
28
+
29
+ - Same error messages as upstream cloudpickle for `_getattribute` on Python
30
+ 3.12 and 3.13, for the unpacking of the states of `_function_setstate` and
31
+ `_class_setstate` on Python 3.14, for file objects whose `mode` or `name` is
32
+ not a string, and when `register_pickle_by_value` and
33
+ `unregister_pickle_by_value` format a module.
34
+
35
+ - `_walk_global_ops`, `_extract_code_globals` and `_find_imported_submodules`
36
+ accept the same objects as upstream's (for instance a function rather than a
37
+ code object).
38
+
39
+ - On PyPy, the functions of the module are saved by `Pickler.save_function`
40
+ like upstream's, and `Pickler` has no `reducer_override` method anymore.
41
+
42
+ - Pickling functions and classes is about 10% slower than with 0.1.0 (the
43
+ cost of the checks of the globals and of upstream's
44
+ `weakref.WeakKeyDictionary` cache): see the updated benchmark in README.md.
45
+
46
+ - Test coverage: the `coverage` job of the Automated Tests workflow measures
47
+ the coverage of the Rust code (with cargo-llvm-cov) and of the Python code
48
+ with every supported version of Python and PyPy, and uploads it to Codecov.
49
+
50
+ 0.1.0
51
+ =====
52
+
53
+ - Initial release: a Rust implementation (built with PyO3 and maturin) of
54
+ [cloudpickle](https://github.com/cloudpipe/cloudpickle) 3.2.0.dev0
55
+ (upstream commit `4af5936`, "MNT: account for removed opcode in Python 3.16
56
+ (#599)"), including the deterministic `co_filename` of dynamic code
57
+ ([PR#560](https://github.com/cloudpipe/cloudpickle/pull/560)).
58
+
59
+ - Same public and private API as `cloudpickle`, under the `cloudpickle_rust`
60
+ package: `cloudpickle_rust.cloudpickle` is the Rust extension module
61
+ equivalent to `cloudpickle/cloudpickle.py`.
62
+
63
+ - Payloads are identical to the ones of upstream cloudpickle (same pickle
64
+ opcodes and memoization), except for the module of the reconstructors
65
+ (`cloudpickle_rust.cloudpickle` instead of `cloudpickle.cloudpickle`).
66
+
67
+ - The upstream test-suite passes with exactly the same outcomes as upstream
68
+ cloudpickle on CPython 3.8 to 3.14 and free-threaded CPython 3.13t and
69
+ 3.14t.
70
+
71
+ - 1.4x to 1.7x faster than cloudpickle to pickle dynamic functions, classes
72
+ and their instances (see `benchmarks/bench.py`).
73
+
74
+ - Supports PyPy 3.11 (PyPy 7.3.20+ and 8.0), on which upstream cloudpickle
75
+ 3.1.2 / 3.2.0.dev0 cannot be used: it fails at import time because
76
+ `pickle.Pickler` became a native class without a `dispatch` attribute (and
77
+ its code objects reducer does not match the signature of `types.CodeType`
78
+ in PyPy 7.3, which differs from the one of CPython and PyPy 8).
79
+
80
+ - Supports free-threaded CPython builds without re-enabling the GIL.
81
+
82
+ - Licensed under the Apache License, Version 2.0. The code derived from
83
+ cloudpickle and the files copied from it keep their BSD 3-Clause license
84
+ notice (see `licenses/LICENSE-cloudpickle.txt` and `NOTICE`).
@@ -4,7 +4,7 @@ version = 4
4
4
 
5
5
  [[package]]
6
6
  name = "cloudpickle-rust"
7
- version = "0.1.0"
7
+ version = "0.3.0"
8
8
  dependencies = [
9
9
  "pyo3",
10
10
  "pyo3-build-config",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "cloudpickle-rust"
3
- version = "0.1.0"
3
+ version = "0.3.0"
4
4
  edition = "2021"
5
5
  rust-version = "1.83"
6
6
  description = "A Rust implementation of cloudpickle: extended pickling support for Python objects"
@@ -213,3 +213,6 @@ src/*.rs (a Rust implementation of cloudpickle/cloudpickle.py)
213
213
  python/cloudpickle_rust/__init__.py
214
214
  python/cloudpickle_rust/cloudpickle_fast.py
215
215
  tests/ (the cloudpickle test-suite, except tests/cloudpickle_rust_test.py)
216
+ ci/install_coverage_subprocess_pth.py
217
+ src/upstream/cloudpickle.py (a copy of cloudpickle/cloudpickle.py)
218
+ src/upstream_docs.rs (the docstrings of cloudpickle/cloudpickle.py)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloudpickle-rust
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Operating System :: POSIX
@@ -38,6 +38,7 @@ Project-URL: Upstream, https://github.com/cloudpipe/cloudpickle
38
38
  # cloudpickle-rust
39
39
 
40
40
  [![Automated Tests](https://github.com/HyukjinKwon/cloudpickle-rust/actions/workflows/testing.yml/badge.svg?branch=main&event=push)](https://github.com/HyukjinKwon/cloudpickle-rust/actions/workflows/testing.yml)
41
+ [![codecov.io](https://codecov.io/github/HyukjinKwon/cloudpickle-rust/coverage.svg?branch=main)](https://codecov.io/github/HyukjinKwon/cloudpickle-rust?branch=main)
41
42
  [![PyPI](https://img.shields.io/pypi/v/cloudpickle-rust.svg)](https://pypi.org/project/cloudpickle-rust/)
42
43
 
43
44
  `cloudpickle-rust` is a Rust implementation of
@@ -196,7 +197,7 @@ situations:
196
197
  Compatibility with cloudpickle
197
198
  ------------------------------
198
199
 
199
- `cloudpickle-rust` 0.1.0 implements cloudpickle 3.2.0.dev0 (upstream commit
200
+ `cloudpickle-rust` 0.3.0 implements cloudpickle 3.2.0.dev0 (upstream commit
200
201
  [`4af5936`](https://github.com/cloudpipe/cloudpickle/commit/4af5936c328de0b33fa9c636e210d9a9e1e97dd3)).
201
202
 
202
203
  - **Same structure and API.** The package mirrors upstream: `cloudpickle_rust/__init__.py`,
@@ -206,6 +207,21 @@ Compatibility with cloudpickle
206
207
  exists in `cloudpickle_rust.cloudpickle` (`Pickler`, `dumps`,
207
208
  `register_pickle_by_value`, but also the private helpers such as
208
209
  `_should_pickle_by_reference` or `_make_skeleton_class`).
210
+ - **Same functions.** Like upstream's, the functions of
211
+ `cloudpickle_rust.cloudpickle` and the methods of its `Pickler` (except
212
+ `reducer_override`, see below) are Python functions, with the signatures,
213
+ the docstrings and the globals (the namespace of the module) of upstream's:
214
+ they call their Rust implementation, which they keep in their closure.
215
+ - **Same globals.** Like upstream's code, cloudpickle-rust reads the globals of
216
+ its module (its state such as `_PICKLE_BY_VALUE_MODULES`, its functions, the
217
+ modules it imported) and the attributes of the standard library modules it
218
+ uses (`types.FunctionType`, `uuid.uuid4`, `sys.modules`...) when it runs:
219
+ replacing any of them, for instance with `monkeypatch`, changes its behavior
220
+ like upstream's. Each Rust function checks that the globals read by the
221
+ upstream function still hold their initial values (a dictionary lookup
222
+ each); if not, it runs the upstream function itself, from a copy of
223
+ upstream's `cloudpickle.py` included in the package, with the namespace of
224
+ `cloudpickle_rust.cloudpickle` as its globals.
209
225
  - **Same payloads.** For a given object, the pickle opcodes (including the
210
226
  memoization of objects, which cloudpickle carefully controls to produce
211
227
  deterministic payloads) are identical to the ones produced by upstream
@@ -214,7 +230,9 @@ Compatibility with cloudpickle
214
230
  test-suite, where only `import cloudpickle` was replaced by
215
231
  `import cloudpickle_rust as cloudpickle`. On CPython 3.8 to 3.14 and
216
232
  free-threaded 3.13t and 3.14t, every test has the same outcome (pass, skip
217
- or expected failure) as with upstream cloudpickle.
233
+ or expected failure) as with upstream cloudpickle. Additional tests compare
234
+ the payloads, the functions and the behavior when globals are replaced with
235
+ upstream cloudpickle's.
218
236
  - **PyPy 3.11.** Upstream cloudpickle cannot be imported on PyPy 3.11 (PyPy
219
237
  7.3.20+ and 8.0), whose `pickle.Pickler` became a native class without the
220
238
  `dispatch` attribute that its PyPy implementation relies on (and its reducer
@@ -224,29 +242,44 @@ Compatibility with cloudpickle
224
242
  and passes the whole test-suite on PyPy 7.3.23 and 8.0.1. On PyPy 8.0.1,
225
243
  with upstream's import fixed, every upstream test has the same outcome.
226
244
 
227
- The few implementation-level differences, which do not change what is
245
+ The remaining implementation-level differences, which do not change what is
228
246
  pickled:
229
247
 
230
- - The `Pickler` methods are implemented in Rust (as method descriptors, like
231
- the methods of builtin types) instead of Python functions, and
232
- `Pickler.dispatch_table` is a subclass of `collections.ChainMap` with a
233
- native `__getitem__`.
234
- - Internal calls between the functions of the module are native: replacing a
235
- private function of `cloudpickle_rust.cloudpickle` (for instance with
236
- `monkeypatch`) does not change the behavior of the pickler. The module-level
237
- `Pickler` and `DEFAULT_PROTOCOL` attributes, as well as the standard library
238
- functions used by cloudpickle (`uuid.uuid4`, `io.BytesIO`, ...), are looked
239
- up at call time like in upstream.
240
- - `_walk_global_ops` decodes the bytecode directly (the encoding of the
241
- global-referencing instructions is measured when the module is imported),
242
- instead of relying on `dis.get_instructions`, and returns an iterator instead
243
- of a generator.
244
- - `_extract_code_globals_cache` maps `id(code)` to `(weakref(code), names)`
245
- instead of being a `weakref.WeakKeyDictionary`.
246
- - The functions accept the same arguments (including by keyword) as
247
- upstream, and `inspect.signature` reports the same signatures, except for
248
- `_make_cell(value=_empty_cell_value)`: the signature of a builtin function
249
- cannot have a default value which is not a literal.
248
+ - `Pickler.reducer_override`, which the C pickler calls for every object, is
249
+ a method descriptor implemented in Rust (like the methods of builtin types)
250
+ rather than a Python function: its `self` parameter is positional-only.
251
+ - `Pickler.dispatch_table` is a subclass of `collections.ChainMap`
252
+ (`_DispatchTable`) with a native `__getitem__`.
253
+ - `_walk_global_ops` decodes the bytecode of code objects directly (the
254
+ encoding of the global-referencing instructions is measured when the module
255
+ is imported) rather than with `dis.get_instructions`, and returns an
256
+ iterator rather than a generator.
257
+ - The builtins (`isinstance`, `getattr`, ...) are not part of the globals
258
+ checked by the Rust functions: shadowing them with globals of
259
+ `cloudpickle_rust.cloudpickle`, or replacing them in the `builtins` module,
260
+ does not change its behavior (unless it runs upstream's code because another
261
+ global was replaced).
262
+ - The Rust functions have no frames: exceptions raised by them have shorter
263
+ tracebacks, `dumps` passes `None` rather than a traceback to the `__exit__`
264
+ method of its `io.BytesIO` for such exceptions, and deeply nested objects
265
+ can reach the recursion limit at a slightly different depth.
266
+ - The docstring of the module also states the license of cloudpickle-rust.
267
+
268
+ One extension, which upstream does not have:
269
+
270
+ - `cloudpickle_rust.cloudpickle.DYNAMIC_CODE_FILENAME` is the `co_filename`
271
+ given to the code of the functions and classes pickled by value:
272
+ `"<dynamic-code>"` by default, as upstream since
273
+ [PR#560](https://github.com/cloudpipe/cloudpickle/pull/560), so that the
274
+ payloads do not depend on where the code is defined. Set it to `None` to
275
+ keep the original filenames, as cloudpickle 3.1 and earlier did, so that
276
+ the tracebacks and the profilers of the processes that load the code show
277
+ where it was defined. Like `DEFAULT_PROTOCOL`, it is looked up at call time:
278
+
279
+ ```python
280
+ >>> import cloudpickle_rust.cloudpickle
281
+ >>> cloudpickle_rust.cloudpickle.DYNAMIC_CODE_FILENAME = None
282
+ ```
250
283
 
251
284
 
252
285
  Performance
@@ -259,28 +292,28 @@ the pickler's `dispatch_table` (which cloudpickle performs in Python for every
259
292
  object that is not handled by `reducer_override`).
260
293
 
261
294
  Time of `dumps` with [`benchmarks/bench.py`](benchmarks/bench.py), on an
262
- Apple M3 Max with CPython 3.13.14 (release build of cloudpickle-rust 0.1.0,
295
+ Apple M3 Max with CPython 3.13.14 (release build of cloudpickle-rust,
263
296
  cloudpickle 3.2.0.dev0, best of 15 interleaved runs):
264
297
 
265
298
  | Payload | cloudpickle | cloudpickle-rust | Speedup |
266
299
  |---|---:|---:|---:|
267
- | A lambda | 10.7 µs | 7.2 µs | 1.48× |
268
- | A closure using globals | 16.1 µs | 10.6 µs | 1.52× |
269
- | A dynamic class | 27.7 µs | 16.8 µs | 1.65× |
270
- | A dynamic dataclass | 74.4 µs | 46.7 µs | 1.59× |
271
- | A dynamic enum | 19.6 µs | 11.7 µs | 1.68× |
272
- | A generic class (`typing.Generic`) | 32.7 µs | 19.9 µs | 1.64× |
273
- | 1,000 distinct lambdas | 5.16 ms | 3.51 ms | 1.47× |
274
- | 100,000 instances of a dynamic class | 94.1 ms | 59.5 ms | 1.58× |
275
- | 100,000 instances of a dynamic dataclass | 103.1 ms | 65.9 ms | 1.56× |
276
- | 100,000 builtin objects (dict of lists) | 25.8 ms | 25.3 ms | 1.02× |
300
+ | A lambda | 10.6 µs | 8.0 µs | 1.32× |
301
+ | A closure using globals | 16.6 µs | 11.9 µs | 1.40× |
302
+ | A dynamic class | 27.5 µs | 19.1 µs | 1.44× |
303
+ | A dynamic dataclass | 75.4 µs | 54.3 µs | 1.39× |
304
+ | A dynamic enum | 19.8 µs | 13.0 µs | 1.52× |
305
+ | A generic class (`typing.Generic`) | 32.8 µs | 22.6 µs | 1.45× |
306
+ | 1,000 distinct lambdas | 5.14 ms | 3.99 ms | 1.29× |
307
+ | 100,000 instances of a dynamic class | 93.4 ms | 60.8 ms | 1.54× |
308
+ | 100,000 instances of a dynamic dataclass | 99.2 ms | 66.7 ms | 1.49× |
309
+ | 100,000 builtin objects (dict of lists) | 19.4 ms | 19.3 ms | 1.00× |
277
310
 
278
311
  For the collections of instances, plain `pickle.dumps` (which pickles the
279
- classes by reference instead of by value) takes 41.1 ms and 46.3 ms: the time
280
- cloudpickle spends on top of the standard library pickler is about 3× smaller
312
+ classes by reference instead of by value) takes 41.2 ms and 45.9 ms: the time
313
+ cloudpickle spends on top of the standard library pickler is about 2.5× smaller
281
314
  with cloudpickle-rust. Builtin types (`dict`, `list`, `str`, `int`...) are
282
315
  handled by the standard library pickler without involving cloudpickle at all,
283
- hence the same speed (plain `pickle.dumps` takes 25.2 ms).
316
+ hence the same speed (plain `pickle.dumps` takes 19.1 ms).
284
317
 
285
318
 
286
319
  Running the tests
@@ -308,6 +341,46 @@ A Rust toolchain ([rustup](https://rustup.rs)) is required to build the
308
341
  extension module. During development, `maturin develop` rebuilds it in place.
309
342
 
310
343
 
344
+ Test coverage
345
+ -------------
346
+
347
+ The `coverage` job of the [`testing.yml`](.github/workflows/testing.yml)
348
+ workflow measures the coverage of the test-suite with every supported version
349
+ of Python and PyPy (on Linux), as the Rust code has version-specific code
350
+ paths, and uploads the reports to
351
+ [Codecov](https://codecov.io/github/HyukjinKwon/cloudpickle-rust), which merges
352
+ them. Each job also writes its coverage in its summary and uploads its HTML
353
+ reports as an artifact (`coverage-report-<Python version>`).
354
+
355
+ - The coverage of the Rust code (the implementation) is measured with
356
+ [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov) (LLVM
357
+ source-based code coverage) on an instrumented build of the extension
358
+ module, in the pytest process and in the Python subprocesses started by the
359
+ tests.
360
+ - The coverage of the Python code is measured with
361
+ [coverage.py](https://coverage.readthedocs.io), in subprocesses as well (as
362
+ in upstream cloudpickle).
363
+
364
+ To measure it locally:
365
+
366
+ rustup component add llvm-tools-preview
367
+ cargo install cargo-llvm-cov
368
+ eval "$(cargo llvm-cov show-env --sh)"
369
+ cargo llvm-cov clean --workspace
370
+ MATURIN_PEP517_ARGS="--profile dev" pip install -e .
371
+ pip install -r dev-requirements.txt
372
+ python ci/install_coverage_subprocess_pth.py
373
+ COVERAGE_PROCESS_START=$PWD/.coveragerc PYTHONPATH='.:tests' pytest
374
+ cargo llvm-cov report --html # target/llvm-cov/html/index.html
375
+ coverage combine --append && coverage html # htmlcov/index.html
376
+
377
+ `cargo llvm-cov show-env` sets the environment variables (in the current
378
+ shell) with which cargo builds an instrumented extension module, and with which
379
+ the instrumented extension module writes its profile data where
380
+ `cargo llvm-cov report` reads it. Run `pip install -e .` in a shell without
381
+ them to go back to a regular build.
382
+
383
+
311
384
  Releasing to PyPI
312
385
  -----------------
313
386