hyprconf2lua 1.4.0__tar.gz → 1.5.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.4.0/src/hyprconf2lua.egg-info → hyprconf2lua-1.5.0}/PKG-INFO +1 -1
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/pyproject.toml +1 -1
- hyprconf2lua-1.5.0/src/hyprconf2lua/__init__.py +1 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/codegen.py +56 -26
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0/src/hyprconf2lua.egg-info}/PKG-INFO +1 -1
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/tests/test_converter.py +21 -0
- hyprconf2lua-1.4.0/src/hyprconf2lua/__init__.py +0 -1
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/LICENSE +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/README.md +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/setup.cfg +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/__main__.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/ast.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/cli.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/converter.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/lexer.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/mappings.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua/parser.py +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua.egg-info/SOURCES.txt +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua.egg-info/dependency_links.txt +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua.egg-info/entry_points.txt +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua.egg-info/requires.txt +0 -0
- {hyprconf2lua-1.4.0 → hyprconf2lua-1.5.0}/src/hyprconf2lua.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.5.0"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
+
import os
|
|
2
3
|
import re
|
|
3
4
|
from typing import Dict, List, Optional
|
|
4
5
|
|
|
@@ -118,6 +119,28 @@ class Codegen:
|
|
|
118
119
|
return "local_var_" + var_name
|
|
119
120
|
return re.sub(r'\$(\w+)', _repl, val)
|
|
120
121
|
|
|
122
|
+
def resolve_val_with_env(self, val: str) -> str:
|
|
123
|
+
def _repl(m: re.Match) -> str:
|
|
124
|
+
var_name = m.group(1)
|
|
125
|
+
if var_name in self.variables:
|
|
126
|
+
return self.variables[var_name]
|
|
127
|
+
if var_name in os.environ:
|
|
128
|
+
return f'os.getenv("{var_name}")'
|
|
129
|
+
return "local_var_" + var_name
|
|
130
|
+
return re.sub(r'\$(\w+)', _repl, val)
|
|
131
|
+
|
|
132
|
+
def _build_concat_expr(self, val: str) -> str:
|
|
133
|
+
parts = re.split(r'(os\.getenv\([^)]+\))', val)
|
|
134
|
+
expr_parts = []
|
|
135
|
+
for part in parts:
|
|
136
|
+
if part.startswith("os.getenv("):
|
|
137
|
+
expr_parts.append(part)
|
|
138
|
+
elif part:
|
|
139
|
+
expr_parts.append(self.quote(part))
|
|
140
|
+
if not expr_parts:
|
|
141
|
+
return '""'
|
|
142
|
+
return " .. ".join(expr_parts)
|
|
143
|
+
|
|
121
144
|
def needs_quotes(self, val: str) -> bool:
|
|
122
145
|
if not val:
|
|
123
146
|
return True
|
|
@@ -139,10 +162,16 @@ class Codegen:
|
|
|
139
162
|
return f'"{escaped}"'
|
|
140
163
|
return val
|
|
141
164
|
|
|
165
|
+
@staticmethod
|
|
166
|
+
def _normalize_key(key: str) -> str:
|
|
167
|
+
return key.replace("-", "_")
|
|
168
|
+
|
|
142
169
|
def to_lua_val(self, val: str):
|
|
143
|
-
val = self.
|
|
170
|
+
val = self.resolve_val_with_env(val)
|
|
144
171
|
if val.startswith("local_var_"):
|
|
145
172
|
return val[len("local_var_"):]
|
|
173
|
+
if "os.getenv(" in val:
|
|
174
|
+
return self._build_concat_expr(val)
|
|
146
175
|
if val.lower() in ("true", "on", "yes"):
|
|
147
176
|
return "true"
|
|
148
177
|
if val.lower() in ("false", "off", "no"):
|
|
@@ -160,7 +189,7 @@ class Codegen:
|
|
|
160
189
|
return self.quote(val)
|
|
161
190
|
|
|
162
191
|
def visit_variable(self, stmt: VariableDef):
|
|
163
|
-
val = self.
|
|
192
|
+
val = self.resolve_val_with_env(stmt.value)
|
|
164
193
|
self.variables[stmt.name] = val
|
|
165
194
|
self.translated_count += 1
|
|
166
195
|
if stmt.name.upper() == "MAINMOD" or stmt.name == "mainMod":
|
|
@@ -179,17 +208,21 @@ class Codegen:
|
|
|
179
208
|
self.main_mod_var = name
|
|
180
209
|
break
|
|
181
210
|
|
|
211
|
+
def _exec_lua_expr(self, cmd: str) -> str:
|
|
212
|
+
resolved = self.resolve_val_with_env(cmd)
|
|
213
|
+
if resolved.startswith("$") and resolved[1:] in self.variables:
|
|
214
|
+
return resolved[1:]
|
|
215
|
+
if "os.getenv(" in resolved:
|
|
216
|
+
return self._build_concat_expr(resolved)
|
|
217
|
+
return self.quote(resolved)
|
|
218
|
+
|
|
182
219
|
def emit_pending_execs(self):
|
|
183
220
|
if self.pending_exec_ones:
|
|
184
221
|
self.emit("-- Autostart")
|
|
185
222
|
self.emit('hl.on("hyprland.start", function()')
|
|
186
223
|
self.indent()
|
|
187
224
|
for cmd in self.pending_exec_ones:
|
|
188
|
-
|
|
189
|
-
if resolved.startswith("$") and resolved[1:] in self.variables:
|
|
190
|
-
self.emit(f"hl.exec_cmd({resolved[1:]})")
|
|
191
|
-
else:
|
|
192
|
-
self.emit(f"hl.exec_cmd({self.quote(resolved)})")
|
|
225
|
+
self.emit(f"hl.exec_cmd({self._exec_lua_expr(cmd)})")
|
|
193
226
|
self.dedent()
|
|
194
227
|
self.emit("end)")
|
|
195
228
|
self.emit("")
|
|
@@ -199,11 +232,7 @@ class Codegen:
|
|
|
199
232
|
self.emit('hl.on("config.reloaded", function()')
|
|
200
233
|
self.indent()
|
|
201
234
|
for cmd in self.pending_execs:
|
|
202
|
-
|
|
203
|
-
if resolved.startswith("$") and resolved[1:] in self.variables:
|
|
204
|
-
self.emit(f"hl.exec_cmd({resolved[1:]})")
|
|
205
|
-
else:
|
|
206
|
-
self.emit(f"hl.exec_cmd({self.quote(resolved)})")
|
|
235
|
+
self.emit(f"hl.exec_cmd({self._exec_lua_expr(cmd)})")
|
|
207
236
|
self.dedent()
|
|
208
237
|
self.emit("end)")
|
|
209
238
|
self.emit("")
|
|
@@ -213,11 +242,7 @@ class Codegen:
|
|
|
213
242
|
self.emit('hl.on("hyprland.shutdown", function()')
|
|
214
243
|
self.indent()
|
|
215
244
|
for cmd in self.pending_exec_shutdowns:
|
|
216
|
-
|
|
217
|
-
if resolved.startswith("$") and resolved[1:] in self.variables:
|
|
218
|
-
self.emit(f"hl.exec_cmd({resolved[1:]})")
|
|
219
|
-
else:
|
|
220
|
-
self.emit(f"hl.exec_cmd({self.quote(resolved)})")
|
|
245
|
+
self.emit(f"hl.exec_cmd({self._exec_lua_expr(cmd)})")
|
|
221
246
|
self.dedent()
|
|
222
247
|
self.emit("end)")
|
|
223
248
|
self.emit("")
|
|
@@ -242,6 +267,7 @@ class Codegen:
|
|
|
242
267
|
return f"{{ colors = {{ {', '.join(colors)} }}, angle = {angle} }}"
|
|
243
268
|
|
|
244
269
|
def _emit_directive(self, key: str, values: List[str]):
|
|
270
|
+
key = self._normalize_key(key)
|
|
245
271
|
if len(values) == 1 and self._is_gradient(values[0]):
|
|
246
272
|
self.translated_count += 1
|
|
247
273
|
self.emit(f"{key} = {self._format_gradient(values[0])},")
|
|
@@ -295,7 +321,7 @@ class Codegen:
|
|
|
295
321
|
self.emit(f"-- Nested subsection {sd.name}:")
|
|
296
322
|
for ssd in sd.body:
|
|
297
323
|
if isinstance(ssd, Directive):
|
|
298
|
-
k = ssd.key
|
|
324
|
+
k = self._normalize_key(ssd.key)
|
|
299
325
|
vv = self.to_lua_val(ssd.value[0]) if ssd.value else "true"
|
|
300
326
|
self.emit(f"{k} = {vv},")
|
|
301
327
|
self.dedent()
|
|
@@ -314,7 +340,7 @@ class Codegen:
|
|
|
314
340
|
self.emit(f"{name} = {{")
|
|
315
341
|
self.indent()
|
|
316
342
|
for d in directives:
|
|
317
|
-
key = d.key
|
|
343
|
+
key = self._normalize_key(d.key)
|
|
318
344
|
if len(d.value) == 1:
|
|
319
345
|
val = self.to_lua_val(d.value[0])
|
|
320
346
|
self.emit(f"{key} = {val},")
|
|
@@ -576,7 +602,10 @@ class Codegen:
|
|
|
576
602
|
return f'{func}({{ on_monitor = true }})'
|
|
577
603
|
|
|
578
604
|
if dispatcher in ("exec", "execr"):
|
|
579
|
-
|
|
605
|
+
raw = params[0] if params else ""
|
|
606
|
+
resolved = self.resolve_val_with_env(raw)
|
|
607
|
+
if "os.getenv(" in resolved:
|
|
608
|
+
return f'{func}({self._build_concat_expr(resolved)})'
|
|
580
609
|
return f'{func}({self.quote(resolved)})'
|
|
581
610
|
|
|
582
611
|
args = self.build_dispatcher_args(params, needs_args, func)
|
|
@@ -731,11 +760,12 @@ class Codegen:
|
|
|
731
760
|
self.emit("match = {")
|
|
732
761
|
self.indent()
|
|
733
762
|
for k, v in stmt.match.items():
|
|
734
|
-
self.emit(f"{k} = {self.quote(v)},")
|
|
763
|
+
self.emit(f"{self._normalize_key(k)} = {self.quote(v)},")
|
|
735
764
|
self.dedent()
|
|
736
765
|
self.emit("},")
|
|
737
766
|
|
|
738
767
|
for key, vals in stmt.effects.items():
|
|
768
|
+
key = self._normalize_key(key)
|
|
739
769
|
if len(vals) == 1:
|
|
740
770
|
parts = vals[0].split()
|
|
741
771
|
if len(parts) == 1:
|
|
@@ -809,10 +839,9 @@ class Codegen:
|
|
|
809
839
|
def visit_env(self, stmt: EnvDirective):
|
|
810
840
|
self.translated_count += 1
|
|
811
841
|
resolved_name = self.resolve_val(stmt.name)
|
|
812
|
-
resolved_val = self.resolve_val(stmt.value)
|
|
813
842
|
name_q = self.quote(resolved_name)
|
|
814
|
-
|
|
815
|
-
self.emit(f"hl.env({name_q}, {
|
|
843
|
+
val_expr = self.to_lua_val(stmt.value)
|
|
844
|
+
self.emit(f"hl.env({name_q}, {val_expr})")
|
|
816
845
|
|
|
817
846
|
def visit_source(self, stmt: SourceDirective):
|
|
818
847
|
self.passthrough_count += 1
|
|
@@ -842,7 +871,7 @@ class Codegen:
|
|
|
842
871
|
self.emit(f'name = {self.quote(stmt.name)},')
|
|
843
872
|
for d in stmt.body:
|
|
844
873
|
if isinstance(d, Directive):
|
|
845
|
-
key = d.key
|
|
874
|
+
key = self._normalize_key(d.key)
|
|
846
875
|
val = self.to_lua_val(d.value[0]) if d.value else "true"
|
|
847
876
|
self.emit(f"{key} = {val},")
|
|
848
877
|
self.dedent()
|
|
@@ -937,11 +966,12 @@ class Codegen:
|
|
|
937
966
|
self.emit("match = {")
|
|
938
967
|
self.indent()
|
|
939
968
|
for k, v in stmt.match.items():
|
|
940
|
-
self.emit(f"{k} = {self.quote(v)},")
|
|
969
|
+
self.emit(f"{self._normalize_key(k)} = {self.quote(v)},")
|
|
941
970
|
self.dedent()
|
|
942
971
|
self.emit("},")
|
|
943
972
|
|
|
944
973
|
for key, vals in stmt.effects.items():
|
|
974
|
+
key = self._normalize_key(key)
|
|
945
975
|
if len(vals) == 1:
|
|
946
976
|
parts = vals[0].split()
|
|
947
977
|
if len(parts) == 1:
|
|
@@ -660,3 +660,24 @@ def test_nested_subsection_in_decoration():
|
|
|
660
660
|
assert result.success
|
|
661
661
|
assert "blur" in result.lua
|
|
662
662
|
assert "size = 3" in result.lua
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
def test_env_var_resolution():
|
|
666
|
+
result = convert('env = AQ_DRM_DEVICES,$HOME/.config/hypr/cards/intelcard:$HOME/.config/hypr/cards/nvidiacard\n')
|
|
667
|
+
assert result.success
|
|
668
|
+
assert 'os.getenv("HOME")' in result.lua
|
|
669
|
+
assert "local_var_HOME" not in result.lua
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def test_hyphen_to_underscore_in_device():
|
|
673
|
+
result = convert('device {\n name = touchpad\n tap-to-click = true\n}\n')
|
|
674
|
+
assert result.success
|
|
675
|
+
assert "tap_to_click" in result.lua
|
|
676
|
+
assert "tap-to-click" not in result.lua
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def test_hyphen_to_underscore_in_general():
|
|
680
|
+
result = convert('general {\n no-cursor = true\n}\n')
|
|
681
|
+
assert result.success
|
|
682
|
+
assert "no_cursor" in result.lua
|
|
683
|
+
assert "no-cursor" not in result.lua
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.4.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
|
|
File without changes
|
|
File without changes
|