vith 0.16.2__tar.gz → 0.16.3__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.
- {vith-0.16.2 → vith-0.16.3}/PKG-INFO +4 -4
- {vith-0.16.2 → vith-0.16.3}/README.md +3 -3
- {vith-0.16.2 → vith-0.16.3}/pyproject.toml +1 -1
- vith-0.16.3/tests/test_io_backends.py +256 -0
- {vith-0.16.2 → vith-0.16.3}/vith/__init__.py +1 -1
- {vith-0.16.2 → vith-0.16.3}/vith/commands/completer.py +15 -2
- {vith-0.16.2 → vith-0.16.3}/vith/commands/files.py +4 -3
- {vith-0.16.2 → vith-0.16.3}/vith/commands/handler.py +29 -1
- {vith-0.16.2 → vith-0.16.3}/vith/editor.py +6 -6
- {vith-0.16.2 → vith-0.16.3}/vith/editor_buffer.py +7 -6
- vith-0.16.3/vith/io/__init__.py +12 -0
- {vith-0.16.2 → vith-0.16.3}/vith/io/backends.py +25 -3
- {vith-0.16.2 → vith-0.16.3}/vith/rc_file.py +14 -13
- {vith-0.16.2 → vith-0.16.3}/vith/window_arrangement.py +4 -0
- {vith-0.16.2 → vith-0.16.3}/vith.egg-info/PKG-INFO +4 -4
- vith-0.16.2/tests/test_io_backends.py +0 -136
- vith-0.16.2/vith/io/__init__.py +0 -10
- {vith-0.16.2 → vith-0.16.3}/LICENSE +0 -0
- {vith-0.16.2 → vith-0.16.3}/setup.cfg +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_cd.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_cli_and_process.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_cold_text.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_commands_grammar.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_completion.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_editor_buffer.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_editor_title.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_ex_commands.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_filetype.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_filetype_tabstops.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_key_bindings_fixes.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_layout.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_lexer.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_preview.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_quit_and_goto.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_range_commands.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_read_command.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_render.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_reporting.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round10_perf.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round11_bugs.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round8_perf.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round8_semantics.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round9_dedup.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round9_perf.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_round9_readability.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_set_ergonomics.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_set_int_options.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_startup_io.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_style.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_substitute.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_thai.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_thai_motions.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_thai_tabs_motion.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_toml_config.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_window_arrangements.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/tests/test_write_commands.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/__main__.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/cold_text.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/__init__.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/buffers.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/common.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/editing.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/global_cmd.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/grammar.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/info.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/lexer.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/normal.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/options.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/preview.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/ranges.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/registry.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/render.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/substitution.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/commands/tabs.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/completion.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/entry_points/__init__.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/entry_points/run_vith.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/help.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/io/base.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/key_bindings.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/layout.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/lexer.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/process.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/render.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/reporting.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/style.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/thai/__init__.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/thai/classify.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/thai/clusters.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/thai/patches.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/thai/words.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith/welcome_message.py +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith.egg-info/SOURCES.txt +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith.egg-info/dependency_links.txt +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith.egg-info/entry_points.txt +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith.egg-info/requires.txt +0 -0
- {vith-0.16.2 → vith-0.16.3}/vith.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vith
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.3
|
|
4
4
|
Summary: Vith — a pure-Python Vi clone with Thai & Lao script support (fork of pyvim)
|
|
5
5
|
Author-email: Chaiwat Suttipongsakul <cwt@bashell.com>
|
|
6
6
|
Maintainer-email: Chaiwat Suttipongsakul <cwt@bashell.com>
|
|
@@ -68,7 +68,7 @@ This fork runs on **Python 3.10+** (`prompt_toolkit` 3.0) and adds four major, m
|
|
|
68
68
|
- **Ex command completeness & `:set` parity**: full Vim Ex command set across files (`:r`/`:read` incl. `:r !cmd`, `:sav`, `:up`, `:x`, `:wa`, `:xa`, `:so`, `:f`, `:enew`), buffers/windows/tabs (`:ls`, `:b #`, `:bf`/`:bl`, `:sb`, `:bd <target>`, `:clo`, `:on`, `:tabo`/`:tabm`/`:tabs`), generalized range editing (`:$`/`±N`, `:d`, `:y`, `:pu`, `:m`, `:t`/`:co`, `:j`, `:sort`, `:retab`, `:g`/`:v`, `:[range]!cmd`, `:[range]w` partial/append/pipe, `:[range]norm[!]`), `%`/`#` filename expansion with `:p`/`:h`/`:t`/`:r`/`:e`, in-editor read-only info splits (`:ver`, `:mes`, `:reg`, `:marks`, `:set`), and ergonomic `:set` syntax (`?`, `!`, `inv`, multi-arg, `smartcase`, `shiftwidth`, `readonly`, `autoindent`, `fileencoding`, `fileformat`). See [`docs/command_completeness_plan.md`](docs/command_completeness_plan.md).
|
|
69
69
|
- **Live async `:render` split preview**: real-time non-blocking split preview (`:render`, `:render-split-v`, `:render-split-h`) powered by optional `vith[render]` (`rich` + `rich-rst`), with direct `Segment` → `StyleAndTextTuples` bridging, debounced executor rendering, stale-edit fallback, heading/landmark-anchored scroll sync, and pluggable `[render.commands]` CLI renderers. See [`docs/live_render.md`](docs/live_render.md).
|
|
70
70
|
|
|
71
|
-
All changes are audited in [`docs/bugs/`](docs/bugs/) (
|
|
71
|
+
All changes are audited in [`docs/bugs/`](docs/bugs/) (194 machine-verified findings across 14 audit rounds and 4 addenda — 193 fixed, 1 archived/withdrawn); quality is enforced with pytest (562 tests), mypy and ruff.
|
|
72
72
|
|
|
73
73
|
Issues, questions, wishes, comments, feedback, remarks? Please create a GitHub issue, I appreciate it.
|
|
74
74
|
|
|
@@ -183,7 +183,7 @@ To run all tests, install the optional and development dependencies (pytest, pyt
|
|
|
183
183
|
pip install -e ".[jedi,lzo,render,dev]"
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
Run unit tests via the test runner script (executes all
|
|
186
|
+
Run unit tests via the test runner script (executes all 562 tests in parallel and enforces ≥85% test coverage):
|
|
187
187
|
|
|
188
188
|
```sh
|
|
189
189
|
bash scripts/runtest.sh
|
|
@@ -197,7 +197,7 @@ python -m pytest tests
|
|
|
197
197
|
|
|
198
198
|
Developer helper scripts are provided in `scripts/`:
|
|
199
199
|
|
|
200
|
-
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (
|
|
200
|
+
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (562 tests)
|
|
201
201
|
- `scripts/type-check.sh`: run `mypy .` (typing, 88 source files checked against the 3.10 floor)
|
|
202
202
|
- `scripts/lint-check-and-fix.sh`: run `ruff check --fix .` (linting)
|
|
203
203
|
- `scripts/code-format.sh`: run `ruff format` (formatting)
|
|
@@ -25,7 +25,7 @@ This fork runs on **Python 3.10+** (`prompt_toolkit` 3.0) and adds four major, m
|
|
|
25
25
|
- **Ex command completeness & `:set` parity**: full Vim Ex command set across files (`:r`/`:read` incl. `:r !cmd`, `:sav`, `:up`, `:x`, `:wa`, `:xa`, `:so`, `:f`, `:enew`), buffers/windows/tabs (`:ls`, `:b #`, `:bf`/`:bl`, `:sb`, `:bd <target>`, `:clo`, `:on`, `:tabo`/`:tabm`/`:tabs`), generalized range editing (`:$`/`±N`, `:d`, `:y`, `:pu`, `:m`, `:t`/`:co`, `:j`, `:sort`, `:retab`, `:g`/`:v`, `:[range]!cmd`, `:[range]w` partial/append/pipe, `:[range]norm[!]`), `%`/`#` filename expansion with `:p`/`:h`/`:t`/`:r`/`:e`, in-editor read-only info splits (`:ver`, `:mes`, `:reg`, `:marks`, `:set`), and ergonomic `:set` syntax (`?`, `!`, `inv`, multi-arg, `smartcase`, `shiftwidth`, `readonly`, `autoindent`, `fileencoding`, `fileformat`). See [`docs/command_completeness_plan.md`](docs/command_completeness_plan.md).
|
|
26
26
|
- **Live async `:render` split preview**: real-time non-blocking split preview (`:render`, `:render-split-v`, `:render-split-h`) powered by optional `vith[render]` (`rich` + `rich-rst`), with direct `Segment` → `StyleAndTextTuples` bridging, debounced executor rendering, stale-edit fallback, heading/landmark-anchored scroll sync, and pluggable `[render.commands]` CLI renderers. See [`docs/live_render.md`](docs/live_render.md).
|
|
27
27
|
|
|
28
|
-
All changes are audited in [`docs/bugs/`](docs/bugs/) (
|
|
28
|
+
All changes are audited in [`docs/bugs/`](docs/bugs/) (194 machine-verified findings across 14 audit rounds and 4 addenda — 193 fixed, 1 archived/withdrawn); quality is enforced with pytest (562 tests), mypy and ruff.
|
|
29
29
|
|
|
30
30
|
Issues, questions, wishes, comments, feedback, remarks? Please create a GitHub issue, I appreciate it.
|
|
31
31
|
|
|
@@ -140,7 +140,7 @@ To run all tests, install the optional and development dependencies (pytest, pyt
|
|
|
140
140
|
pip install -e ".[jedi,lzo,render,dev]"
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
Run unit tests via the test runner script (executes all
|
|
143
|
+
Run unit tests via the test runner script (executes all 562 tests in parallel and enforces ≥85% test coverage):
|
|
144
144
|
|
|
145
145
|
```sh
|
|
146
146
|
bash scripts/runtest.sh
|
|
@@ -154,7 +154,7 @@ python -m pytest tests
|
|
|
154
154
|
|
|
155
155
|
Developer helper scripts are provided in `scripts/`:
|
|
156
156
|
|
|
157
|
-
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (
|
|
157
|
+
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (562 tests)
|
|
158
158
|
- `scripts/type-check.sh`: run `mypy .` (typing, 88 source files checked against the 3.10 floor)
|
|
159
159
|
- `scripts/lint-check-and-fix.sh`: run `ruff check --fix .` (linting)
|
|
160
160
|
- `scripts/code-format.sh`: run `ruff format` (formatting)
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for `vith/io/backends.py` (P5: `codecs.open` deprecation removal,
|
|
3
|
+
`FileIO`/`GZipFileIO` behaviour).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import io
|
|
7
|
+
import warnings
|
|
8
|
+
|
|
9
|
+
from vith.io.backends import FileIO, GZipFileIO
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_fileio_write_read_utf8_roundtrip(tmp_path):
|
|
13
|
+
f = FileIO()
|
|
14
|
+
p = str(tmp_path / 'file.txt')
|
|
15
|
+
|
|
16
|
+
f.write(p, 'héllo wörld', 'utf-8')
|
|
17
|
+
text, encoding = f.read(p)
|
|
18
|
+
|
|
19
|
+
assert text == 'héllo wörld'
|
|
20
|
+
assert encoding == 'utf-8'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_fileio_latin1_fallback(tmp_path):
|
|
24
|
+
p = tmp_path / 'latin1.txt'
|
|
25
|
+
# A byte that is not valid UTF-8: falls back to latin-1 (which accepts
|
|
26
|
+
# any byte sequence).
|
|
27
|
+
p.write_bytes(b'caf\xe9')
|
|
28
|
+
|
|
29
|
+
text, encoding = FileIO().read(str(p))
|
|
30
|
+
|
|
31
|
+
assert text == 'café'
|
|
32
|
+
assert encoding == 'latin-1'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_fileio_no_deprecation_warning(tmp_path):
|
|
36
|
+
# P5: `codecs.open` is deprecated in Python 3.14+; the C-buffered
|
|
37
|
+
# `io.open` must be used instead, so no DeprecationWarning may be
|
|
38
|
+
# emitted while reading or writing.
|
|
39
|
+
p = str(tmp_path / 'deprecation.txt')
|
|
40
|
+
f = FileIO()
|
|
41
|
+
|
|
42
|
+
with warnings.catch_warnings(record=True) as caught:
|
|
43
|
+
warnings.simplefilter('always')
|
|
44
|
+
f.write(p, 'plain text', 'utf-8')
|
|
45
|
+
f.read(p)
|
|
46
|
+
|
|
47
|
+
deprecations = [w for w in caught if issubclass(w.category, DeprecationWarning)]
|
|
48
|
+
assert deprecations == [], (
|
|
49
|
+
'FileIO read/write must not emit DeprecationWarnings: %r' % deprecations
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_fileio_uses_io_open(tmp_path, monkeypatch):
|
|
54
|
+
# Explicitly: reads/writes go through `io.open`, not `codecs.open`.
|
|
55
|
+
p = str(tmp_path / 'tracked.txt')
|
|
56
|
+
f = FileIO()
|
|
57
|
+
|
|
58
|
+
calls = []
|
|
59
|
+
original = io.open
|
|
60
|
+
|
|
61
|
+
def tracking_open(*args, **kwargs):
|
|
62
|
+
calls.append((args, kwargs))
|
|
63
|
+
return original(*args, **kwargs)
|
|
64
|
+
|
|
65
|
+
monkeypatch.setattr('vith.io.backends.io.open', tracking_open)
|
|
66
|
+
|
|
67
|
+
f.write(p, 'data', 'utf-8')
|
|
68
|
+
assert f.read(p) == ('data', 'utf-8')
|
|
69
|
+
|
|
70
|
+
assert [args[1] for args, _kw in calls] == ['w']
|
|
71
|
+
assert [kw.get('encoding') for _args, kw in calls] == ['utf-8']
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_gzip_roundtrip(tmp_path):
|
|
75
|
+
p = str(tmp_path / 'data.txt.gz')
|
|
76
|
+
g = GZipFileIO()
|
|
77
|
+
|
|
78
|
+
g.write(p, 'compressed content', 'utf-8')
|
|
79
|
+
text, encoding = g.read(p)
|
|
80
|
+
|
|
81
|
+
assert text == 'compressed content'
|
|
82
|
+
assert encoding == 'utf-8'
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_gzip_can_open_location():
|
|
86
|
+
g = GZipFileIO()
|
|
87
|
+
assert g.can_open_location('/tmp/some-file.txt.gz') is True
|
|
88
|
+
assert g.can_open_location('/tmp/some-file.txt') is False
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_directory_io_handles_tilde(editor):
|
|
92
|
+
editor.load_initial_files(['~'])
|
|
93
|
+
eb = editor.window_arrangement.active_editor_buffer
|
|
94
|
+
assert eb.in_file_explorer_mode is True
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_gzip_can_open_location_expands_tilde(monkeypatch, tmp_path):
|
|
98
|
+
# 113 item 6: `GZipFileIO.can_open_location` delegates to `super()` and
|
|
99
|
+
# `_expand_location` consistently for `~/` paths.
|
|
100
|
+
monkeypatch.setenv('HOME', str(tmp_path))
|
|
101
|
+
gz_dir = tmp_path / 'dir.gz'
|
|
102
|
+
gz_dir.mkdir()
|
|
103
|
+
|
|
104
|
+
g = GZipFileIO()
|
|
105
|
+
assert g.can_open_location('~/archive.txt.gz') is True
|
|
106
|
+
assert g.can_open_location('~/dir.gz') is False
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_auto_decode_primary_and_fallback_encodings():
|
|
110
|
+
# 115 item 6: `_auto_decode` tries `PRIMARY_ENCODING` ('utf-8') then
|
|
111
|
+
# falls back to `FALLBACK_ENCODING` ('latin-1').
|
|
112
|
+
from vith.io.backends import ENCODINGS, FALLBACK_ENCODING, PRIMARY_ENCODING, _auto_decode
|
|
113
|
+
|
|
114
|
+
assert ENCODINGS == (PRIMARY_ENCODING, FALLBACK_ENCODING) == ('utf-8', 'latin-1')
|
|
115
|
+
assert _auto_decode('สวัสดี'.encode('utf-8')) == ('สวัสดี', 'utf-8')
|
|
116
|
+
assert _auto_decode(b'\xff\xfe') == ('\xff\xfe', 'latin-1')
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_directory_io_unreadable_raises_oserror(editor, tmp_path, monkeypatch):
|
|
120
|
+
# 110 item 8: `DirectoryIO.read` propagates `OSError` to `EditorBuffer._read`,
|
|
121
|
+
# which surfaces an error message in the editor instead of crashing.
|
|
122
|
+
import os
|
|
123
|
+
|
|
124
|
+
from vith.editor_buffer import EditorBuffer
|
|
125
|
+
|
|
126
|
+
target_dir = tmp_path / 'restricted'
|
|
127
|
+
target_dir.mkdir()
|
|
128
|
+
|
|
129
|
+
def failing_scandir(_path):
|
|
130
|
+
raise PermissionError('Permission denied')
|
|
131
|
+
|
|
132
|
+
monkeypatch.setattr(os, 'scandir', failing_scandir)
|
|
133
|
+
editor.message = None
|
|
134
|
+
eb = EditorBuffer(editor, str(target_dir))
|
|
135
|
+
assert eb.in_file_explorer_mode is True
|
|
136
|
+
assert editor.message is not None and 'Permission denied' in editor.message
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_expand_env_vars_and_location_preserve_urls(monkeypatch, tmp_path):
|
|
140
|
+
import os
|
|
141
|
+
|
|
142
|
+
from vith.io.backends import expand_env_vars, expand_location
|
|
143
|
+
|
|
144
|
+
monkeypatch.setenv('VITH_TEST_ROOT', str(tmp_path))
|
|
145
|
+
|
|
146
|
+
# `$VAR` and `${VAR}` expand on every platform.
|
|
147
|
+
expected = os.path.join(str(tmp_path), 'alacritty.toml')
|
|
148
|
+
assert expand_env_vars(os.path.join('$VITH_TEST_ROOT', 'alacritty.toml')) == expected
|
|
149
|
+
assert expand_env_vars(os.path.join('${VITH_TEST_ROOT}', 'alacritty.toml')) == expected
|
|
150
|
+
assert expand_location(os.path.join('$VITH_TEST_ROOT', 'alacritty.toml')) == expected
|
|
151
|
+
|
|
152
|
+
# URLs must never undergo env-var or tilde expansion.
|
|
153
|
+
assert expand_env_vars('https://example.com/$VITH_TEST_ROOT') == (
|
|
154
|
+
'https://example.com/$VITH_TEST_ROOT'
|
|
155
|
+
)
|
|
156
|
+
assert expand_location('http://example.com/%VITH_TEST_ROOT%/a') == (
|
|
157
|
+
'http://example.com/%VITH_TEST_ROOT%/a'
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# On Windows, `%VAR%` (case-insensitive) expands too.
|
|
161
|
+
if os.name == 'nt':
|
|
162
|
+
assert expand_env_vars(r'%VITH_TEST_ROOT%\alacritty.toml') == expected
|
|
163
|
+
assert expand_env_vars(r'%vith_test_root%\alacritty.toml') == expected
|
|
164
|
+
assert expand_location(r'%VITH_TEST_ROOT%\alacritty.toml') == expected
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_load_initial_files_and_ex_commands_expand_env_vars(editor, tmp_path, monkeypatch):
|
|
168
|
+
import os
|
|
169
|
+
|
|
170
|
+
from prompt_toolkit.completion import CompleteEvent
|
|
171
|
+
from prompt_toolkit.document import Document
|
|
172
|
+
|
|
173
|
+
from vith.commands.completer import create_command_completer
|
|
174
|
+
from vith.commands.handler import expand_command_filenames, handle_command
|
|
175
|
+
from vith.rc_file import run_rc_file
|
|
176
|
+
|
|
177
|
+
sub = tmp_path / 'alacritty'
|
|
178
|
+
sub.mkdir()
|
|
179
|
+
cfg = sub / 'alacritty.toml'
|
|
180
|
+
cfg.write_bytes(b'size = 14.0\n')
|
|
181
|
+
|
|
182
|
+
rc = tmp_path / 'vith.toml'
|
|
183
|
+
rc.write_bytes(b'tabstop = 4\n')
|
|
184
|
+
|
|
185
|
+
monkeypatch.setenv('VITH_TEST_APPDATA', str(tmp_path))
|
|
186
|
+
|
|
187
|
+
path_expr = (
|
|
188
|
+
r'%VITH_TEST_APPDATA%\alacritty\alacritty.toml'
|
|
189
|
+
if os.name == 'nt'
|
|
190
|
+
else '$VITH_TEST_APPDATA/alacritty/alacritty.toml'
|
|
191
|
+
)
|
|
192
|
+
rc_expr = (
|
|
193
|
+
r'%VITH_TEST_APPDATA%\vith.toml' if os.name == 'nt' else '$VITH_TEST_APPDATA/vith.toml'
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# 1. CLI `load_initial_files` opens the real file and stores the expanded path.
|
|
197
|
+
editor.load_initial_files([path_expr])
|
|
198
|
+
eb = editor.window_arrangement.active_editor_buffer
|
|
199
|
+
assert eb is not None
|
|
200
|
+
assert eb.is_new is False
|
|
201
|
+
assert eb.location == str(cfg)
|
|
202
|
+
assert eb.buffer.text == 'size = 14.0'
|
|
203
|
+
|
|
204
|
+
# Opening the expanded path again reuses the existing buffer (no duplicate).
|
|
205
|
+
editor.window_arrangement.open_buffer(str(cfg), show_in_current_window=True)
|
|
206
|
+
assert len(editor.window_arrangement.editor_buffers) == 1
|
|
207
|
+
|
|
208
|
+
# 2. Ex `:e` expands env vars without triggering `%` E499 or corrupting `%VAR%`.
|
|
209
|
+
editor.window_arrangement.open_buffer(None, show_in_current_window=True)
|
|
210
|
+
handle_command(editor, f'e {path_expr}')
|
|
211
|
+
active = editor.window_arrangement.active_editor_buffer
|
|
212
|
+
assert active is not None
|
|
213
|
+
assert active.location == str(cfg)
|
|
214
|
+
assert active.buffer.text == 'size = 14.0'
|
|
215
|
+
|
|
216
|
+
# 3. `:w` overwrite guard and `:cd` honor env-var paths.
|
|
217
|
+
out_expr = r'%VITH_TEST_APPDATA%\out.txt' if os.name == 'nt' else '$VITH_TEST_APPDATA/out.txt'
|
|
218
|
+
handle_command(editor, f'w {out_expr}')
|
|
219
|
+
assert (tmp_path / 'out.txt').read_text(encoding='utf-8') == 'size = 14.0\n'
|
|
220
|
+
editor.message = None
|
|
221
|
+
handle_command(editor, f'w {out_expr}')
|
|
222
|
+
assert editor.message == 'File exists (add ! to override)'
|
|
223
|
+
|
|
224
|
+
orig_cwd = os.getcwd()
|
|
225
|
+
try:
|
|
226
|
+
dir_expr = (
|
|
227
|
+
r'%VITH_TEST_APPDATA%\alacritty' if os.name == 'nt' else '$VITH_TEST_APPDATA/alacritty'
|
|
228
|
+
)
|
|
229
|
+
handle_command(editor, f'cd {dir_expr}')
|
|
230
|
+
assert os.path.realpath(os.getcwd()) == os.path.realpath(str(sub))
|
|
231
|
+
finally:
|
|
232
|
+
os.chdir(orig_cwd)
|
|
233
|
+
|
|
234
|
+
# 4. `run_rc_file` (`vith -u` / `:so`) expands env vars.
|
|
235
|
+
assert run_rc_file(editor, rc_expr) is True
|
|
236
|
+
assert editor.tabstop == 4
|
|
237
|
+
|
|
238
|
+
# 5. Path completion completes files inside env-var directories.
|
|
239
|
+
completer = create_command_completer(editor)
|
|
240
|
+
prefix = (
|
|
241
|
+
r'e %VITH_TEST_APPDATA%\alacritty\al'
|
|
242
|
+
if os.name == 'nt'
|
|
243
|
+
else 'e $VITH_TEST_APPDATA/alacritty/al'
|
|
244
|
+
)
|
|
245
|
+
comps = list(completer.get_completions(Document(prefix, len(prefix)), CompleteEvent()))
|
|
246
|
+
assert any(c.display_text == 'alacritty.toml' for c in comps)
|
|
247
|
+
|
|
248
|
+
# 6. On Windows, shell commands preserve `%VAR%` while still expanding trailing `%`.
|
|
249
|
+
if os.name == 'nt':
|
|
250
|
+
cmd_str, err = expand_command_filenames(
|
|
251
|
+
r'echo %VITH_TEST_APPDATA% %', editor, shell_escape=True
|
|
252
|
+
)
|
|
253
|
+
assert err is None
|
|
254
|
+
assert cmd_str is not None
|
|
255
|
+
assert cmd_str.startswith('echo %VITH_TEST_APPDATA% ')
|
|
256
|
+
assert 'alacritty.toml' in cmd_str
|
|
@@ -11,7 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
# In a development checkout (e.g. repo root), read directly from pyproject.toml
|
|
12
12
|
# so editing the version requires touching only pyproject.toml. The fallback
|
|
13
13
|
# is a single constant (docs/bugs/075.md); pyproject.toml remains primary.
|
|
14
|
-
_FALLBACK_VERSION = "0.16.
|
|
14
|
+
_FALLBACK_VERSION = "0.16.3"
|
|
15
15
|
_pyproject = Path(__file__).resolve().parent.parent / "pyproject.toml"
|
|
16
16
|
if _pyproject.is_file():
|
|
17
17
|
_m = re.search(
|
|
@@ -7,6 +7,8 @@ from prompt_toolkit.contrib.completers.system import SystemCompleter
|
|
|
7
7
|
from prompt_toolkit.contrib.regular_languages.completion import GrammarCompleter
|
|
8
8
|
from prompt_toolkit.document import Document
|
|
9
9
|
|
|
10
|
+
from vith.io.backends import expand_env_vars
|
|
11
|
+
|
|
10
12
|
from .grammar import COMMAND_GRAMMAR
|
|
11
13
|
from .options import SET_EXTRA_TOGGLE_ON_NAMES, SET_TOGGLE_GROUPS
|
|
12
14
|
from .registry import SET_COMMANDS, get_commands
|
|
@@ -178,6 +180,17 @@ class CommandCompleter(Completer):
|
|
|
178
180
|
yield from self.inner.get_completions(document, complete_event)
|
|
179
181
|
|
|
180
182
|
|
|
183
|
+
class _EnvPathCompleter(PathCompleter):
|
|
184
|
+
"""`PathCompleter` that also expands environment variables (`$VAR`, `%VAR%`)."""
|
|
185
|
+
|
|
186
|
+
def get_completions(self, document, complete_event):
|
|
187
|
+
raw = document.text_before_cursor
|
|
188
|
+
expanded = expand_env_vars(raw)
|
|
189
|
+
if expanded != raw:
|
|
190
|
+
document = Document(expanded, len(expanded))
|
|
191
|
+
yield from super().get_completions(document, complete_event)
|
|
192
|
+
|
|
193
|
+
|
|
181
194
|
def create_command_completer(editor):
|
|
182
195
|
commands = [c + ' ' for c in get_commands()]
|
|
183
196
|
|
|
@@ -185,8 +198,8 @@ def create_command_completer(editor):
|
|
|
185
198
|
COMMAND_GRAMMAR,
|
|
186
199
|
{
|
|
187
200
|
'command': WordCompleter(commands),
|
|
188
|
-
'location':
|
|
189
|
-
'write_append':
|
|
201
|
+
'location': _EnvPathCompleter(expanduser=True),
|
|
202
|
+
'write_append': _EnvPathCompleter(expanduser=True),
|
|
190
203
|
'set_option': WordCompleter(sorted(SET_COMMANDS)),
|
|
191
204
|
'buffer_name': BufferNameCompleter(editor),
|
|
192
205
|
'colorscheme': ColorSchemeCompleter(editor),
|
|
@@ -10,6 +10,7 @@ import os
|
|
|
10
10
|
from typing import Any
|
|
11
11
|
|
|
12
12
|
from vith.editor_buffer import is_same_write_target
|
|
13
|
+
from vith.io.backends import expand_location
|
|
13
14
|
from vith.io.base import find_backend
|
|
14
15
|
from vith.thai import note_document_text
|
|
15
16
|
|
|
@@ -163,7 +164,7 @@ def file_info(editor: Any, location: str | None) -> None:
|
|
|
163
164
|
if location is not None:
|
|
164
165
|
# `:f {name}` renames the buffer; normalize metadata the same way
|
|
165
166
|
# writes do (docs/bugs/147.md).
|
|
166
|
-
normalized = os.path.abspath(
|
|
167
|
+
normalized = os.path.abspath(expand_location(location))
|
|
167
168
|
eb.location = normalized
|
|
168
169
|
eb.is_new = not os.path.exists(normalized)
|
|
169
170
|
eb.isdir = os.path.isdir(normalized)
|
|
@@ -188,7 +189,7 @@ def _reject_existing_write_target(editor: Any, eb: Any, location: str | None, fo
|
|
|
188
189
|
return False
|
|
189
190
|
if is_same_write_target(eb.location, location):
|
|
190
191
|
return False
|
|
191
|
-
if os.path.exists(
|
|
192
|
+
if os.path.exists(expand_location(location)):
|
|
192
193
|
editor.show_message('File exists (add ! to override)')
|
|
193
194
|
return True
|
|
194
195
|
return False
|
|
@@ -519,7 +520,7 @@ def source_file(editor: Any, location: str | None) -> None:
|
|
|
519
520
|
@location_cmd('cd', accepts_force=False)
|
|
520
521
|
def cd(editor: Any, location: str | None) -> None:
|
|
521
522
|
"""Change working directory."""
|
|
522
|
-
target =
|
|
523
|
+
target = expand_location(location or '~')
|
|
523
524
|
try:
|
|
524
525
|
os.chdir(target)
|
|
525
526
|
except OSError as exc:
|
|
@@ -3,6 +3,8 @@ import os
|
|
|
3
3
|
import shlex
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
|
+
from vith.io.backends import expand_env_vars, expand_location
|
|
7
|
+
|
|
6
8
|
from .files import filter_range_command
|
|
7
9
|
from .grammar import COMMAND_GRAMMAR
|
|
8
10
|
from .ranges import NO_SUCH_LINE_TEXT, resolve_line_address
|
|
@@ -37,7 +39,7 @@ class _ExpandedVariables:
|
|
|
37
39
|
def _apply_filename_modifier(path: str, modifier: str) -> str:
|
|
38
40
|
"""Apply a single Vim filename modifier (`:p`, `:h`, `:t`, `:r`, `:e`)."""
|
|
39
41
|
if modifier == 'p':
|
|
40
|
-
return os.path.abspath(
|
|
42
|
+
return os.path.abspath(expand_location(path))
|
|
41
43
|
if modifier == 'h':
|
|
42
44
|
head = os.path.dirname(path)
|
|
43
45
|
return head if head else '.'
|
|
@@ -50,6 +52,22 @@ def _apply_filename_modifier(path: str, modifier: str) -> str:
|
|
|
50
52
|
return path
|
|
51
53
|
|
|
52
54
|
|
|
55
|
+
def _match_windows_env_var(text: str, start: int) -> tuple[str, int] | None:
|
|
56
|
+
"""
|
|
57
|
+
If `text[start:]` begins with `%VAR%` for a defined Windows environment
|
|
58
|
+
variable, return `(var_name, end_index)` (index after the closing `%`).
|
|
59
|
+
"""
|
|
60
|
+
if os.name != 'nt' or text[start] != '%':
|
|
61
|
+
return None
|
|
62
|
+
end = text.find('%', start + 1)
|
|
63
|
+
if end <= start + 1:
|
|
64
|
+
return None
|
|
65
|
+
var_name = text[start + 1 : end]
|
|
66
|
+
if any(c in var_name for c in '/\\:') or var_name not in os.environ:
|
|
67
|
+
return None
|
|
68
|
+
return var_name, end + 1
|
|
69
|
+
|
|
70
|
+
|
|
53
71
|
def expand_command_filenames(
|
|
54
72
|
text: str, editor: Any, *, shell_escape: bool = False
|
|
55
73
|
) -> tuple[str | None, str | None]:
|
|
@@ -75,6 +93,15 @@ def expand_command_filenames(
|
|
|
75
93
|
i += 2
|
|
76
94
|
continue
|
|
77
95
|
|
|
96
|
+
# On Windows, treat `%VAR%` as an environment variable when `VAR`
|
|
97
|
+
# exists in `os.environ` (e.g. `:e %APPDATA%\alacritty\alacritty.toml`)
|
|
98
|
+
# instead of expanding both `%` delimiters as the current buffer name.
|
|
99
|
+
if (win_env := _match_windows_env_var(text, i)) is not None:
|
|
100
|
+
var_name, next_i = win_env
|
|
101
|
+
out.append(text[i:next_i] if shell_escape else os.environ[var_name])
|
|
102
|
+
i = next_i
|
|
103
|
+
continue
|
|
104
|
+
|
|
78
105
|
if ch in ('%', '#'):
|
|
79
106
|
wa = editor.window_arrangement
|
|
80
107
|
if ch == '%':
|
|
@@ -118,6 +145,7 @@ def _expand_variables(variables: Any, editor: Any) -> tuple[Any, str | None]:
|
|
|
118
145
|
expanded, err = expand_command_filenames(raw, editor, shell_escape=False)
|
|
119
146
|
if err is not None or expanded is None:
|
|
120
147
|
return None, err
|
|
148
|
+
expanded = expand_env_vars(expanded)
|
|
121
149
|
if expanded != raw:
|
|
122
150
|
overrides[key] = expanded
|
|
123
151
|
|
|
@@ -32,7 +32,7 @@ from .commands.options import snapshot_default_options
|
|
|
32
32
|
from .commands.preview import CommandPreviewer
|
|
33
33
|
from .commands.substitution import resolve_ignore_case
|
|
34
34
|
from .help import HELP_TEXT
|
|
35
|
-
from .io import DirectoryIO, FileIO, GZipFileIO, HttpIO
|
|
35
|
+
from .io import DirectoryIO, FileIO, GZipFileIO, HttpIO, expand_location
|
|
36
36
|
from .key_bindings import create_key_bindings
|
|
37
37
|
from .layout import EditorLayout
|
|
38
38
|
from .process import set_process_name
|
|
@@ -248,11 +248,11 @@ class Editor:
|
|
|
248
248
|
self._default_options = snapshot_default_options(self)
|
|
249
249
|
|
|
250
250
|
# Ensure config directory exists (with legacy fallback).
|
|
251
|
-
target_dir = os.path.abspath(
|
|
252
|
-
if
|
|
253
|
-
|
|
254
|
-
)
|
|
255
|
-
legacy_dir = os.path.abspath(
|
|
251
|
+
target_dir = os.path.abspath(expand_location(config_directory))
|
|
252
|
+
if expand_location(config_directory) == expand_location('~/.vith') and not os.path.exists(
|
|
253
|
+
target_dir
|
|
254
|
+
):
|
|
255
|
+
legacy_dir = os.path.abspath(expand_location('~/.pyvim'))
|
|
256
256
|
if os.path.exists(legacy_dir):
|
|
257
257
|
target_dir = legacy_dir
|
|
258
258
|
self.config_directory = target_dir
|
|
@@ -9,6 +9,7 @@ from prompt_toolkit.filters import to_filter
|
|
|
9
9
|
|
|
10
10
|
from vith.cold_text import ColdTextBuffer, make_cold_text_compressor
|
|
11
11
|
from vith.completion import DocumentCompleter
|
|
12
|
+
from vith.io.backends import expand_env_vars, expand_location
|
|
12
13
|
from vith.io.base import find_backend
|
|
13
14
|
from vith.lexer import sniff_filetype_from_text
|
|
14
15
|
from vith.reporting import checks_python_file, report
|
|
@@ -20,12 +21,12 @@ UNTITLED_LABEL = '[New file]'
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def normalize_write_target(location: str | None) -> str | None:
|
|
23
|
-
"""Normalize a write path for same-file comparison (tilde/symlink safe; docs/bugs/152.md)."""
|
|
24
|
+
"""Normalize a write path for same-file comparison (tilde/env/symlink safe; docs/bugs/152.md)."""
|
|
24
25
|
if not location:
|
|
25
26
|
return None
|
|
26
27
|
if '://' in location:
|
|
27
28
|
return location
|
|
28
|
-
return os.path.realpath(os.path.abspath(
|
|
29
|
+
return os.path.realpath(os.path.abspath(expand_location(location)))
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
def is_same_write_target(current_location: str | None, target_location: str | None) -> bool:
|
|
@@ -51,7 +52,7 @@ class EditorBuffer:
|
|
|
51
52
|
assert not (location and text)
|
|
52
53
|
|
|
53
54
|
self._editor_ref = weakref.ref(editor)
|
|
54
|
-
self.location = location
|
|
55
|
+
self.location = expand_env_vars(location) if location is not None else None
|
|
55
56
|
self.encoding = 'utf-8'
|
|
56
57
|
# Pygments lexer alias overriding filename-based detection
|
|
57
58
|
# (`:set filetype=python`). `None` means auto-detect.
|
|
@@ -87,8 +88,8 @@ class EditorBuffer:
|
|
|
87
88
|
|
|
88
89
|
# Read text.
|
|
89
90
|
unreadable = False
|
|
90
|
-
if location:
|
|
91
|
-
text = self._read(location)
|
|
91
|
+
if self.location:
|
|
92
|
+
text = self._read(self.location)
|
|
92
93
|
if text is None:
|
|
93
94
|
# Not a new file: an unknown backend or a read failure.
|
|
94
95
|
# Show a fallback-empty buffer, but keep it read-only so the
|
|
@@ -466,7 +467,7 @@ class EditorBuffer:
|
|
|
466
467
|
Writing an untitled buffer names it and marks it clean.
|
|
467
468
|
"""
|
|
468
469
|
# Resolve the target location without mutating state up front.
|
|
469
|
-
target_location = location if location is not None else self.location
|
|
470
|
+
target_location = expand_env_vars(location) if location is not None else self.location
|
|
470
471
|
if not target_location:
|
|
471
472
|
self.editor.show_message('Unknown location: %r' % location)
|
|
472
473
|
return False
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .backends import DirectoryIO, FileIO, GZipFileIO, HttpIO, expand_env_vars, expand_location
|
|
2
|
+
from .base import EditorIO
|
|
3
|
+
|
|
4
|
+
__all__ = (
|
|
5
|
+
'EditorIO',
|
|
6
|
+
'FileIO',
|
|
7
|
+
'GZipFileIO',
|
|
8
|
+
'DirectoryIO',
|
|
9
|
+
'HttpIO',
|
|
10
|
+
'expand_env_vars',
|
|
11
|
+
'expand_location',
|
|
12
|
+
)
|
|
@@ -10,6 +10,8 @@ __all__ = (
|
|
|
10
10
|
'GZipFileIO',
|
|
11
11
|
'DirectoryIO',
|
|
12
12
|
'HttpIO',
|
|
13
|
+
'expand_env_vars',
|
|
14
|
+
'expand_location',
|
|
13
15
|
)
|
|
14
16
|
|
|
15
17
|
|
|
@@ -22,9 +24,29 @@ FALLBACK_ENCODING = 'latin-1'
|
|
|
22
24
|
ENCODINGS = (PRIMARY_ENCODING, FALLBACK_ENCODING)
|
|
23
25
|
|
|
24
26
|
|
|
25
|
-
def
|
|
26
|
-
"""
|
|
27
|
-
|
|
27
|
+
def expand_env_vars(location: str) -> str:
|
|
28
|
+
"""
|
|
29
|
+
Expand environment variables (`$VAR`, `${VAR}`, and `%VAR%` on Windows)
|
|
30
|
+
for local filesystem paths, leaving URLs (`scheme://...`) untouched.
|
|
31
|
+
"""
|
|
32
|
+
if '://' in location:
|
|
33
|
+
return location
|
|
34
|
+
return os.path.expandvars(location)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def expand_location(location: str) -> str:
|
|
38
|
+
"""
|
|
39
|
+
Expand environment variables (`$VAR`, `${VAR}`, and `%VAR%` on Windows)
|
|
40
|
+
and leading `~` user-home prefixes for local filesystem locations.
|
|
41
|
+
URLs (`scheme://...`) are returned untouched.
|
|
42
|
+
"""
|
|
43
|
+
if '://' in location:
|
|
44
|
+
return location
|
|
45
|
+
return os.path.expanduser(os.path.expandvars(location))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Backward-compatible internal alias.
|
|
49
|
+
_expand_location = expand_location
|
|
28
50
|
|
|
29
51
|
|
|
30
52
|
class FileIO(EditorIO):
|
|
@@ -18,6 +18,7 @@ from .commands import (
|
|
|
18
18
|
press_enter_to_continue,
|
|
19
19
|
)
|
|
20
20
|
from .editor import Editor
|
|
21
|
+
from .io.backends import expand_location
|
|
21
22
|
|
|
22
23
|
if TYPE_CHECKING:
|
|
23
24
|
pass
|
|
@@ -204,15 +205,15 @@ def find_config_file() -> str | None:
|
|
|
204
205
|
"""
|
|
205
206
|
xdg_home = os.environ.get('XDG_CONFIG_HOME')
|
|
206
207
|
if xdg_home:
|
|
207
|
-
xdg_config = os.path.join(
|
|
208
|
+
xdg_config = os.path.join(expand_location(xdg_home), 'vith', 'config.toml')
|
|
208
209
|
else:
|
|
209
|
-
xdg_config =
|
|
210
|
+
xdg_config = expand_location('~/.config/vith/config.toml')
|
|
210
211
|
|
|
211
212
|
candidates = [
|
|
212
213
|
xdg_config,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
expand_location('~/.vith/config.toml'),
|
|
215
|
+
expand_location('~/.vithrc'),
|
|
216
|
+
expand_location('~/.pyvimrc'),
|
|
216
217
|
]
|
|
217
218
|
for path in candidates:
|
|
218
219
|
if os.path.exists(path):
|
|
@@ -233,7 +234,7 @@ def _resolve_hook_path(
|
|
|
233
234
|
4. ~/.config/vith/hooks/<name>
|
|
234
235
|
5. ~/.vith/hooks/<name>
|
|
235
236
|
"""
|
|
236
|
-
expanded =
|
|
237
|
+
expanded = expand_location(hook_name)
|
|
237
238
|
if os.path.isabs(expanded) and os.path.exists(expanded):
|
|
238
239
|
return os.path.abspath(expanded)
|
|
239
240
|
if os.path.exists(expanded):
|
|
@@ -241,17 +242,17 @@ def _resolve_hook_path(
|
|
|
241
242
|
|
|
242
243
|
search_dirs: list[str] = []
|
|
243
244
|
if config_path:
|
|
244
|
-
config_dir = os.path.dirname(os.path.abspath(
|
|
245
|
+
config_dir = os.path.dirname(os.path.abspath(expand_location(config_path)))
|
|
245
246
|
if custom_dir:
|
|
246
|
-
search_dirs.append(os.path.join(config_dir, custom_dir))
|
|
247
|
+
search_dirs.append(os.path.join(config_dir, expand_location(custom_dir)))
|
|
247
248
|
search_dirs.append(os.path.join(config_dir, 'hooks'))
|
|
248
249
|
search_dirs.append(config_dir)
|
|
249
250
|
|
|
250
251
|
xdg_home = os.environ.get('XDG_CONFIG_HOME')
|
|
251
252
|
if xdg_home:
|
|
252
|
-
search_dirs.append(os.path.join(
|
|
253
|
-
search_dirs.append(
|
|
254
|
-
search_dirs.append(
|
|
253
|
+
search_dirs.append(os.path.join(expand_location(xdg_home), 'vith', 'hooks'))
|
|
254
|
+
search_dirs.append(expand_location('~/.config/vith/hooks'))
|
|
255
|
+
search_dirs.append(expand_location('~/.vith/hooks'))
|
|
255
256
|
|
|
256
257
|
for directory in search_dirs:
|
|
257
258
|
candidate = os.path.join(directory, hook_name)
|
|
@@ -297,7 +298,7 @@ def run_hook_file(
|
|
|
297
298
|
The hook file is executed in an isolated namespace containing `editor`.
|
|
298
299
|
If a `configure` function is defined, it is called with `editor`.
|
|
299
300
|
"""
|
|
300
|
-
resolved =
|
|
301
|
+
resolved = expand_location(os.fspath(hook_path))
|
|
301
302
|
if not os.path.exists(resolved):
|
|
302
303
|
_report_rc_error('Hook file not found: %r' % resolved, error_handler)
|
|
303
304
|
return False
|
|
@@ -505,7 +506,7 @@ def run_rc_file(
|
|
|
505
506
|
assert isinstance(editor, Editor)
|
|
506
507
|
assert isinstance(rc_file, (str, os.PathLike))
|
|
507
508
|
|
|
508
|
-
rc_file_str =
|
|
509
|
+
rc_file_str = expand_location(os.fspath(rc_file))
|
|
509
510
|
|
|
510
511
|
if not os.path.exists(rc_file_str):
|
|
511
512
|
_report_rc_error('Impossible to read %r' % rc_file_str, error_handler)
|
|
@@ -9,6 +9,7 @@ represents the rendering, while this is more specific for the editor itself.
|
|
|
9
9
|
import weakref
|
|
10
10
|
|
|
11
11
|
from .editor_buffer import EditorBuffer
|
|
12
|
+
from .io.backends import expand_env_vars
|
|
12
13
|
|
|
13
14
|
__all__ = ('WindowArrangement',)
|
|
14
15
|
|
|
@@ -635,6 +636,9 @@ class WindowArrangement:
|
|
|
635
636
|
|
|
636
637
|
return eb
|
|
637
638
|
else:
|
|
639
|
+
# Expand environment variables before buffer deduplication so
|
|
640
|
+
# `%APPDATA%\...` and its expanded path resolve to the same buffer.
|
|
641
|
+
location = expand_env_vars(location)
|
|
638
642
|
# When a location is given, first look whether the file was already
|
|
639
643
|
# opened.
|
|
640
644
|
eb = self.get_editor_buffer_for_location(location)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vith
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.3
|
|
4
4
|
Summary: Vith — a pure-Python Vi clone with Thai & Lao script support (fork of pyvim)
|
|
5
5
|
Author-email: Chaiwat Suttipongsakul <cwt@bashell.com>
|
|
6
6
|
Maintainer-email: Chaiwat Suttipongsakul <cwt@bashell.com>
|
|
@@ -68,7 +68,7 @@ This fork runs on **Python 3.10+** (`prompt_toolkit` 3.0) and adds four major, m
|
|
|
68
68
|
- **Ex command completeness & `:set` parity**: full Vim Ex command set across files (`:r`/`:read` incl. `:r !cmd`, `:sav`, `:up`, `:x`, `:wa`, `:xa`, `:so`, `:f`, `:enew`), buffers/windows/tabs (`:ls`, `:b #`, `:bf`/`:bl`, `:sb`, `:bd <target>`, `:clo`, `:on`, `:tabo`/`:tabm`/`:tabs`), generalized range editing (`:$`/`±N`, `:d`, `:y`, `:pu`, `:m`, `:t`/`:co`, `:j`, `:sort`, `:retab`, `:g`/`:v`, `:[range]!cmd`, `:[range]w` partial/append/pipe, `:[range]norm[!]`), `%`/`#` filename expansion with `:p`/`:h`/`:t`/`:r`/`:e`, in-editor read-only info splits (`:ver`, `:mes`, `:reg`, `:marks`, `:set`), and ergonomic `:set` syntax (`?`, `!`, `inv`, multi-arg, `smartcase`, `shiftwidth`, `readonly`, `autoindent`, `fileencoding`, `fileformat`). See [`docs/command_completeness_plan.md`](docs/command_completeness_plan.md).
|
|
69
69
|
- **Live async `:render` split preview**: real-time non-blocking split preview (`:render`, `:render-split-v`, `:render-split-h`) powered by optional `vith[render]` (`rich` + `rich-rst`), with direct `Segment` → `StyleAndTextTuples` bridging, debounced executor rendering, stale-edit fallback, heading/landmark-anchored scroll sync, and pluggable `[render.commands]` CLI renderers. See [`docs/live_render.md`](docs/live_render.md).
|
|
70
70
|
|
|
71
|
-
All changes are audited in [`docs/bugs/`](docs/bugs/) (
|
|
71
|
+
All changes are audited in [`docs/bugs/`](docs/bugs/) (194 machine-verified findings across 14 audit rounds and 4 addenda — 193 fixed, 1 archived/withdrawn); quality is enforced with pytest (562 tests), mypy and ruff.
|
|
72
72
|
|
|
73
73
|
Issues, questions, wishes, comments, feedback, remarks? Please create a GitHub issue, I appreciate it.
|
|
74
74
|
|
|
@@ -183,7 +183,7 @@ To run all tests, install the optional and development dependencies (pytest, pyt
|
|
|
183
183
|
pip install -e ".[jedi,lzo,render,dev]"
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
Run unit tests via the test runner script (executes all
|
|
186
|
+
Run unit tests via the test runner script (executes all 562 tests in parallel and enforces ≥85% test coverage):
|
|
187
187
|
|
|
188
188
|
```sh
|
|
189
189
|
bash scripts/runtest.sh
|
|
@@ -197,7 +197,7 @@ python -m pytest tests
|
|
|
197
197
|
|
|
198
198
|
Developer helper scripts are provided in `scripts/`:
|
|
199
199
|
|
|
200
|
-
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (
|
|
200
|
+
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (562 tests)
|
|
201
201
|
- `scripts/type-check.sh`: run `mypy .` (typing, 88 source files checked against the 3.10 floor)
|
|
202
202
|
- `scripts/lint-check-and-fix.sh`: run `ruff check --fix .` (linting)
|
|
203
203
|
- `scripts/code-format.sh`: run `ruff format` (formatting)
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Tests for `vith/io/backends.py` (P5: `codecs.open` deprecation removal,
|
|
3
|
-
`FileIO`/`GZipFileIO` behaviour).
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import io
|
|
7
|
-
import warnings
|
|
8
|
-
|
|
9
|
-
from vith.io.backends import FileIO, GZipFileIO
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test_fileio_write_read_utf8_roundtrip(tmp_path):
|
|
13
|
-
f = FileIO()
|
|
14
|
-
p = str(tmp_path / 'file.txt')
|
|
15
|
-
|
|
16
|
-
f.write(p, 'héllo wörld', 'utf-8')
|
|
17
|
-
text, encoding = f.read(p)
|
|
18
|
-
|
|
19
|
-
assert text == 'héllo wörld'
|
|
20
|
-
assert encoding == 'utf-8'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def test_fileio_latin1_fallback(tmp_path):
|
|
24
|
-
p = tmp_path / 'latin1.txt'
|
|
25
|
-
# A byte that is not valid UTF-8: falls back to latin-1 (which accepts
|
|
26
|
-
# any byte sequence).
|
|
27
|
-
p.write_bytes(b'caf\xe9')
|
|
28
|
-
|
|
29
|
-
text, encoding = FileIO().read(str(p))
|
|
30
|
-
|
|
31
|
-
assert text == 'café'
|
|
32
|
-
assert encoding == 'latin-1'
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def test_fileio_no_deprecation_warning(tmp_path):
|
|
36
|
-
# P5: `codecs.open` is deprecated in Python 3.14+; the C-buffered
|
|
37
|
-
# `io.open` must be used instead, so no DeprecationWarning may be
|
|
38
|
-
# emitted while reading or writing.
|
|
39
|
-
p = str(tmp_path / 'deprecation.txt')
|
|
40
|
-
f = FileIO()
|
|
41
|
-
|
|
42
|
-
with warnings.catch_warnings(record=True) as caught:
|
|
43
|
-
warnings.simplefilter('always')
|
|
44
|
-
f.write(p, 'plain text', 'utf-8')
|
|
45
|
-
f.read(p)
|
|
46
|
-
|
|
47
|
-
deprecations = [w for w in caught if issubclass(w.category, DeprecationWarning)]
|
|
48
|
-
assert deprecations == [], (
|
|
49
|
-
'FileIO read/write must not emit DeprecationWarnings: %r' % deprecations
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def test_fileio_uses_io_open(tmp_path, monkeypatch):
|
|
54
|
-
# Explicitly: reads/writes go through `io.open`, not `codecs.open`.
|
|
55
|
-
p = str(tmp_path / 'tracked.txt')
|
|
56
|
-
f = FileIO()
|
|
57
|
-
|
|
58
|
-
calls = []
|
|
59
|
-
original = io.open
|
|
60
|
-
|
|
61
|
-
def tracking_open(*args, **kwargs):
|
|
62
|
-
calls.append((args, kwargs))
|
|
63
|
-
return original(*args, **kwargs)
|
|
64
|
-
|
|
65
|
-
monkeypatch.setattr('vith.io.backends.io.open', tracking_open)
|
|
66
|
-
|
|
67
|
-
f.write(p, 'data', 'utf-8')
|
|
68
|
-
assert f.read(p) == ('data', 'utf-8')
|
|
69
|
-
|
|
70
|
-
assert [args[1] for args, _kw in calls] == ['w']
|
|
71
|
-
assert [kw.get('encoding') for _args, kw in calls] == ['utf-8']
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def test_gzip_roundtrip(tmp_path):
|
|
75
|
-
p = str(tmp_path / 'data.txt.gz')
|
|
76
|
-
g = GZipFileIO()
|
|
77
|
-
|
|
78
|
-
g.write(p, 'compressed content', 'utf-8')
|
|
79
|
-
text, encoding = g.read(p)
|
|
80
|
-
|
|
81
|
-
assert text == 'compressed content'
|
|
82
|
-
assert encoding == 'utf-8'
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def test_gzip_can_open_location():
|
|
86
|
-
g = GZipFileIO()
|
|
87
|
-
assert g.can_open_location('/tmp/some-file.txt.gz') is True
|
|
88
|
-
assert g.can_open_location('/tmp/some-file.txt') is False
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def test_directory_io_handles_tilde(editor):
|
|
92
|
-
editor.load_initial_files(['~'])
|
|
93
|
-
eb = editor.window_arrangement.active_editor_buffer
|
|
94
|
-
assert eb.in_file_explorer_mode is True
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def test_gzip_can_open_location_expands_tilde(monkeypatch, tmp_path):
|
|
98
|
-
# 113 item 6: `GZipFileIO.can_open_location` delegates to `super()` and
|
|
99
|
-
# `_expand_location` consistently for `~/` paths.
|
|
100
|
-
monkeypatch.setenv('HOME', str(tmp_path))
|
|
101
|
-
gz_dir = tmp_path / 'dir.gz'
|
|
102
|
-
gz_dir.mkdir()
|
|
103
|
-
|
|
104
|
-
g = GZipFileIO()
|
|
105
|
-
assert g.can_open_location('~/archive.txt.gz') is True
|
|
106
|
-
assert g.can_open_location('~/dir.gz') is False
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def test_auto_decode_primary_and_fallback_encodings():
|
|
110
|
-
# 115 item 6: `_auto_decode` tries `PRIMARY_ENCODING` ('utf-8') then
|
|
111
|
-
# falls back to `FALLBACK_ENCODING` ('latin-1').
|
|
112
|
-
from vith.io.backends import ENCODINGS, FALLBACK_ENCODING, PRIMARY_ENCODING, _auto_decode
|
|
113
|
-
|
|
114
|
-
assert ENCODINGS == (PRIMARY_ENCODING, FALLBACK_ENCODING) == ('utf-8', 'latin-1')
|
|
115
|
-
assert _auto_decode('สวัสดี'.encode('utf-8')) == ('สวัสดี', 'utf-8')
|
|
116
|
-
assert _auto_decode(b'\xff\xfe') == ('\xff\xfe', 'latin-1')
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def test_directory_io_unreadable_raises_oserror(editor, tmp_path, monkeypatch):
|
|
120
|
-
# 110 item 8: `DirectoryIO.read` propagates `OSError` to `EditorBuffer._read`,
|
|
121
|
-
# which surfaces an error message in the editor instead of crashing.
|
|
122
|
-
import os
|
|
123
|
-
|
|
124
|
-
from vith.editor_buffer import EditorBuffer
|
|
125
|
-
|
|
126
|
-
target_dir = tmp_path / 'restricted'
|
|
127
|
-
target_dir.mkdir()
|
|
128
|
-
|
|
129
|
-
def failing_scandir(_path):
|
|
130
|
-
raise PermissionError('Permission denied')
|
|
131
|
-
|
|
132
|
-
monkeypatch.setattr(os, 'scandir', failing_scandir)
|
|
133
|
-
editor.message = None
|
|
134
|
-
eb = EditorBuffer(editor, str(target_dir))
|
|
135
|
-
assert eb.in_file_explorer_mode is True
|
|
136
|
-
assert editor.message is not None and 'Permission denied' in editor.message
|
vith-0.16.2/vith/io/__init__.py
DELETED
|
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
|
|
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
|
|
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
|
|
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
|