hyprconf2lua 1.8.0__tar.gz → 1.8.2__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.
- {hyprconf2lua-1.8.0/src/hyprconf2lua.egg-info → hyprconf2lua-1.8.2}/PKG-INFO +1 -1
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/pyproject.toml +1 -1
- hyprconf2lua-1.8.2/src/hyprconf2lua/__init__.py +1 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/cli.py +10 -9
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/codegen.py +26 -3
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/lexer.py +2 -2
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/parser.py +5 -5
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2/src/hyprconf2lua.egg-info}/PKG-INFO +1 -1
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/tests/test_converter.py +52 -0
- hyprconf2lua-1.8.0/src/hyprconf2lua/__init__.py +0 -1
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/LICENSE +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/README.md +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/setup.cfg +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/__main__.py +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/ast.py +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/converter.py +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua/mappings.py +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua.egg-info/SOURCES.txt +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua.egg-info/dependency_links.txt +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua.egg-info/entry_points.txt +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua.egg-info/requires.txt +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/src/hyprconf2lua.egg-info/top_level.txt +0 -0
- {hyprconf2lua-1.8.0 → hyprconf2lua-1.8.2}/tests/test_issue54.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.8.2"
|
|
@@ -48,7 +48,9 @@ def process_dir(dir_path: str, in_place: bool = False, check: bool = False,
|
|
|
48
48
|
fpath = os.path.join(root, fname)
|
|
49
49
|
lua_path = os.path.splitext(fpath)[0] + ".lua"
|
|
50
50
|
|
|
51
|
-
if not check and not in_place:
|
|
51
|
+
if not check and not in_place and os.path.exists(lua_path):
|
|
52
|
+
print(f" SKIP: {lua_path} exists (use --in-place to overwrite)",
|
|
53
|
+
file=sys.stderr)
|
|
52
54
|
continue
|
|
53
55
|
|
|
54
56
|
lua_output = convert_file(fpath, check=check, report=report)
|
|
@@ -62,14 +64,13 @@ def process_dir(dir_path: str, in_place: bool = False, check: bool = False,
|
|
|
62
64
|
if check:
|
|
63
65
|
print(f" PASS: {fpath}")
|
|
64
66
|
continue
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
failed += 1
|
|
67
|
+
try:
|
|
68
|
+
with open(lua_path, "w") as f:
|
|
69
|
+
f.write(lua_output)
|
|
70
|
+
print(f" WROTE: {lua_path}")
|
|
71
|
+
except IOError as e:
|
|
72
|
+
print(f" ERROR writing {lua_path}: {e}", file=sys.stderr)
|
|
73
|
+
failed += 1
|
|
73
74
|
|
|
74
75
|
return failed
|
|
75
76
|
|
|
@@ -55,7 +55,8 @@ class Codegen:
|
|
|
55
55
|
|
|
56
56
|
def generate(self, config: ConfigFile) -> str:
|
|
57
57
|
self.lines = []
|
|
58
|
-
|
|
58
|
+
import hyprconf2lua
|
|
59
|
+
self.emit(f"-- Generated by hyprconf2lua v{hyprconf2lua.__version__}")
|
|
59
60
|
self.emit("-- https://github.com/Prateek-squadron/hyprconf2lua")
|
|
60
61
|
self.emit("-- Manual review may be needed for complex directives")
|
|
61
62
|
self.emit("")
|
|
@@ -517,7 +518,7 @@ class Codegen:
|
|
|
517
518
|
params = rest
|
|
518
519
|
|
|
519
520
|
if dsp_code is None:
|
|
520
|
-
self.
|
|
521
|
+
self._reclassify_as_flagged()
|
|
521
522
|
self.emit(f'-- TODO: manual review (unknown dispatcher: {stmt.dispatcher})')
|
|
522
523
|
pstr = ", ".join(self.quote(self.resolve_val(p)) for p in stmt.params)
|
|
523
524
|
self.emit(f'-- hl.bind({combo_expr}, hl.dsp.{stmt.dispatcher}({pstr}))')
|
|
@@ -618,6 +619,19 @@ class Codegen:
|
|
|
618
619
|
if dispatcher == "pass":
|
|
619
620
|
return f'{func}({{ window = {self.quote(params[0]) if params else "nil"} }})'
|
|
620
621
|
|
|
622
|
+
if dispatcher == "fullscreen":
|
|
623
|
+
if params and params[0] == "1":
|
|
624
|
+
return f'{func}({{ mode = 1 }})'
|
|
625
|
+
elif params and params[0] == "0":
|
|
626
|
+
return f'{func}()'
|
|
627
|
+
return f'{func}()'
|
|
628
|
+
|
|
629
|
+
if dispatcher == "splitratio":
|
|
630
|
+
nums = params[0].split() if params else []
|
|
631
|
+
x = nums[0] if len(nums) > 0 else "0"
|
|
632
|
+
y = nums[1] if len(nums) > 1 else "0"
|
|
633
|
+
return f'{func}({{ x = {x}, y = {y}, relative = true }})'
|
|
634
|
+
|
|
621
635
|
if dispatcher == "resizeactive":
|
|
622
636
|
nums = params[0].split() if params else []
|
|
623
637
|
x = nums[0] if len(nums) > 0 else "0"
|
|
@@ -850,10 +864,13 @@ class Codegen:
|
|
|
850
864
|
self.dedent()
|
|
851
865
|
self.emit("},")
|
|
852
866
|
|
|
867
|
+
flagged = False
|
|
853
868
|
for prop in props:
|
|
854
869
|
if not self._emit_rule_effect(prop):
|
|
855
|
-
|
|
870
|
+
flagged = True
|
|
856
871
|
self.emit(f'-- TODO: review rule: {self.quote(prop)}')
|
|
872
|
+
if flagged:
|
|
873
|
+
self._reclassify_as_flagged()
|
|
857
874
|
|
|
858
875
|
self.dedent()
|
|
859
876
|
self.emit("})")
|
|
@@ -1124,6 +1141,12 @@ class Codegen:
|
|
|
1124
1141
|
self.dedent()
|
|
1125
1142
|
self.emit("})")
|
|
1126
1143
|
|
|
1144
|
+
def _reclassify_as_flagged(self):
|
|
1145
|
+
# The visitor counted this directive as translated on entry; a
|
|
1146
|
+
# directive is reported in exactly one bucket, so move it to flagged.
|
|
1147
|
+
self.translated_count -= 1
|
|
1148
|
+
self.flag_count += 1
|
|
1149
|
+
|
|
1127
1150
|
def get_report(self) -> dict:
|
|
1128
1151
|
return {
|
|
1129
1152
|
"translated": self.translated_count,
|
|
@@ -14,7 +14,7 @@ TOKEN_SPECS = [
|
|
|
14
14
|
("COLON", r":"),
|
|
15
15
|
("SHELL_EXP", r"\$\{[^}\n]*\}"),
|
|
16
16
|
("DOLLAR", r"\$"),
|
|
17
|
-
("STRING", r'"([^"\\]|\\.)*"'),
|
|
17
|
+
("STRING", r'"([^"\\]|\\.)*"|\'([^\'\\]|\\.)*\''),
|
|
18
18
|
("CONT", r"\\[ \t]*\n"),
|
|
19
19
|
("IDENT", r'[^\s#"={},:!]+'),
|
|
20
20
|
("NEWLINE", r"\n"),
|
|
@@ -71,7 +71,7 @@ def tokenize(source: str) -> List[Token]:
|
|
|
71
71
|
elif kind == "MISMATCH":
|
|
72
72
|
raise LexerError(f"Unexpected character: {value!r}", line, _col(pos))
|
|
73
73
|
elif kind == "STRING":
|
|
74
|
-
tokens.append(Token("STRING", value
|
|
74
|
+
tokens.append(Token("STRING", value, line, _col(pos)))
|
|
75
75
|
else:
|
|
76
76
|
tokens.append(Token(kind, value, line, _col(pos)))
|
|
77
77
|
|
|
@@ -15,7 +15,7 @@ BIND_FLAG_MAP = {
|
|
|
15
15
|
"bindn": "n",
|
|
16
16
|
"bindo": "",
|
|
17
17
|
"bindm": "m",
|
|
18
|
-
"binde": "",
|
|
18
|
+
"binde": "e",
|
|
19
19
|
"bindt": "t",
|
|
20
20
|
"bindi": "i",
|
|
21
21
|
"bindp": "p",
|
|
@@ -212,8 +212,8 @@ class Parser:
|
|
|
212
212
|
current.append("$" + var_t.value)
|
|
213
213
|
else:
|
|
214
214
|
t = self.advance()
|
|
215
|
-
if
|
|
216
|
-
current.append(
|
|
215
|
+
if t.type == "STRING" and not keep_string_quotes:
|
|
216
|
+
current.append(t.value[1:-1])
|
|
217
217
|
else:
|
|
218
218
|
current.append(t.value)
|
|
219
219
|
remaining = self._join_tokens(current)
|
|
@@ -445,8 +445,8 @@ class Parser:
|
|
|
445
445
|
parts.append("$" + var_t.value)
|
|
446
446
|
else:
|
|
447
447
|
t = self.advance()
|
|
448
|
-
if
|
|
449
|
-
parts.append(
|
|
448
|
+
if t.type == "STRING" and not keep_string_quotes:
|
|
449
|
+
parts.append(t.value[1:-1])
|
|
450
450
|
else:
|
|
451
451
|
parts.append(t.value)
|
|
452
452
|
return self._join_tokens(parts)
|
|
@@ -875,3 +875,55 @@ def test_rgba_color_values():
|
|
|
875
875
|
assert result.success
|
|
876
876
|
assert '"rgba(0,0,0,0.85)"' in result.lua
|
|
877
877
|
assert "shadow = { color =" in result.lua
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
def test_report_counts_flagged_windowrule_once():
|
|
881
|
+
result = convert(
|
|
882
|
+
"windowrule = float, class:foo\n"
|
|
883
|
+
"windowrule = bogus, class:foo\n"
|
|
884
|
+
"windowrule = bogus, other, class:bar\n"
|
|
885
|
+
)
|
|
886
|
+
assert result.success
|
|
887
|
+
assert result.report == {"translated": 1, "passthrough": 0, "flagged": 2}
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def test_report_counts_unknown_dispatcher_bind_once():
|
|
891
|
+
result = convert("bind = SUPER, Q, notadispatcher, arg\n")
|
|
892
|
+
assert result.success
|
|
893
|
+
assert result.report == {"translated": 0, "passthrough": 0, "flagged": 1}
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
def test_directory_conversion_writes_missing_lua():
|
|
897
|
+
from hyprconf2lua.cli import process_dir
|
|
898
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
899
|
+
with open(os.path.join(tmpdir, "new.conf"), "w") as f:
|
|
900
|
+
f.write("bind = SUPER, Q, exec, kitty\n")
|
|
901
|
+
with open(os.path.join(tmpdir, "old.conf"), "w") as f:
|
|
902
|
+
f.write("bind = SUPER, Q, exec, kitty\n")
|
|
903
|
+
old_lua = os.path.join(tmpdir, "old.lua")
|
|
904
|
+
with open(old_lua, "w") as f:
|
|
905
|
+
f.write("-- hand-edited\n")
|
|
906
|
+
|
|
907
|
+
failed = process_dir(tmpdir)
|
|
908
|
+
|
|
909
|
+
assert failed == 0
|
|
910
|
+
with open(os.path.join(tmpdir, "new.lua")) as f:
|
|
911
|
+
assert "hl.bind" in f.read()
|
|
912
|
+
with open(old_lua) as f:
|
|
913
|
+
assert f.read() == "-- hand-edited\n"
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
def test_directory_conversion_in_place_overwrites_lua():
|
|
917
|
+
from hyprconf2lua.cli import process_dir
|
|
918
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
919
|
+
with open(os.path.join(tmpdir, "old.conf"), "w") as f:
|
|
920
|
+
f.write("bind = SUPER, Q, exec, kitty\n")
|
|
921
|
+
old_lua = os.path.join(tmpdir, "old.lua")
|
|
922
|
+
with open(old_lua, "w") as f:
|
|
923
|
+
f.write("-- hand-edited\n")
|
|
924
|
+
|
|
925
|
+
failed = process_dir(tmpdir, in_place=True)
|
|
926
|
+
|
|
927
|
+
assert failed == 0
|
|
928
|
+
with open(old_lua) as f:
|
|
929
|
+
assert "hl.bind" in f.read()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.8.0"
|
|
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
|