xcomponent 0.8.3__tar.gz → 0.9.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.
Files changed (89) hide show
  1. {xcomponent-0.8.3 → xcomponent-0.9.0}/CHANGELOG.md +11 -0
  2. {xcomponent-0.8.3 → xcomponent-0.9.0}/Cargo.lock +1 -1
  3. {xcomponent-0.8.3 → xcomponent-0.9.0}/Cargo.toml +1 -1
  4. {xcomponent-0.8.3 → xcomponent-0.9.0}/PKG-INFO +1 -1
  5. {xcomponent-0.8.3 → xcomponent-0.9.0}/pyproject.toml +1 -1
  6. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/context.rs +14 -2
  7. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/ast/eval.rs +1 -0
  8. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/i18n.rs +19 -2
  9. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/adapters/test_babel.py +30 -1
  10. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_binary_eq.py +4 -1
  11. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_types.py +31 -1
  12. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_node.py +41 -1
  13. {xcomponent-0.8.3 → xcomponent-0.9.0}/uv.lock +1 -1
  14. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/build-sdist.yml +0 -0
  15. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/build-wheels.yml +0 -0
  16. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/publish-doc.yml +0 -0
  17. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/publish-pypi.yml +0 -0
  18. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/release.yml +0 -0
  19. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/tests-artifacts.yml +0 -0
  20. {xcomponent-0.8.3 → xcomponent-0.9.0}/.github/workflows/tests.yml +0 -0
  21. {xcomponent-0.8.3 → xcomponent-0.9.0}/.gitignore +0 -0
  22. {xcomponent-0.8.3 → xcomponent-0.9.0}/.python-version +0 -0
  23. {xcomponent-0.8.3 → xcomponent-0.9.0}/Justfile +0 -0
  24. {xcomponent-0.8.3 → xcomponent-0.9.0}/LICENSE +0 -0
  25. {xcomponent-0.8.3 → xcomponent-0.9.0}/README.md +0 -0
  26. {xcomponent-0.8.3 → xcomponent-0.9.0}/docs/Makefile +0 -0
  27. {xcomponent-0.8.3 → xcomponent-0.9.0}/docs/source/conf.py +0 -0
  28. {xcomponent-0.8.3 → xcomponent-0.9.0}/docs/source/develop/.gitkeep +0 -0
  29. {xcomponent-0.8.3 → xcomponent-0.9.0}/docs/source/index.md +0 -0
  30. {xcomponent-0.8.3 → xcomponent-0.9.0}/docs/source/user/changelog.md +0 -0
  31. {xcomponent-0.8.3 → xcomponent-0.9.0}/docs/source/user/getting_started.md +0 -0
  32. {xcomponent-0.8.3 → xcomponent-0.9.0}/scripts/get_version.py +0 -0
  33. {xcomponent-0.8.3 → xcomponent-0.9.0}/scripts/write_changelog.py +0 -0
  34. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/__init__.py +0 -0
  35. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/adapters/__init__.py +0 -0
  36. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/adapters/babel.py +0 -0
  37. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/py.typed +0 -0
  38. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/service/__init__.py +0 -0
  39. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/service/catalog.py +0 -0
  40. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/python/xcomponent/xcore.pyi +0 -0
  41. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/catalog/catalog.rs +0 -0
  42. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/catalog/mod.rs +0 -0
  43. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/ast/mod.rs +0 -0
  44. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/ast/model.rs +0 -0
  45. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/ast/parse.rs +0 -0
  46. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/grammar.pest +0 -0
  47. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/mod.rs +0 -0
  48. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/parser.rs +0 -0
  49. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/expression/tokens.rs +0 -0
  50. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/lib.rs +0 -0
  51. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/markup/grammar.pest +0 -0
  52. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/markup/mod.rs +0 -0
  53. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/markup/parser.rs +0 -0
  54. {xcomponent-0.8.3 → xcomponent-0.9.0}/src/rust/markup/tokens.rs +0 -0
  55. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/__init__.py +0 -0
  56. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/__init__.py +0 -0
  57. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/i18n/__init__.py +0 -0
  58. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/i18n/babel.ini +0 -0
  59. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/i18n/fr.mo +0 -0
  60. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/i18n/fr.po +0 -0
  61. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/i18n/mydomain.pot +0 -0
  62. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/functionals/i18n/test_l10n.py +0 -0
  63. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/__init__.py +0 -0
  64. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/adapters/__init__.py +0 -0
  65. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/conftest.py +0 -0
  66. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_binary_op.py +0 -0
  67. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_binary_op_bool.py +0 -0
  68. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_default_values.py +0 -0
  69. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_field_access.py +0 -0
  70. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_for_expr.py +0 -0
  71. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_func.py +0 -0
  72. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_if_expr.py +0 -0
  73. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_let.py +0 -0
  74. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_nested.py +0 -0
  75. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_render_comment.py +0 -0
  76. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_script.py +0 -0
  77. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_str_dedent.py +0 -0
  78. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_str_method.py +0 -0
  79. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/expression/test_unary.py +0 -0
  80. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_core.py +0 -0
  81. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_named_component.py +0 -0
  82. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_attributes.py +0 -0
  83. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_context.py +0 -0
  84. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_globals.py +0 -0
  85. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_globals_obj.py +0 -0
  86. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_globals_obj2.py +0 -0
  87. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_nested_dict.py +0 -0
  88. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_nested_node.py +0 -0
  89. {xcomponent-0.8.3 → xcomponent-0.9.0}/tests/unittests/test_render_script.py +0 -0
@@ -1,3 +1,14 @@
1
+ ## 0.9.0 - 2025-11-16
2
+
3
+ * Improve UUID support.
4
+ * Implement equality comparison
5
+ * Render uuid with hyphen
6
+ * Downcast uuid to python while running into_py
7
+
8
+ ## 0.8.4 - 2025-10-19
9
+
10
+ * Improve more messages extraction from nested fragment.
11
+
1
12
  ## 0.8.3 - 2025-10-18
2
13
 
3
14
  * Improve more messages extraction from nested expressions.
@@ -595,7 +595,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
595
595
 
596
596
  [[package]]
597
597
  name = "xcore"
598
- version = "0.8.3"
598
+ version = "0.9.0"
599
599
  dependencies = [
600
600
  "env_logger",
601
601
  "html-escape",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "xcore"
3
- version = "0.8.3"
3
+ version = "0.9.0"
4
4
  authors = ["Guillaume Gauvrit <guillaume@gauvr.it>"]
5
5
  edition = "2021"
6
6
  description = "JSX-like for python using maturin/pyo3 and pest."
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xcomponent
3
- Version: 0.8.3
3
+ Version: 0.9.0
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.11
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xcomponent"
3
- version = "0.8.3"
3
+ version = "0.9.0"
4
4
  description = "An embeded component base template engine - inspired by JSX"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Guillaume Gauvrit", email = "guillaume@gauvr.it" }]
@@ -151,7 +151,12 @@ impl Literal {
151
151
  .unbind()
152
152
  .into_bound_py_any(py)
153
153
  .unwrap(),
154
- Literal::Uuid(v) => v.clone().into_pyobject(py).unwrap().into_any(),
154
+ Literal::Uuid(v) => {
155
+ let uuidmod = PyModule::import(py, "uuid").unwrap();
156
+ let uuid_class = uuidmod.getattr("UUID").unwrap();
157
+ let args = (PyString::new(py, v.as_str()),);
158
+ uuid_class.call1(args).unwrap()
159
+ }
155
160
  Literal::Int(v) => v.clone().into_pyobject(py).unwrap().into_any(),
156
161
  Literal::Str(v) => v.clone().into_pyobject(py).unwrap().into_any(),
157
162
  Literal::XNode(v) => v.clone().into_pyobject(py).unwrap().into_any(),
@@ -220,7 +225,14 @@ impl ToHtml for Literal {
220
225
  Literal::Int(i) => Ok(format!("{}", i)),
221
226
  Literal::Str(s) => Ok(format!("{}", s)),
222
227
  Literal::Callable(s) => Ok(format!("{}()", s)),
223
- Literal::Uuid(uuid) => Ok(format!("{}", uuid)),
228
+ Literal::Uuid(uuid) => Ok(format!(
229
+ "{}-{}-{}-{}-{}",
230
+ &uuid[0..8],
231
+ &uuid[8..12],
232
+ &uuid[12..16],
233
+ &uuid[16..20],
234
+ &uuid[20..32]
235
+ )),
224
236
  Literal::List(l) => {
225
237
  let mut out = String::new();
226
238
  for item in l {
@@ -123,6 +123,7 @@ fn eval_raw_eq(l: Literal, r: Literal, op: String) -> PyResult<bool> {
123
123
  (Literal::Bool(a), Literal::Int(b)) => Ok(a as isize == b),
124
124
  (Literal::Bool(a), Literal::Bool(b)) => Ok(a == b),
125
125
  (Literal::Str(a), Literal::Str(b)) => Ok(a == b),
126
+ (Literal::Uuid(a), Literal::Uuid(b)) => Ok(a == b),
126
127
  (Literal::None(()), Literal::None(())) => Ok(true),
127
128
  (Literal::None(()), _) => Ok(false),
128
129
  (_, Literal::None(())) => Ok(false),
@@ -301,8 +301,25 @@ fn extract_from_ast(ast: AST) -> PyResult<Vec<ExtractedMessage>> {
301
301
  }
302
302
  AST::Literal(Literal::XNode(XNode::Fragment(node))) => {
303
303
  for child in node.children() {
304
- if let XNode::Expression(expr) = child {
305
- res.extend(extract_expr_i18n_messages(expr.expression())?);
304
+ match child {
305
+ XNode::Expression(expr) => {
306
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
307
+ }
308
+ XNode::Element(node) => {
309
+ for child in node.attrs().values() {
310
+ if let XNode::Expression(expr) = child {
311
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
312
+ }
313
+ }
314
+ for child in node.children() {
315
+ if let XNode::Expression(expr) = child {
316
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
317
+ }
318
+ }
319
+ }
320
+ _ => {
321
+ warn!("Ignoring {:?} while extracting messages", child);
322
+ }
306
323
  }
307
324
  }
308
325
  }
@@ -331,7 +331,36 @@ empty_comment: list[str] = []
331
331
  empty_comment,
332
332
  ),
333
333
  ],
334
- id="nested diamon",
334
+ id="nested diamond",
335
+ ),
336
+ pytest.param(
337
+ """
338
+ <BaseLayout>
339
+ {
340
+ if authenticated {
341
+ <>
342
+ {globals.username}
343
+ -
344
+ <A href={globals.request.route_path('sign_out')} hx-disable>
345
+ {globals.pgettext("Sign out header link", "Sign Out")}
346
+ </A>
347
+ </>
348
+ }
349
+ }
350
+ </BaseLayout>
351
+ """,
352
+ [
353
+ (
354
+ 1,
355
+ "pgettext",
356
+ (
357
+ "Sign out header link",
358
+ "Sign Out",
359
+ ),
360
+ empty_comment,
361
+ ),
362
+ ],
363
+ id="if nested diamond",
335
364
  ),
336
365
  pytest.param(
337
366
  """
@@ -1,4 +1,5 @@
1
1
  import pytest
2
+ from uuid import UUID
2
3
 
3
4
  from xcomponent import Catalog
4
5
 
@@ -6,7 +7,7 @@ catalog = Catalog()
6
7
 
7
8
 
8
9
  @catalog.component
9
- def Eq(a: int | bool | str, b: int | bool | str) -> str:
10
+ def Eq(a: int | bool | str, b: int | bool | str | UUID) -> str:
10
11
  return """<>{a == b}</>"""
11
12
 
12
13
 
@@ -50,6 +51,8 @@ def Lte(a: int | bool | str, b: int | bool | str) -> str:
50
51
  pytest.param(Eq(True, True), "true", id="add true-true"),
51
52
  pytest.param(Eq("1", "2"), "false", id="str-false"),
52
53
  pytest.param(Eq("1", "1"), "true", id="str-true"),
54
+ pytest.param(Eq(UUID(int=1), UUID(int=1)), "true", id="uuid-true"),
55
+ pytest.param(Eq(UUID(int=1), UUID(int=2)), "false", id="uuid-false"),
53
56
  pytest.param(Eq("", None), "false", id="str-None"),
54
57
  pytest.param(Eq(None, None), "true", id="None-None"),
55
58
  ],
@@ -1,3 +1,4 @@
1
+ from dataclasses import dataclass
1
2
  from typing import TypedDict
2
3
  from uuid import UUID
3
4
  from xcomponent import Catalog
@@ -43,6 +44,23 @@ def DynamicKeyDictComplexType(
43
44
  return """<>{products[product_id].owner.username}</>"""
44
45
 
45
46
 
47
+ @dataclass
48
+ class UserModel:
49
+ username: str
50
+
51
+
52
+ @dataclass
53
+ class ProductModel:
54
+ user_id: UUID
55
+
56
+
57
+ @catalog.component
58
+ def DynamicKeyDictComplexType2(
59
+ users: dict[UUID, UserModel], product: ProductModel
60
+ ) -> str:
61
+ return """<>{users[product.user_id].username}</>"""
62
+
63
+
46
64
  @catalog.component
47
65
  def DynamicKeyListComplexType(users: list[User], user_id: int) -> str:
48
66
  return """<>{users[user_id].username}</>"""
@@ -53,7 +71,7 @@ def DynamicKeyListComplexType(users: list[User], user_id: int) -> str:
53
71
  [
54
72
  pytest.param(
55
73
  Types(False, True, 2, "3", UUID(int=4), DummyNode(a="5")),
56
- "false-true-2-3-00000000000000000000000000000004-<p>5</p>",
74
+ "false-true-2-3-00000000-0000-0000-0000-000000000004-<p>5</p>",
57
75
  id="simpletypes",
58
76
  ),
59
77
  pytest.param(
@@ -114,6 +132,18 @@ def DynamicKeyListComplexType(users: list[User], user_id: int) -> str:
114
132
  "bernard",
115
133
  id="key-dict-int",
116
134
  ),
135
+ pytest.param(
136
+ DynamicKeyDictComplexType2(
137
+ users={
138
+ UUID(int=1): User(username="alice"),
139
+ UUID(int=2): User(username="bob"),
140
+ UUID(int=3): User(username="bernard"),
141
+ },
142
+ product=ProductModel(user_id=UUID(int=3)),
143
+ ),
144
+ "bernard",
145
+ id="nested-attribute-with-dataclass",
146
+ ),
117
147
  ],
118
148
  )
119
149
  def test_types(component: str, expected: str):
@@ -1,7 +1,8 @@
1
- from xcomponent import Catalog, Component, XNode
1
+ from uuid import UUID
2
2
 
3
3
  import pytest
4
4
  from bs4 import PageElement # type: ignore
5
+ from xcomponent import Catalog, Component, XNode
5
6
 
6
7
 
7
8
  @pytest.fixture(autouse=True)
@@ -31,6 +32,20 @@ def Section(catalog: Catalog):
31
32
  return Section
32
33
 
33
34
 
35
+ @pytest.fixture(autouse=True)
36
+ def Paragraph(catalog: Catalog):
37
+ @catalog.component
38
+ def Paragraph() -> str:
39
+ return """
40
+ <>
41
+ <p>The lazy <strong>dog</strong> jump over...</p>
42
+ <p>the lazy dog jumped over the <em>quick brown fox</em>.</p>
43
+ </>
44
+ """
45
+
46
+ return Paragraph
47
+
48
+
34
49
  @pytest.fixture(autouse=True)
35
50
  def HtmlHead(catalog: Catalog):
36
51
  @catalog.component
@@ -80,6 +95,17 @@ def Layout(catalog: Catalog):
80
95
  return Layout
81
96
 
82
97
 
98
+ @pytest.fixture(autouse=True)
99
+ def RenderUuid(catalog: Catalog):
100
+ @catalog.component
101
+ def RenderUuid(uuid: UUID) -> str:
102
+ return """
103
+ <input value={uuid}/>
104
+ """
105
+
106
+ return RenderUuid
107
+
108
+
83
109
  def test_render_h1(catalog: Catalog):
84
110
  assert catalog.render('<H1 title="Hello, world!" />') == "<h1>Hello, world!</h1>"
85
111
 
@@ -94,12 +120,26 @@ def test_render_h2(catalog: Catalog):
94
120
  )
95
121
 
96
122
 
123
+ def test_render_uuid(catalog: Catalog):
124
+ assert (
125
+ catalog.render("<RenderUuid uuid={val} />", val=UUID(int=1))
126
+ == '<input value="00000000-0000-0000-0000-000000000001"/>'
127
+ )
128
+
129
+
97
130
  def test_render_children(catalog: Catalog):
98
131
  assert (
99
132
  catalog.render("<Section />") == "<div><h1>hello</h1><h2>I - world</h2></div>"
100
133
  )
101
134
 
102
135
 
136
+ def test_render_whitespace(catalog: Catalog):
137
+ assert catalog.render("<Paragraph />") == (
138
+ "<p>The lazy <strong>dog</strong> jump over...</p>"
139
+ "<p>the lazy dog jumped over the <em>quick brown fox</em>.</p>"
140
+ )
141
+
142
+
103
143
  def test_render_children_param(catalog: Catalog, Layout: Component):
104
144
  # ensure we cam remder the HtmlHead before continuing
105
145
  assert catalog.render('<HtmlHead title="happy world" />') == (
@@ -1407,7 +1407,7 @@ wheels = [
1407
1407
 
1408
1408
  [[package]]
1409
1409
  name = "xcomponent"
1410
- version = "0.8.3"
1410
+ version = "0.9.0"
1411
1411
  source = { editable = "." }
1412
1412
 
1413
1413
  [package.optional-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes