ocdiff 0.0.5__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.
@@ -0,0 +1,81 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ tags:
8
+ - '**'
9
+ pull_request: {}
10
+
11
+ jobs:
12
+ build:
13
+ name: build py${{ matrix.python-version }} on ${{ matrix.platform || matrix.os }}
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ os:
18
+ - macos
19
+ python-version:
20
+ - '3.11'
21
+ include:
22
+ - os: ubuntu
23
+ platform: linux
24
+ - os: windows
25
+ ls: dir
26
+ - python-version: 3.11
27
+ cibw-version: cp311
28
+
29
+ runs-on: ${{ format('{0}-latest', matrix.os) }}
30
+ steps:
31
+ - uses: actions/checkout@v2
32
+
33
+ - name: set up python
34
+ uses: actions/setup-python@v1
35
+ with:
36
+ python-version: ${{ matrix.python-version }}
37
+
38
+ - name: set up rust
39
+ uses: actions-rs/toolchain@v1
40
+ with:
41
+ toolchain: 1.74.0
42
+ profile: minimal
43
+ default: true
44
+ override: true
45
+
46
+ - name: install python dependencies
47
+ run: |
48
+ pip install twine
49
+ pip install -U build
50
+
51
+ - name: build ${{ matrix.platform || matrix.os }} binaries
52
+ run: python -m build
53
+ env:
54
+ CIBW_BUILD: '${{ matrix.cibw-version }}-*'
55
+ CIBW_SKIP: '*-win32'
56
+ CIBW_PLATFORM: ${{ matrix.platform || matrix.os }}
57
+ CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH"'
58
+ CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'
59
+ CIBW_BEFORE_BUILD: >
60
+ rustup show
61
+ CIBW_BEFORE_BUILD_LINUX: >
62
+ curl https://sh.rustup.rs -sSf | sh -s -- --profile=minimal -y &&
63
+ rustup show
64
+ CIBW_TEST_COMMAND: "pytest {project}/tests"
65
+ CIBW_TEST_EXTRAS: test
66
+
67
+ # - name: Upload to github releases
68
+ # if: startsWith(github.ref, 'refs/tags/')
69
+ # uses: svenstaro/upload-release-action@v2
70
+ # with:
71
+ # repo_token: ${{ secrets.GITHUB_TOKEN }}
72
+ # file: dist/*.whl
73
+ # file_glob: true
74
+ # tag: ${{ github.ref }}
75
+
76
+ - name: upload to pypi
77
+ if: startsWith(github.ref, 'refs/tags/')
78
+ run: twine upload dist/*
79
+ env:
80
+ TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
81
+ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
@@ -0,0 +1,163 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Profiles
10
+ *.prof
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py,cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # poetry
101
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105
+ #poetry.lock
106
+
107
+ # pdm
108
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109
+ #pdm.lock
110
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111
+ # in version control.
112
+ # https://pdm.fming.dev/#use-with-ide
113
+ .pdm.toml
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # Pyre type checker
150
+ .pyre/
151
+
152
+ # pytype static type analyzer
153
+ .pytype/
154
+
155
+ # Cython debug symbols
156
+ cython_debug/
157
+
158
+ # PyCharm
159
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
162
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
163
+ #.idea/
@@ -0,0 +1,318 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.1.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
10
+
11
+ [[package]]
12
+ name = "bitflags"
13
+ version = "1.3.2"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
16
+
17
+ [[package]]
18
+ name = "cfg-if"
19
+ version = "1.0.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
22
+
23
+ [[package]]
24
+ name = "heck"
25
+ version = "0.4.1"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
28
+
29
+ [[package]]
30
+ name = "html-escape"
31
+ version = "0.2.13"
32
+ source = "registry+https://github.com/rust-lang/crates.io-index"
33
+ checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476"
34
+ dependencies = [
35
+ "utf8-width",
36
+ ]
37
+
38
+ [[package]]
39
+ name = "indoc"
40
+ version = "2.0.4"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8"
43
+
44
+ [[package]]
45
+ name = "libc"
46
+ version = "0.2.153"
47
+ source = "registry+https://github.com/rust-lang/crates.io-index"
48
+ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
49
+
50
+ [[package]]
51
+ name = "lock_api"
52
+ version = "0.4.11"
53
+ source = "registry+https://github.com/rust-lang/crates.io-index"
54
+ checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
55
+ dependencies = [
56
+ "autocfg",
57
+ "scopeguard",
58
+ ]
59
+
60
+ [[package]]
61
+ name = "memoffset"
62
+ version = "0.9.0"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
65
+ dependencies = [
66
+ "autocfg",
67
+ ]
68
+
69
+ [[package]]
70
+ name = "ocdiff"
71
+ version = "0.0.1"
72
+ dependencies = [
73
+ "html-escape",
74
+ "pyo3",
75
+ "similar",
76
+ "unicode-width",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "once_cell"
81
+ version = "1.19.0"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
84
+
85
+ [[package]]
86
+ name = "parking_lot"
87
+ version = "0.12.1"
88
+ source = "registry+https://github.com/rust-lang/crates.io-index"
89
+ checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
90
+ dependencies = [
91
+ "lock_api",
92
+ "parking_lot_core",
93
+ ]
94
+
95
+ [[package]]
96
+ name = "parking_lot_core"
97
+ version = "0.9.9"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
100
+ dependencies = [
101
+ "cfg-if",
102
+ "libc",
103
+ "redox_syscall",
104
+ "smallvec",
105
+ "windows-targets",
106
+ ]
107
+
108
+ [[package]]
109
+ name = "portable-atomic"
110
+ version = "1.6.0"
111
+ source = "registry+https://github.com/rust-lang/crates.io-index"
112
+ checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
113
+
114
+ [[package]]
115
+ name = "proc-macro2"
116
+ version = "1.0.79"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
119
+ dependencies = [
120
+ "unicode-ident",
121
+ ]
122
+
123
+ [[package]]
124
+ name = "pyo3"
125
+ version = "0.20.3"
126
+ source = "registry+https://github.com/rust-lang/crates.io-index"
127
+ checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233"
128
+ dependencies = [
129
+ "cfg-if",
130
+ "indoc",
131
+ "libc",
132
+ "memoffset",
133
+ "parking_lot",
134
+ "portable-atomic",
135
+ "pyo3-build-config",
136
+ "pyo3-ffi",
137
+ "pyo3-macros",
138
+ "unindent",
139
+ ]
140
+
141
+ [[package]]
142
+ name = "pyo3-build-config"
143
+ version = "0.20.3"
144
+ source = "registry+https://github.com/rust-lang/crates.io-index"
145
+ checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7"
146
+ dependencies = [
147
+ "once_cell",
148
+ "target-lexicon",
149
+ ]
150
+
151
+ [[package]]
152
+ name = "pyo3-ffi"
153
+ version = "0.20.3"
154
+ source = "registry+https://github.com/rust-lang/crates.io-index"
155
+ checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa"
156
+ dependencies = [
157
+ "libc",
158
+ "pyo3-build-config",
159
+ ]
160
+
161
+ [[package]]
162
+ name = "pyo3-macros"
163
+ version = "0.20.3"
164
+ source = "registry+https://github.com/rust-lang/crates.io-index"
165
+ checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158"
166
+ dependencies = [
167
+ "proc-macro2",
168
+ "pyo3-macros-backend",
169
+ "quote",
170
+ "syn",
171
+ ]
172
+
173
+ [[package]]
174
+ name = "pyo3-macros-backend"
175
+ version = "0.20.3"
176
+ source = "registry+https://github.com/rust-lang/crates.io-index"
177
+ checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185"
178
+ dependencies = [
179
+ "heck",
180
+ "proc-macro2",
181
+ "pyo3-build-config",
182
+ "quote",
183
+ "syn",
184
+ ]
185
+
186
+ [[package]]
187
+ name = "quote"
188
+ version = "1.0.35"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
191
+ dependencies = [
192
+ "proc-macro2",
193
+ ]
194
+
195
+ [[package]]
196
+ name = "redox_syscall"
197
+ version = "0.4.1"
198
+ source = "registry+https://github.com/rust-lang/crates.io-index"
199
+ checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
200
+ dependencies = [
201
+ "bitflags",
202
+ ]
203
+
204
+ [[package]]
205
+ name = "scopeguard"
206
+ version = "1.2.0"
207
+ source = "registry+https://github.com/rust-lang/crates.io-index"
208
+ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
209
+
210
+ [[package]]
211
+ name = "similar"
212
+ version = "2.5.0"
213
+ source = "registry+https://github.com/rust-lang/crates.io-index"
214
+ checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640"
215
+
216
+ [[package]]
217
+ name = "smallvec"
218
+ version = "1.13.2"
219
+ source = "registry+https://github.com/rust-lang/crates.io-index"
220
+ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
221
+
222
+ [[package]]
223
+ name = "syn"
224
+ version = "2.0.53"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
227
+ dependencies = [
228
+ "proc-macro2",
229
+ "quote",
230
+ "unicode-ident",
231
+ ]
232
+
233
+ [[package]]
234
+ name = "target-lexicon"
235
+ version = "0.12.14"
236
+ source = "registry+https://github.com/rust-lang/crates.io-index"
237
+ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
238
+
239
+ [[package]]
240
+ name = "unicode-ident"
241
+ version = "1.0.12"
242
+ source = "registry+https://github.com/rust-lang/crates.io-index"
243
+ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
244
+
245
+ [[package]]
246
+ name = "unicode-width"
247
+ version = "0.1.11"
248
+ source = "registry+https://github.com/rust-lang/crates.io-index"
249
+ checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
250
+
251
+ [[package]]
252
+ name = "unindent"
253
+ version = "0.2.3"
254
+ source = "registry+https://github.com/rust-lang/crates.io-index"
255
+ checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce"
256
+
257
+ [[package]]
258
+ name = "utf8-width"
259
+ version = "0.1.7"
260
+ source = "registry+https://github.com/rust-lang/crates.io-index"
261
+ checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3"
262
+
263
+ [[package]]
264
+ name = "windows-targets"
265
+ version = "0.48.5"
266
+ source = "registry+https://github.com/rust-lang/crates.io-index"
267
+ checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
268
+ dependencies = [
269
+ "windows_aarch64_gnullvm",
270
+ "windows_aarch64_msvc",
271
+ "windows_i686_gnu",
272
+ "windows_i686_msvc",
273
+ "windows_x86_64_gnu",
274
+ "windows_x86_64_gnullvm",
275
+ "windows_x86_64_msvc",
276
+ ]
277
+
278
+ [[package]]
279
+ name = "windows_aarch64_gnullvm"
280
+ version = "0.48.5"
281
+ source = "registry+https://github.com/rust-lang/crates.io-index"
282
+ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
283
+
284
+ [[package]]
285
+ name = "windows_aarch64_msvc"
286
+ version = "0.48.5"
287
+ source = "registry+https://github.com/rust-lang/crates.io-index"
288
+ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
289
+
290
+ [[package]]
291
+ name = "windows_i686_gnu"
292
+ version = "0.48.5"
293
+ source = "registry+https://github.com/rust-lang/crates.io-index"
294
+ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
295
+
296
+ [[package]]
297
+ name = "windows_i686_msvc"
298
+ version = "0.48.5"
299
+ source = "registry+https://github.com/rust-lang/crates.io-index"
300
+ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
301
+
302
+ [[package]]
303
+ name = "windows_x86_64_gnu"
304
+ version = "0.48.5"
305
+ source = "registry+https://github.com/rust-lang/crates.io-index"
306
+ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
307
+
308
+ [[package]]
309
+ name = "windows_x86_64_gnullvm"
310
+ version = "0.48.5"
311
+ source = "registry+https://github.com/rust-lang/crates.io-index"
312
+ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
313
+
314
+ [[package]]
315
+ name = "windows_x86_64_msvc"
316
+ version = "0.48.5"
317
+ source = "registry+https://github.com/rust-lang/crates.io-index"
318
+ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
@@ -0,0 +1,29 @@
1
+ [package]
2
+ authors = ["Oliver Russell <ojhrussell@gmail.com>"]
3
+ name = "ocdiff"
4
+ version = "0.0.1"
5
+
6
+ [dependencies]
7
+ pyo3 = "0.20.0"
8
+ similar = "2.5.0"
9
+ html-escape = "0.2.13"
10
+ unicode-width = "0.1.11"
11
+
12
+ [lib]
13
+ name = "ocdiff"
14
+ crate-type = ["cdylib"]
15
+
16
+ [features]
17
+ default = ["pyo3/extension-module"]
18
+
19
+ [profile.dev]
20
+ # opt-level = 0
21
+ # debug = 2
22
+ # split-debuginfo = "unpacked"
23
+ opt-level = 3
24
+
25
+ [profile.release]
26
+ opt-level = 3
27
+
28
+ [profile.test]
29
+ opt-level = 3
ocdiff-0.0.5/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Oliver Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
ocdiff-0.0.5/PKG-INFO ADDED
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.3
2
+ Name: ocdiff
3
+ Version: 0.0.5
4
+ Classifier: Programming Language :: Python
5
+ Requires-Dist: maturin ==1.4.0 ; extra == 'dev'
6
+ Requires-Dist: pytest ==7.* ; extra == 'dev'
7
+ Requires-Dist: mypy ==1.6.* ; extra == 'dev'
8
+ Requires-Dist: pip ==24.0 ; extra == 'dev'
9
+ Provides-Extra: dev
10
+ License-File: LICENSE
11
+ Summary: difftastic Python wrapper
12
+ Keywords: diff
13
+ Author: Oliver Russell <ojhrussell@gmail.com>
14
+ Author-email: Oliver Russell <ojhrussell@gmail.com>
15
+ Maintainer-email: Oliver Russell <ojhrussell@gmail.com>
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
18
+ Project-URL: homepage, https://github.com/leontrolski/ocdiff
19
+ Project-URL: documentation, https://github.com/leontrolski/ocdiff
20
+ Project-URL: repository, https://github.com/leontrolski/ocdiff.git
21
+
22
+ # ocdiff
23
+
24
+ Fast diff library for Python - wraps [similar](https://crates.io/crates/similar).
25
+
26
+ # Install/Develop
27
+
28
+ ```shell
29
+ uv pip install -e '.[dev]'
30
+ maturin develop
31
+ ```
32
+
33
+ # Make release
34
+
35
+ - Add pypi token and user = `__token__` to settings (do this once).
36
+ - Upversion `pyproject.toml`.
37
+
38
+ ```shell
39
+ git tag -a v0.0.x head -m v0.0.x
40
+ git push origin v0.0.x
41
+ ```
42
+
43
+ # TODO
44
+
45
+ - Implement `column_limit` - should just be a function of `Vec<LinePartsDiff>` to `Vec<LinePartsDiff>`.
46
+ - Add console output with colours.
47
+ - Add pytest plugin magic that plays with `rich`.
48
+
ocdiff-0.0.5/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # ocdiff
2
+
3
+ Fast diff library for Python - wraps [similar](https://crates.io/crates/similar).
4
+
5
+ # Install/Develop
6
+
7
+ ```shell
8
+ uv pip install -e '.[dev]'
9
+ maturin develop
10
+ ```
11
+
12
+ # Make release
13
+
14
+ - Add pypi token and user = `__token__` to settings (do this once).
15
+ - Upversion `pyproject.toml`.
16
+
17
+ ```shell
18
+ git tag -a v0.0.x head -m v0.0.x
19
+ git push origin v0.0.x
20
+ ```
21
+
22
+ # TODO
23
+
24
+ - Implement `column_limit` - should just be a function of `Vec<LinePartsDiff>` to `Vec<LinePartsDiff>`.
25
+ - Add console output with colours.
26
+ - Add pytest plugin magic that plays with `rich`.
@@ -0,0 +1,51 @@
1
+ [project]
2
+ name = "ocdiff"
3
+ version = "0.0.5"
4
+ description = "difftastic Python wrapper"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = { file = "LICENSE" }
8
+ keywords = ["diff"]
9
+ authors = [{ name = "Oliver Russell", email = "ojhrussell@gmail.com" }]
10
+ maintainers = [{ name = "Oliver Russell", email = "ojhrussell@gmail.com" }]
11
+ classifiers = ["Programming Language :: Python"]
12
+
13
+ dependencies = []
14
+
15
+ [project.optional-dependencies]
16
+ dev = [
17
+ "maturin==1.4.0",
18
+ "pytest==7.*",
19
+ "mypy==1.6.*",
20
+ "pip==24.0"
21
+ ]
22
+
23
+ [project.urls]
24
+ homepage = "https://github.com/leontrolski/ocdiff"
25
+ documentation = "https://github.com/leontrolski/ocdiff"
26
+ repository = "https://github.com/leontrolski/ocdiff.git"
27
+
28
+ [tool.mypy]
29
+ # Strict mode; enables the following flags:
30
+ warn_unused_configs = true
31
+ disallow_any_generics = true
32
+ disallow_subclassing_any = true
33
+ disallow_untyped_calls = true
34
+ disallow_untyped_defs = true
35
+ disallow_incomplete_defs = true
36
+ check_untyped_defs = true
37
+ disallow_untyped_decorators = true
38
+ warn_redundant_casts = true
39
+ warn_unused_ignores = true
40
+ warn_return_any = true
41
+ no_implicit_reexport = true
42
+ strict_equality = true
43
+ no_implicit_optional = true
44
+
45
+ [build-system]
46
+ requires = ["maturin>=1.0,<2.0"]
47
+ build-backend = "maturin"
48
+
49
+ [tool.maturin]
50
+ python-source = "python"
51
+ strip = true
@@ -0,0 +1,6 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from . import ocdiff as _ocdiff # type: ignore
4
+
5
+ if not TYPE_CHECKING:
6
+ html_diff = _ocdiff.html_diff
@@ -0,0 +1,7 @@
1
+ def html_diff(
2
+ a: str,
3
+ b: str,
4
+ context_lines: int | None = None,
5
+ # Not respected yet
6
+ column_limit: int | None = None,
7
+ ) -> str: ...
@@ -0,0 +1,50 @@
1
+ import os
2
+ from typing import Any
3
+
4
+
5
+ # From https://github.com/jeffkaufman/icdiff
6
+ def get_number_of_cols() -> int:
7
+ if os.name == "nt":
8
+ try:
9
+ import struct
10
+ from ctypes import windll, create_string_buffer # type: ignore[attr-defined]
11
+
12
+ fh = windll.kernel32.GetStdHandle(-12) # stderr is -12
13
+ csbi = create_string_buffer(22)
14
+ windll.kernel32.GetConsoleScreenBufferInfo(fh, csbi)
15
+ res = struct.unpack("hhhhHhhhhhh", csbi.raw)
16
+ # right - left + 1
17
+ return res[7] - res[5] + 1 # type: ignore[no-any-return]
18
+
19
+ except Exception:
20
+ pass
21
+
22
+ else:
23
+
24
+ def ioctl_GWINSZ(fd: Any) -> tuple[Any, ...] | None:
25
+ try:
26
+ import fcntl
27
+ import termios
28
+ import struct
29
+
30
+ cr = struct.unpack(
31
+ "hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234") # type: ignore[call-overload]
32
+ )
33
+ except Exception:
34
+ return None
35
+ return cr
36
+
37
+ cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
38
+ if cr and cr[1] > 0:
39
+ return cr[1] # type: ignore[no-any-return]
40
+
41
+ return 80
42
+
43
+
44
+ # Other version...
45
+ # From: https://gist.github.com/jtriley/1108174
46
+ def get_terminal_width() -> int:
47
+ fd = os.open(os.ctermid(), os.O_RDONLY)
48
+ cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234")) # type: ignore
49
+ os.close(fd)
50
+ return int(cr[1])
@@ -0,0 +1,273 @@
1
+ extern crate html_escape;
2
+ extern crate pyo3;
3
+ extern crate similar;
4
+ extern crate unicode_width;
5
+
6
+ use html_escape::encode_text;
7
+ use pyo3::prelude::*;
8
+ use similar::{ChangeTag, TextDiff};
9
+ use unicode_width::UnicodeWidthStr;
10
+
11
+ #[derive(Clone)]
12
+ enum Part {
13
+ Equal(String),
14
+ Delete(String),
15
+ Insert(String),
16
+ }
17
+ struct PartsDiff {
18
+ parts: Vec<Part>,
19
+ }
20
+ struct LinePartsDiff {
21
+ left_lineno: i64,
22
+ left: PartsDiff,
23
+ right_lineno: i64,
24
+ right: PartsDiff,
25
+ }
26
+ struct LineDiff {
27
+ left_lineno: i64,
28
+ left: String,
29
+ right_lineno: i64,
30
+ right: String,
31
+ }
32
+ impl PartsDiff {
33
+ fn push_equal(&mut self, value: &str) {
34
+ match &mut self.parts.last_mut() {
35
+ Some(Part::Equal(s)) => {
36
+ s.push_str(value);
37
+ }
38
+ _ => {
39
+ let part = Part::Equal(String::from(value));
40
+ self.parts.push(part)
41
+ }
42
+ }
43
+ }
44
+ fn push_delete(&mut self, value: &str) {
45
+ match &mut self.parts.last_mut() {
46
+ Some(Part::Delete(s)) => {
47
+ s.push_str(value);
48
+ }
49
+ _ => {
50
+ let part = Part::Delete(String::from(value));
51
+ self.parts.push(part)
52
+ }
53
+ }
54
+ }
55
+ fn push_insert(&mut self, value: &str) {
56
+ match &mut self.parts.last_mut() {
57
+ Some(Part::Insert(s)) => {
58
+ s.push_str(value);
59
+ }
60
+ _ => {
61
+ let part = Part::Insert(String::from(value));
62
+ self.parts.push(part)
63
+ }
64
+ }
65
+ }
66
+ fn width(&self) -> usize {
67
+ let mut width: usize = 0;
68
+ for part in &self.parts {
69
+ match part {
70
+ Part::Equal(s) => width += UnicodeWidthStr::width(s.as_str()),
71
+ Part::Delete(s) => width += UnicodeWidthStr::width(s.as_str()),
72
+ Part::Insert(s) => width += UnicodeWidthStr::width(s.as_str()),
73
+ }
74
+ }
75
+ width
76
+ }
77
+ }
78
+ #[pyclass(name = "Part", get_all)]
79
+ #[derive(Clone)]
80
+ struct PyPart {
81
+ value: String,
82
+ kind: String, // EQUAL|DELETE|INSERT
83
+ }
84
+ impl PartialEq for PyPart {
85
+ fn eq(&self, other: &Self) -> bool {
86
+ self.value == other.value && self.kind == other.kind
87
+ }
88
+ }
89
+
90
+ fn diff_lines(a: String, b: String) -> (PartsDiff, PartsDiff) {
91
+ let diff = TextDiff::from_chars(&a, &b);
92
+ let mut x = PartsDiff { parts: Vec::new() };
93
+ let mut y = PartsDiff { parts: Vec::new() };
94
+ for change in diff.iter_all_changes() {
95
+ let value = change.value();
96
+ match change.tag() {
97
+ ChangeTag::Equal => {
98
+ x.push_equal(value);
99
+ y.push_equal(value);
100
+ }
101
+ ChangeTag::Delete => {
102
+ if change.old_index().is_some() {
103
+ x.push_delete(value);
104
+ } else {
105
+ y.push_delete(value)
106
+ }
107
+ }
108
+ ChangeTag::Insert => {
109
+ if change.old_index().is_some() {
110
+ x.push_insert(value);
111
+ } else {
112
+ y.push_insert(value)
113
+ }
114
+ }
115
+ }
116
+ }
117
+ (x, y)
118
+ }
119
+
120
+ fn diff_a_and_b(a: String, b: String, context_lines: Option<usize>) -> Vec<LinePartsDiff> {
121
+ let diff = TextDiff::from_lines(&a, &b);
122
+ let mut unified = diff.unified_diff();
123
+ unified.context_radius(context_lines.unwrap_or(1000)); // We default to just a large number
124
+
125
+ let mut diffs: Vec<LineDiff> = Vec::new();
126
+
127
+ let mut append: bool = false;
128
+ for hunk in unified.iter_hunks() {
129
+ for change in hunk.iter_changes() {
130
+ let value = String::from(change.value().trim_end_matches('\n'));
131
+ match change.tag() {
132
+ ChangeTag::Equal => {
133
+ let diff = LineDiff {
134
+ left_lineno: change.old_index().unwrap() as i64 + 1,
135
+ left: value.clone(),
136
+ right_lineno: change.new_index().unwrap() as i64 + 1,
137
+ right: value.clone(),
138
+ };
139
+ diffs.push(diff);
140
+ append = false;
141
+ }
142
+ _ => {
143
+ if append {
144
+ let last = diffs.len() - 1;
145
+ if change.old_index().is_some() {
146
+ diffs[last].left_lineno = change.old_index().unwrap() as i64 + 1;
147
+ diffs[last].left = value.clone();
148
+ } else {
149
+ diffs[last].right_lineno = change.new_index().unwrap() as i64 + 1;
150
+ diffs[last].right = value.clone();
151
+ }
152
+ append = false;
153
+ } else {
154
+ if change.old_index().is_some() {
155
+ let diff = LineDiff {
156
+ left_lineno: change.old_index().unwrap() as i64 + 1,
157
+ left: value.clone(),
158
+ right_lineno: -1,
159
+ right: String::from(""),
160
+ };
161
+ diffs.push(diff);
162
+ } else {
163
+ let diff = LineDiff {
164
+ left_lineno: -1,
165
+ left: String::from(""),
166
+ right_lineno: change.new_index().unwrap() as i64 + 1,
167
+ right: value.clone(),
168
+ };
169
+ diffs.push(diff);
170
+ }
171
+ append = true;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ fn f(diff: &LineDiff) -> LinePartsDiff {
178
+ let (x, y) = diff_lines(diff.left.clone(), diff.right.clone());
179
+ LinePartsDiff {
180
+ left_lineno: diff.left_lineno,
181
+ left: x,
182
+ right_lineno: diff.right_lineno,
183
+ right: y,
184
+ }
185
+ }
186
+ diffs.iter().map(f).collect()
187
+ }
188
+
189
+ fn generate_html(diff: Vec<LinePartsDiff>, column_limit: usize) -> String {
190
+ let mut html = String::new();
191
+ let mut left = String::new();
192
+ let mut right = String::new();
193
+ html.push_str("<div>");
194
+ html.push_str("<style>");
195
+ html.push_str(".ocdiff-container { display: flex; background-color: #141414; color: white; }");
196
+ html.push_str(".ocdiff-side { width: 50%; overflow-x: scroll; margin: 0; padding: 1rem; }");
197
+ html.push_str(".ocdiff-delete { font-weight: bolder; color: red; }");
198
+ html.push_str(".ocdiff-insert { font-weight: bolder; color: green; }");
199
+ html.push_str("</style>");
200
+ html.push_str("<div class=\"ocdiff-container\">");
201
+
202
+ for line_diff in diff {
203
+ let _max_width = line_diff.left.width().max(line_diff.right.width());
204
+ let _number_of_lines = (_max_width + (column_limit - 1)) / column_limit;
205
+
206
+ left.push_str(generate_html_parts(&line_diff.left.parts).as_str());
207
+ left.push_str("\n");
208
+ right.push_str(generate_html_parts(&line_diff.right.parts).as_str());
209
+ right.push_str("\n");
210
+ }
211
+
212
+ html.push_str("<pre class=\"ocdiff-side\">");
213
+ html.push_str(left.as_str());
214
+ html.push_str("</pre>");
215
+ html.push_str("<pre class=\"ocdiff-side\">");
216
+ html.push_str(right.as_str());
217
+ html.push_str("</pre>");
218
+
219
+ html.push_str("</div>");
220
+ html.push_str("</div>");
221
+ html
222
+ }
223
+
224
+ fn generate_html_parts(parts: &Vec<Part>) -> String {
225
+ let mut html = String::new();
226
+
227
+ for part in parts {
228
+ match part {
229
+ Part::Equal(text) => {
230
+ let escaped_text = encode_text(text);
231
+ html.push_str(&format!(
232
+ "<span class=\"ocdiff-line ocdiff-equal\">{}</span>",
233
+ escaped_text
234
+ ));
235
+ }
236
+ Part::Delete(text) => {
237
+ let escaped_text = encode_text(text);
238
+ html.push_str(&format!(
239
+ "<span class=\"ocdiff-line ocdiff-delete\">{}</span>",
240
+ escaped_text
241
+ ));
242
+ }
243
+ Part::Insert(text) => {
244
+ let escaped_text = encode_text(text);
245
+ html.push_str(&format!(
246
+ "<span class=\"ocdiff-line ocdiff-insert\">{}</span>",
247
+ escaped_text
248
+ ));
249
+ }
250
+ }
251
+ }
252
+ html
253
+ }
254
+
255
+ #[pymodule]
256
+ #[pyo3(name = "ocdiff")]
257
+ fn init_mod(_py: Python, m: &PyModule) -> PyResult<()> {
258
+ #[pyfn(m)]
259
+ #[pyo3(name = "html_diff")]
260
+ fn html_diff<'a>(
261
+ _py: Python<'a>,
262
+ a: String,
263
+ b: String,
264
+ context_lines: Option<usize>,
265
+ column_limit: Option<usize>,
266
+ ) -> PyResult<String> {
267
+ let line_parts_diffs = diff_a_and_b(a, b, context_lines);
268
+ let html = generate_html(line_parts_diffs, column_limit.unwrap_or(80));
269
+ Ok(html)
270
+ }
271
+
272
+ Ok(())
273
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "glossary": {
3
+ "title": "example glossary",
4
+ "GlossDiv": {
5
+ "title": "S",
6
+ "GlossList": {
7
+ "GlossEntry": {
8
+ "ID": "SGML",
9
+ "SortAs": "SGML",
10
+ "GlossTerm": "Standard Generalized Markup Language",
11
+ "Acronym": "SGML",
12
+ "Abbrev": "ISO 8879:1986",
13
+ "GlossDef": {
14
+ "para": "A meta-markup language, used to create markup languages such as DocBook.",
15
+ "GlossSeeAlso": [
16
+ "GML",
17
+ "XML"
18
+ ]
19
+ },
20
+ "GlossSee": "markup"
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "glossary": {
3
+ "title": "example glossary",
4
+ "GlossDiv": {
5
+ "GlossList": {
6
+ "GlossEntryyyyy": {
7
+ "ID": "SGML",
8
+ "SortAs": "SGML",
9
+ "GlossTerm": "Standard Generalized Markup Language",
10
+ "Acronym": "SGML",
11
+ "Abbrev": "ISO 8879:1986",
12
+ "GlossDef": {
13
+ "para": "A to create markup languages such as DocBook.",
14
+ "GlossSeeAlso": [
15
+ "XML"
16
+ ]
17
+ },
18
+ "GlossSee": "markup",
19
+ "Hullo": 42
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,53 @@
1
+ <div><style>.ocdiff-container { display: flex; background-color: #141414; color: white; }.ocdiff-side { width: 50%; overflow-x: scroll; margin: 0; padding: 1rem; }.ocdiff-delete { font-weight: bolder; color: red; }.ocdiff-insert { font-weight: bolder; color: green; }</style><div class="ocdiff-container"><pre class="ocdiff-side"><span class="ocdiff-line ocdiff-equal">{</span>
2
+ <span class="ocdiff-line ocdiff-equal"> "glossary": {</span>
3
+ <span class="ocdiff-line ocdiff-equal"> "title": "example glossary",</span>
4
+ <span class="ocdiff-line ocdiff-equal"> "GlossDiv": {</span>
5
+ <span class="ocdiff-line ocdiff-delete"> "title": "S",</span>
6
+ <span class="ocdiff-line ocdiff-equal"> "GlossList": {</span>
7
+ <span class="ocdiff-line ocdiff-equal"> "GlossEntry": {</span>
8
+ <span class="ocdiff-line ocdiff-equal"> "ID": "SGML",</span>
9
+ <span class="ocdiff-line ocdiff-equal"> "SortAs": "SGML",</span>
10
+ <span class="ocdiff-line ocdiff-equal"> "GlossTerm": "Standard Generalized Markup Language",</span>
11
+ <span class="ocdiff-line ocdiff-equal"> "Acronym": "SGML",</span>
12
+ <span class="ocdiff-line ocdiff-equal"> "Abbrev": "ISO 8879:1986",</span>
13
+ <span class="ocdiff-line ocdiff-equal"> "GlossDef": {</span>
14
+ <span class="ocdiff-line ocdiff-equal"> "para": "A </span><span class="ocdiff-line ocdiff-delete">meta-markup language, used </span><span class="ocdiff-line ocdiff-equal">to create markup languages such as DocBook.",</span>
15
+ <span class="ocdiff-line ocdiff-equal"> "GlossSeeAlso": [</span>
16
+ <span class="ocdiff-line ocdiff-delete"> "GML",</span>
17
+ <span class="ocdiff-line ocdiff-equal"> "XML"</span>
18
+ <span class="ocdiff-line ocdiff-equal"> ]</span>
19
+ <span class="ocdiff-line ocdiff-equal"> },</span>
20
+ <span class="ocdiff-line ocdiff-equal"> "GlossSee": "markup"</span>
21
+
22
+ <span class="ocdiff-line ocdiff-equal"> }</span>
23
+ <span class="ocdiff-line ocdiff-equal"> }</span>
24
+ <span class="ocdiff-line ocdiff-equal"> }</span>
25
+ <span class="ocdiff-line ocdiff-equal"> }</span>
26
+ <span class="ocdiff-line ocdiff-equal">}</span>
27
+ </pre><pre class="ocdiff-side"><span class="ocdiff-line ocdiff-equal">{</span>
28
+ <span class="ocdiff-line ocdiff-equal"> "glossary": {</span>
29
+ <span class="ocdiff-line ocdiff-equal"> "title": "example glossary",</span>
30
+ <span class="ocdiff-line ocdiff-equal"> "GlossDiv": {</span>
31
+
32
+ <span class="ocdiff-line ocdiff-equal"> "GlossList": {</span>
33
+ <span class="ocdiff-line ocdiff-equal"> "GlossEntry</span><span class="ocdiff-line ocdiff-insert">yyyy</span><span class="ocdiff-line ocdiff-equal">": {</span>
34
+ <span class="ocdiff-line ocdiff-equal"> "ID": "SGML",</span>
35
+ <span class="ocdiff-line ocdiff-equal"> "SortAs": "SGML",</span>
36
+ <span class="ocdiff-line ocdiff-equal"> "GlossTerm": "Standard Generalized Markup Language",</span>
37
+ <span class="ocdiff-line ocdiff-equal"> "Acronym": "SGML",</span>
38
+ <span class="ocdiff-line ocdiff-equal"> "Abbrev": "ISO 8879:1986",</span>
39
+ <span class="ocdiff-line ocdiff-equal"> "GlossDef": {</span>
40
+ <span class="ocdiff-line ocdiff-equal"> "para": "A to create markup languages such as DocBook.",</span>
41
+ <span class="ocdiff-line ocdiff-equal"> "GlossSeeAlso": [</span>
42
+
43
+ <span class="ocdiff-line ocdiff-equal"> "XML"</span>
44
+ <span class="ocdiff-line ocdiff-equal"> ]</span>
45
+ <span class="ocdiff-line ocdiff-equal"> },</span>
46
+ <span class="ocdiff-line ocdiff-equal"> "GlossSee": "markup"</span><span class="ocdiff-line ocdiff-insert">,</span>
47
+ <span class="ocdiff-line ocdiff-insert"> "Hullo": 42</span>
48
+ <span class="ocdiff-line ocdiff-equal"> }</span>
49
+ <span class="ocdiff-line ocdiff-equal"> }</span>
50
+ <span class="ocdiff-line ocdiff-equal"> }</span>
51
+ <span class="ocdiff-line ocdiff-equal"> }</span>
52
+ <span class="ocdiff-line ocdiff-equal">}</span>
53
+ </pre></div></div>
@@ -0,0 +1,13 @@
1
+ from pathlib import Path
2
+ import ocdiff
3
+
4
+
5
+ def test_html_diff() -> None:
6
+ actual = ocdiff.html_diff(
7
+ (Path(__file__).parent / "a.json").read_text(),
8
+ (Path(__file__).parent / "b.json").read_text(),
9
+ context_lines=5,
10
+ column_limit=80,
11
+ )
12
+ expected = (Path(__file__).parent / "expected.html").read_text()
13
+ assert actual == expected