bakefile 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl

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.
@@ -1,8 +1,15 @@
1
1
  import types
2
2
  from pathlib import Path
3
3
 
4
+ from bake.samples import simple
4
5
  from bake.utils.constants import BAKEBOOK_NAME_IN_SAMPLES
5
6
 
7
+ # Allowed sample modules
8
+ # This dictionary acts as a whitelist for security - only these modules can be used
9
+ ALLOWED_SAMPLE_MODULES: dict[str, types.ModuleType] = {
10
+ simple.__name__: simple,
11
+ }
12
+
6
13
 
7
14
  def write_bakefile(
8
15
  bakefile_path: Path, bakebook_name: str, sample_module: types.ModuleType
@@ -12,9 +19,21 @@ def write_bakefile(
12
19
  f"Module `{sample_module.__name__}` must have `{BAKEBOOK_NAME_IN_SAMPLES}` attribute"
13
20
  )
14
21
 
15
- if sample_module.__file__ is None:
16
- raise ValueError(f"Could not find `{sample_module.__name__}`")
22
+ module_name = sample_module.__name__
23
+ if module_name not in ALLOWED_SAMPLE_MODULES:
24
+ raise ValueError(
25
+ f"Module `{module_name}` is not in the allowed sample modules list. "
26
+ f"Allowed modules: {list(ALLOWED_SAMPLE_MODULES.keys())}"
27
+ )
28
+
29
+ allowed_module = ALLOWED_SAMPLE_MODULES[module_name]
30
+ if sample_module is not allowed_module:
31
+ raise ValueError(f"Module `{module_name}` does not match the allowed module object")
32
+
33
+ if allowed_module.__file__ is None:
34
+ raise ValueError(f"Could not find file for module `{module_name}`")
17
35
 
18
- original_bakefile_content = Path(sample_module.__file__).read_text()
36
+ source_file_path = Path(allowed_module.__file__)
37
+ original_bakefile_content = source_file_path.read_text()
19
38
  customized_content = original_bakefile_content.replace(BAKEBOOK_NAME_IN_SAMPLES, bakebook_name)
20
39
  bakefile_path.write_text(customized_content)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bakefile
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: Add your description here
5
5
  Author: Wisaroot Lertthaweedech
6
6
  Author-email: Wisaroot Lertthaweedech <l.wisaroot@gmail.com>
@@ -31,7 +31,7 @@ bake/manage/add_inline.py,sha256=yefHmF33ghCB8NZ-v61ybeVsaeE8iDFvfRGeTAKg4I8,224
31
31
  bake/manage/find_python.py,sha256=oVmd8KaSsgDQWHuGZpYiQx-DHn50P9EkRi6-YIad99E,7165
32
32
  bake/manage/lint.py,sha256=OqwYFF8GGvzHGVPuJcWMRAv5esXEIX4nQXdGcChnkqA,2394
33
33
  bake/manage/run_uv.py,sha256=QzlKeVpr20dXNDcwUgyJqnXT4MofRqK-6XkWpzBbUhE,3234
34
- bake/manage/write_bakefile.py,sha256=efGViLk7sh-QX9Mox7yQw_A1Tp7EOuc_vmSTbFmXUm0,736
34
+ bake/manage/write_bakefile.py,sha256=ZlBL2XBy0XIY8_4t56szvq2c6-DwEyRuNljjZI3m0ls,1487
35
35
  bake/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
36
  bake/samples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  bake/samples/simple.py,sha256=hP2TW-D7BQBGJseqRPpilxkoQ8ScTuZZePICupyvFKA,155
@@ -57,7 +57,7 @@ bakelib/space/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  bakelib/space/base.py,sha256=bJlpPkP85xBu8X5fJoVaHrMzX27rQrYTEPSObwBANJ8,6008
58
58
  bakelib/space/python.py,sha256=UEr4Jo76T2cbAQdClVu7RvJYzflLE9i_xFohcNhjFjw,2597
59
59
  bakelib/space/utils.py,sha256=xx4X_txhDH_p97CKJ-KuvFpgfNBC0y_din1IBlUVusU,2983
60
- bakefile-0.0.6.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
61
- bakefile-0.0.6.dist-info/entry_points.txt,sha256=Ecvvh7BYHCPJ0UdntrDc3Od6AZdRPXN5Z7o_7ok_0Qw,107
62
- bakefile-0.0.6.dist-info/METADATA,sha256=6tec3_eRxbtTAsdHJHUC1Vo4yIondUR_U28oRq2Cp1c,2331
63
- bakefile-0.0.6.dist-info/RECORD,,
60
+ bakefile-0.0.7.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
61
+ bakefile-0.0.7.dist-info/entry_points.txt,sha256=Ecvvh7BYHCPJ0UdntrDc3Od6AZdRPXN5Z7o_7ok_0Qw,107
62
+ bakefile-0.0.7.dist-info/METADATA,sha256=zVQg9_SCgUUvIT_rosZIW8pf658SG3pDTfyp4I5qMek,2331
63
+ bakefile-0.0.7.dist-info/RECORD,,