exhash 0.2.3__tar.gz → 0.2.4__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.
@@ -25,7 +25,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
25
25
 
26
26
  [[package]]
27
27
  name = "exhash"
28
- version = "0.2.3"
28
+ version = "0.2.4"
29
29
  dependencies = [
30
30
  "pyo3",
31
31
  "regex",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "exhash"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  edition = "2021"
5
5
  license = "MIT OR Apache-2.0"
6
6
  description = "Verified line-addressed file editor using lnhash addresses"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exhash
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Summary: Verified line-addressed file editor using lnhash addresses
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "exhash"
7
- version = "0.2.3"
7
+ version = "0.2.4"
8
8
  description = "Verified line-addressed file editor using lnhash addresses"
9
9
  license = {text = "MIT OR Apache-2.0"}
10
10
  requires-python = ">=3.10"
@@ -1,3 +1,4 @@
1
+ from pathlib import Path
1
2
  from .exhash import line_hash as _line_hash, lnhash as _lnhash, lnhashview as _lnhashview, exhash as _exhash
2
3
 
3
4
  def line_hash(line:str) -> str:
@@ -15,6 +16,11 @@ def lnhashview(text:str) -> list[str]:
15
16
  return _lnhashview(text)
16
17
 
17
18
 
19
+ def lnhashview_file(path:str) -> list[str]:
20
+ 'Return lines formatted as ``lineno|hash| content`` for each line in file at ``path``.'
21
+ return _lnhashview(Path(path).read_text())
22
+
23
+
18
24
  def exhash_result(results:list[dict]) -> str:
19
25
  'Format modified lines from exhash result dicts in lnhash view format.'
20
26
  if not isinstance(results, list): raise TypeError("results must be a list[dict]")
@@ -88,3 +94,11 @@ def exhash(text:str, cmds:list[str], sw:int=4) -> dict:
88
94
  """
89
95
  r = _exhash(text, *cmds, sw=sw)
90
96
  return dict(lines=r.lines, hashes=r.hashes, modified=r.modified, deleted=r.deleted)
97
+
98
+
99
+ def exhash_file(path:str, cmds:list[str], sw:int=4, inplace:bool=False) -> dict:
100
+ 'Like ``exhash`` but reads from file at ``path``. If ``inplace``, writes result back (atomically on success only).'
101
+ text = Path(path).read_text()
102
+ r = exhash(text, cmds, sw=sw)
103
+ if inplace: Path(path).write_text('\n'.join(r['lines']) + '\n' if r['lines'] else '')
104
+ return r
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes