hyprconf2lua 1.5.0__tar.gz → 1.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hyprconf2lua-1.5.0/src/hyprconf2lua.egg-info → hyprconf2lua-1.6.0}/PKG-INFO +1 -1
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/pyproject.toml +1 -1
- hyprconf2lua-1.6.0/src/hyprconf2lua/__init__.py +1 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/codegen.py +56 -12
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/lexer.py +5 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/parser.py +17 -9
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0/src/hyprconf2lua.egg-info}/PKG-INFO +1 -1
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/tests/test_converter.py +76 -0
- hyprconf2lua-1.5.0/src/hyprconf2lua/__init__.py +0 -1
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/LICENSE +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/README.md +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/setup.cfg +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/__main__.py +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/ast.py +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/cli.py +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/converter.py +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/mappings.py +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/SOURCES.txt +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/dependency_links.txt +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/entry_points.txt +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/requires.txt +0 -0
- {hyprconf2lua-1.5.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.6.0"
|
|
@@ -129,6 +129,16 @@ class Codegen:
|
|
|
129
129
|
return "local_var_" + var_name
|
|
130
130
|
return re.sub(r'\$(\w+)', _repl, val)
|
|
131
131
|
|
|
132
|
+
def resolve_val_exec(self, val: str) -> str:
|
|
133
|
+
def _repl(m: re.Match) -> str:
|
|
134
|
+
var_name = m.group(1)
|
|
135
|
+
if var_name in self.variables:
|
|
136
|
+
return self.variables[var_name]
|
|
137
|
+
if var_name in os.environ:
|
|
138
|
+
return f'os.getenv("{var_name}")'
|
|
139
|
+
return m.group(0)
|
|
140
|
+
return re.sub(r'\$(\w+)', _repl, val)
|
|
141
|
+
|
|
132
142
|
def _build_concat_expr(self, val: str) -> str:
|
|
133
143
|
parts = re.split(r'(os\.getenv\([^)]+\))', val)
|
|
134
144
|
expr_parts = []
|
|
@@ -209,7 +219,7 @@ class Codegen:
|
|
|
209
219
|
break
|
|
210
220
|
|
|
211
221
|
def _exec_lua_expr(self, cmd: str) -> str:
|
|
212
|
-
resolved = self.
|
|
222
|
+
resolved = self.resolve_val_exec(cmd)
|
|
213
223
|
if resolved.startswith("$") and resolved[1:] in self.variables:
|
|
214
224
|
return resolved[1:]
|
|
215
225
|
if "os.getenv(" in resolved:
|
|
@@ -267,6 +277,8 @@ class Codegen:
|
|
|
267
277
|
return f"{{ colors = {{ {', '.join(colors)} }}, angle = {angle} }}"
|
|
268
278
|
|
|
269
279
|
def _emit_directive(self, key: str, values: List[str]):
|
|
280
|
+
if not values or all(not v.strip() for v in values):
|
|
281
|
+
return
|
|
270
282
|
key = self._normalize_key(key)
|
|
271
283
|
if len(values) == 1 and self._is_gradient(values[0]):
|
|
272
284
|
self.translated_count += 1
|
|
@@ -320,7 +332,7 @@ class Codegen:
|
|
|
320
332
|
self.passthrough_count += 1
|
|
321
333
|
self.emit(f"-- Nested subsection {sd.name}:")
|
|
322
334
|
for ssd in sd.body:
|
|
323
|
-
if isinstance(ssd, Directive):
|
|
335
|
+
if isinstance(ssd, Directive) and ssd.value and ssd.value[0].strip():
|
|
324
336
|
k = self._normalize_key(ssd.key)
|
|
325
337
|
vv = self.to_lua_val(ssd.value[0]) if ssd.value else "true"
|
|
326
338
|
self.emit(f"{k} = {vv},")
|
|
@@ -341,6 +353,8 @@ class Codegen:
|
|
|
341
353
|
self.indent()
|
|
342
354
|
for d in directives:
|
|
343
355
|
key = self._normalize_key(d.key)
|
|
356
|
+
if not d.value or not d.value[0].strip():
|
|
357
|
+
continue
|
|
344
358
|
if len(d.value) == 1:
|
|
345
359
|
val = self.to_lua_val(d.value[0])
|
|
346
360
|
self.emit(f"{key} = {val},")
|
|
@@ -603,7 +617,7 @@ class Codegen:
|
|
|
603
617
|
|
|
604
618
|
if dispatcher in ("exec", "execr"):
|
|
605
619
|
raw = params[0] if params else ""
|
|
606
|
-
resolved = self.
|
|
620
|
+
resolved = self.resolve_val_exec(raw)
|
|
607
621
|
if "os.getenv(" in resolved:
|
|
608
622
|
return f'{func}({self._build_concat_expr(resolved)})'
|
|
609
623
|
return f'{func}({self.quote(resolved)})'
|
|
@@ -691,6 +705,22 @@ class Codegen:
|
|
|
691
705
|
effects = {}
|
|
692
706
|
|
|
693
707
|
for mp in match_params:
|
|
708
|
+
if mp.startswith("match:"):
|
|
709
|
+
rest = mp[len("match:"):].strip()
|
|
710
|
+
m = re.match(r'^([a-zA-Z0-9_-]+)(?:\s*=\s*|\s*:\s*|\s+)(.*)$', rest)
|
|
711
|
+
if m:
|
|
712
|
+
match_key, value = m.groups()
|
|
713
|
+
else:
|
|
714
|
+
match_key = rest
|
|
715
|
+
value = "true"
|
|
716
|
+
if value.lower() == "true":
|
|
717
|
+
match[match_key] = "true"
|
|
718
|
+
elif value.lower() == "false":
|
|
719
|
+
match[match_key] = "false"
|
|
720
|
+
else:
|
|
721
|
+
match[match_key] = self.quote(value)
|
|
722
|
+
continue
|
|
723
|
+
|
|
694
724
|
colon_idx = mp.find(":")
|
|
695
725
|
if colon_idx > 0:
|
|
696
726
|
prefix = mp[:colon_idx].strip()
|
|
@@ -766,6 +796,8 @@ class Codegen:
|
|
|
766
796
|
|
|
767
797
|
for key, vals in stmt.effects.items():
|
|
768
798
|
key = self._normalize_key(key)
|
|
799
|
+
if not vals or not vals[0].strip():
|
|
800
|
+
continue
|
|
769
801
|
if len(vals) == 1:
|
|
770
802
|
parts = vals[0].split()
|
|
771
803
|
if len(parts) == 1:
|
|
@@ -843,25 +875,35 @@ class Codegen:
|
|
|
843
875
|
val_expr = self.to_lua_val(stmt.value)
|
|
844
876
|
self.emit(f"hl.env({name_q}, {val_expr})")
|
|
845
877
|
|
|
878
|
+
@staticmethod
|
|
879
|
+
def _sanitize_ident(s: str) -> str:
|
|
880
|
+
return re.sub(r"[^a-zA-Z0-9_]", "_", s)
|
|
881
|
+
|
|
882
|
+
def _source_module_path(self, path: str) -> str:
|
|
883
|
+
p = path.strip()
|
|
884
|
+
for marker in ("/.config/hypr/", "/.config/", "$XDG_CONFIG_HOME/", "$HOME/", "~/"):
|
|
885
|
+
if marker in p:
|
|
886
|
+
p = p.split(marker, 1)[1]
|
|
887
|
+
break
|
|
888
|
+
else:
|
|
889
|
+
p = p.lstrip("/")
|
|
890
|
+
p = p.replace(".conf", "")
|
|
891
|
+
return ".".join(self._sanitize_ident(part) for part in p.split("/") if part)
|
|
892
|
+
|
|
846
893
|
def visit_source(self, stmt: SourceDirective):
|
|
847
894
|
self.passthrough_count += 1
|
|
848
895
|
path = stmt.path
|
|
849
896
|
|
|
850
|
-
lua_path = path.replace(".conf", "")
|
|
851
|
-
lua_path = lua_path.replace("~", "os.getenv(\"HOME\")")
|
|
852
|
-
lua_path = lua_path.replace("/", ".")
|
|
853
|
-
|
|
854
897
|
if path.endswith("/*.conf"):
|
|
855
898
|
self.emit(f'-- source = {path}')
|
|
856
899
|
self.emit(f"-- NOTE: glob sources need manual handling")
|
|
857
900
|
self.emit(f"-- Directory contents must be required individually")
|
|
858
901
|
return
|
|
859
902
|
|
|
903
|
+
module = self._source_module_path(path)
|
|
904
|
+
local_name = module.split(".")[-1]
|
|
860
905
|
self.emit(f'-- source = {path} -> requires manual conversion')
|
|
861
|
-
|
|
862
|
-
import os as _os
|
|
863
|
-
just_name = _os.path.splitext(_os.path.basename(path))[0]
|
|
864
|
-
self.emit(f'-- local {just_name} = require("{just_name}")')
|
|
906
|
+
self.emit(f'-- local {local_name} = require("{module}")')
|
|
865
907
|
self.emit(f'-- TODO: convert {path} to .lua and use require()')
|
|
866
908
|
|
|
867
909
|
def visit_device(self, stmt: DeviceSection):
|
|
@@ -870,7 +912,7 @@ class Codegen:
|
|
|
870
912
|
self.indent()
|
|
871
913
|
self.emit(f'name = {self.quote(stmt.name)},')
|
|
872
914
|
for d in stmt.body:
|
|
873
|
-
if isinstance(d, Directive):
|
|
915
|
+
if isinstance(d, Directive) and d.value and d.value[0].strip():
|
|
874
916
|
key = self._normalize_key(d.key)
|
|
875
917
|
val = self.to_lua_val(d.value[0]) if d.value else "true"
|
|
876
918
|
self.emit(f"{key} = {val},")
|
|
@@ -972,6 +1014,8 @@ class Codegen:
|
|
|
972
1014
|
|
|
973
1015
|
for key, vals in stmt.effects.items():
|
|
974
1016
|
key = self._normalize_key(key)
|
|
1017
|
+
if not vals or not vals[0].strip():
|
|
1018
|
+
continue
|
|
975
1019
|
if len(vals) == 1:
|
|
976
1020
|
parts = vals[0].split()
|
|
977
1021
|
if len(parts) == 1:
|
|
@@ -12,8 +12,10 @@ TOKEN_SPECS = [
|
|
|
12
12
|
("COMMA", r","),
|
|
13
13
|
("DOT", r"\."),
|
|
14
14
|
("COLON", r":"),
|
|
15
|
+
("SHELL_EXP", r"\$\{[^}\n]*\}"),
|
|
15
16
|
("DOLLAR", r"\$"),
|
|
16
17
|
("STRING", r'"([^"\\]|\\.)*"'),
|
|
18
|
+
("CONT", r"\\[ \t]*\n"),
|
|
17
19
|
("IDENT", r'[^\s#"={},:!]+'),
|
|
18
20
|
("NEWLINE", r"\n"),
|
|
19
21
|
("SKIP", r"[ \t]+"),
|
|
@@ -59,6 +61,9 @@ def tokenize(source: str) -> List[Token]:
|
|
|
59
61
|
line += 1
|
|
60
62
|
last_line_start = pos + 1
|
|
61
63
|
tokens.append(Token("NEWLINE", value, line - 1, _col(pos)))
|
|
64
|
+
elif kind == "CONT":
|
|
65
|
+
line += 1
|
|
66
|
+
last_line_start = m.end()
|
|
62
67
|
elif kind == "SKIP":
|
|
63
68
|
pass
|
|
64
69
|
elif kind == "COMMENT":
|
|
@@ -137,7 +137,7 @@ class Parser:
|
|
|
137
137
|
|
|
138
138
|
def parse_value_rest(self) -> str:
|
|
139
139
|
parts = []
|
|
140
|
-
while self.peek().type in ("IDENT", "STRING", "DOLLAR", "DOT", "COLON") or \
|
|
140
|
+
while self.peek().type in ("IDENT", "STRING", "DOLLAR", "SHELL_EXP", "DOT", "COLON") or \
|
|
141
141
|
(self.peek().type == "EQUALS" and parts):
|
|
142
142
|
if self.peek().type == "COMMENT":
|
|
143
143
|
break
|
|
@@ -160,14 +160,14 @@ class Parser:
|
|
|
160
160
|
result = tokens[0]
|
|
161
161
|
for t in tokens[1:]:
|
|
162
162
|
no_space_before = {":", ",", "=", "+", "-", "%", "@", "^", "*", "|", "~"}
|
|
163
|
-
no_space_after = {":", ",", "="}
|
|
164
|
-
if t in no_space_before or result[-1:] in no_space_after:
|
|
163
|
+
no_space_after = {":", ",", "=", "."}
|
|
164
|
+
if t in no_space_before or result[-1:] in no_space_after or t.startswith(("/", ".")):
|
|
165
165
|
result += t
|
|
166
166
|
else:
|
|
167
167
|
result += " " + t
|
|
168
168
|
return result.strip()
|
|
169
169
|
|
|
170
|
-
def parse_comma_values(self) -> List[str]:
|
|
170
|
+
def parse_comma_values(self, keep_string_quotes: bool = False) -> List[str]:
|
|
171
171
|
values = []
|
|
172
172
|
current = []
|
|
173
173
|
while self.peek().type not in ("NEWLINE", "EOF") and \
|
|
@@ -200,7 +200,10 @@ class Parser:
|
|
|
200
200
|
current.append("$" + var_t.value)
|
|
201
201
|
else:
|
|
202
202
|
t = self.advance()
|
|
203
|
-
|
|
203
|
+
if keep_string_quotes and t.type == "STRING":
|
|
204
|
+
current.append('"' + t.value + '"')
|
|
205
|
+
else:
|
|
206
|
+
current.append(t.value)
|
|
204
207
|
remaining = self._join_tokens(current)
|
|
205
208
|
if remaining:
|
|
206
209
|
values.append(remaining)
|
|
@@ -296,6 +299,8 @@ class Parser:
|
|
|
296
299
|
if t.type == "EQUALS":
|
|
297
300
|
self.advance()
|
|
298
301
|
values = self.parse_comma_values()
|
|
302
|
+
if not values or all(not v.strip() for v in values):
|
|
303
|
+
return None
|
|
299
304
|
return Directive(directive, values, line, 0)
|
|
300
305
|
if t.type == "BLOCK_OPEN":
|
|
301
306
|
self.advance()
|
|
@@ -308,7 +313,7 @@ class Parser:
|
|
|
308
313
|
flags = _parse_combined_bind(directive)
|
|
309
314
|
self.expect("EQUALS")
|
|
310
315
|
self.skip_newlines()
|
|
311
|
-
values = self.parse_comma_values()
|
|
316
|
+
values = self.parse_comma_values(keep_string_quotes=True)
|
|
312
317
|
if len(values) < 3:
|
|
313
318
|
raise ParserError(f"bind needs at least 3 arguments (mods, key, dispatcher), got {len(values)}", Token("IDENT", directive, line, 0))
|
|
314
319
|
mods_str = values[0].strip()
|
|
@@ -416,10 +421,10 @@ class Parser:
|
|
|
416
421
|
|
|
417
422
|
def parse_exec(self, directive: str, line: int) -> ExecDirective:
|
|
418
423
|
self.expect("EQUALS")
|
|
419
|
-
command = self.parse_line_rest()
|
|
424
|
+
command = self.parse_line_rest(keep_string_quotes=True)
|
|
420
425
|
return ExecDirective(directive, command, line)
|
|
421
426
|
|
|
422
|
-
def parse_line_rest(self) -> str:
|
|
427
|
+
def parse_line_rest(self, keep_string_quotes: bool = False) -> str:
|
|
423
428
|
parts = []
|
|
424
429
|
while self.peek().type not in ("NEWLINE", "EOF", "COMMENT", "BLOCK_CLOSE"):
|
|
425
430
|
if self.peek().type == "DOLLAR":
|
|
@@ -428,7 +433,10 @@ class Parser:
|
|
|
428
433
|
parts.append("$" + var_t.value)
|
|
429
434
|
else:
|
|
430
435
|
t = self.advance()
|
|
431
|
-
|
|
436
|
+
if keep_string_quotes and t.type == "STRING":
|
|
437
|
+
parts.append('"' + t.value + '"')
|
|
438
|
+
else:
|
|
439
|
+
parts.append(t.value)
|
|
432
440
|
return self._join_tokens(parts)
|
|
433
441
|
|
|
434
442
|
def parse_animation(self, line: int) -> AnimationDirective:
|
|
@@ -662,6 +662,30 @@ def test_nested_subsection_in_decoration():
|
|
|
662
662
|
assert "size = 3" in result.lua
|
|
663
663
|
|
|
664
664
|
|
|
665
|
+
def test_windowrule_match_class():
|
|
666
|
+
result = convert("windowrule = workspace special:T silent, match:class ^(T)$\n")
|
|
667
|
+
assert result.success
|
|
668
|
+
assert "class = \"^(T)$\"" in result.lua
|
|
669
|
+
assert "workspace = \"special:T silent\"" in result.lua
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def test_windowrule_match_class_with_equals():
|
|
673
|
+
result = convert("windowrule = workspace special:T silent, match:class = ^(T)$\n")
|
|
674
|
+
assert result.success
|
|
675
|
+
assert "class = \"^(T)$\"" in result.lua
|
|
676
|
+
assert "workspace = \"special:T silent\"" in result.lua
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def test_windowrule_match_class_complex():
|
|
680
|
+
result = convert("windowrule = workspace special:T silent, match:class ^foo=bar$\n")
|
|
681
|
+
assert result.success
|
|
682
|
+
assert "class = \"^foo=bar$\"" in result.lua
|
|
683
|
+
|
|
684
|
+
result2 = convert("windowrule = workspace special:T silent, match:class:^(T)$\n")
|
|
685
|
+
assert result2.success
|
|
686
|
+
assert "class = \"^(T)$\"" in result2.lua
|
|
687
|
+
|
|
688
|
+
|
|
665
689
|
def test_env_var_resolution():
|
|
666
690
|
result = convert('env = AQ_DRM_DEVICES,$HOME/.config/hypr/cards/intelcard:$HOME/.config/hypr/cards/nvidiacard\n')
|
|
667
691
|
assert result.success
|
|
@@ -681,3 +705,55 @@ def test_hyphen_to_underscore_in_general():
|
|
|
681
705
|
assert result.success
|
|
682
706
|
assert "no_cursor" in result.lua
|
|
683
707
|
assert "no-cursor" not in result.lua
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
def test_leading_dot_float():
|
|
711
|
+
result = convert("input {\n scale = .97\n}\n")
|
|
712
|
+
assert result.success
|
|
713
|
+
assert "scale = .97," in result.lua
|
|
714
|
+
assert '". 97"' not in result.lua
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
def test_empty_value_skipped():
|
|
718
|
+
result = convert("input {\n kb_layout = es\n kb_variant =\n kb_model =\n}\n")
|
|
719
|
+
assert result.success
|
|
720
|
+
assert "kb_layout" in result.lua
|
|
721
|
+
assert "kb_variant" not in result.lua
|
|
722
|
+
assert "kb_model" not in result.lua
|
|
723
|
+
assert "{ }" not in result.lua
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
def test_source_filename_hyphens_sanitized():
|
|
727
|
+
result = convert("source = ~/.config/hypr/media-binds.conf\n")
|
|
728
|
+
assert result.success
|
|
729
|
+
assert 'require("media_binds")' in result.lua
|
|
730
|
+
assert "local media-binds" not in result.lua
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
def test_source_path_mapped_to_module():
|
|
734
|
+
result = convert("source = $HOME/.config/hypr/modules/keybinds.conf\n")
|
|
735
|
+
assert result.success
|
|
736
|
+
assert 'require("modules.keybinds")' in result.lua
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
def test_shell_brace_expansion():
|
|
740
|
+
result = convert("exec-once = xrdb ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources\n")
|
|
741
|
+
assert result.success
|
|
742
|
+
assert "xrdb ${XDG_CONFIG_HOME:-" in result.lua
|
|
743
|
+
assert "os.getenv(\"HOME\")" in result.lua
|
|
744
|
+
assert "/x11/xresources" in result.lua
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def test_multiline_exec_continuation():
|
|
748
|
+
src = (
|
|
749
|
+
"bind = ,print, exec, \\\n"
|
|
750
|
+
' FILE=~/Pictures/screenshot_$(date +%s).png; \\\n'
|
|
751
|
+
' grim -g "$(slurp)" "$FILE" && wl-copy < "$FILE" && \\\n'
|
|
752
|
+
' notify-send "Screenshot saved" -i "$FILE"\n'
|
|
753
|
+
)
|
|
754
|
+
result = convert(src)
|
|
755
|
+
assert result.success
|
|
756
|
+
assert 'hl.dsp.exec_cmd("FILE=~/Pictures/screenshot_$(date +%s).png;' in result.lua
|
|
757
|
+
assert '\\"$(slurp)\\"' in result.lua
|
|
758
|
+
assert "$FILE" in result.lua
|
|
759
|
+
assert "local_var_FILE" not in result.lua
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.5.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
|