pyodide-mkdocs-theme 5.3.6__py3-none-any.whl → 5.4.1__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.
Files changed (38) hide show
  1. pyodide_mkdocs_theme/__main__.py +9 -6
  2. pyodide_mkdocs_theme/__version__.py +1 -1
  3. pyodide_mkdocs_theme/pyodide_macros/macros/figure.py +0 -3
  4. pyodide_mkdocs_theme/pyodide_macros/macros/ide_manager.py +169 -65
  5. pyodide_mkdocs_theme/pyodide_macros/macros/ide_term_ide.py +3 -1
  6. pyodide_mkdocs_theme/pyodide_macros/macros/ide_tester.py +6 -8
  7. pyodide_mkdocs_theme/pyodide_macros/macros/qcm.py +0 -2
  8. pyodide_mkdocs_theme/pyodide_macros/messages/de_lang.py +162 -126
  9. pyodide_mkdocs_theme/pyodide_macros/messages/en_lang.py +162 -126
  10. pyodide_mkdocs_theme/pyodide_macros/messages/fr_lang.py +166 -128
  11. pyodide_mkdocs_theme/pyodide_macros/messages/proxy.py +1 -1
  12. pyodide_mkdocs_theme/pyodide_macros/parsing.py +0 -2
  13. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_base.py +14 -18
  14. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_contracts.py +240 -7
  15. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_templates.py +13 -12
  16. pyodide_mkdocs_theme/pyodide_macros/plugin_config/definitions/macros_configs.py +7 -3
  17. pyodide_mkdocs_theme/pyodide_macros/plugin_config/definitions/plugin_config.py +5 -4
  18. pyodide_mkdocs_theme/pyodide_macros/plugin_config/definitions/sub_configs.py +213 -38
  19. pyodide_mkdocs_theme/pyodide_macros/plugin_config/plugin_config_src.py +3 -0
  20. pyodide_mkdocs_theme/pyodide_macros/tools_and_constants.py +73 -5
  21. pyodide_mkdocs_theme/scripts/de/mkdocs.yml +12 -6
  22. pyodide_mkdocs_theme/scripts/en/mkdocs.yml +12 -6
  23. pyodide_mkdocs_theme/scripts/fr/mkdocs.yml +12 -6
  24. pyodide_mkdocs_theme/scripts/models/main.py +23 -40
  25. pyodide_mkdocs_theme/scripts/models/mkdocs.yml +12 -6
  26. pyodide_mkdocs_theme/templates/js-libs/0-config.js +58 -50
  27. pyodide_mkdocs_theme/templates/js-libs/functools.js +47 -2
  28. pyodide_mkdocs_theme/templates/js-libs/process_and_gui.js +32 -18
  29. pyodide_mkdocs_theme/templates/js-per-pages/4-ideRunner-ide.js +2 -2
  30. pyodide_mkdocs_theme/templates/js-per-pages/qcms-qcm.js +12 -8
  31. {pyodide_mkdocs_theme-5.3.6.dist-info → pyodide_mkdocs_theme-5.4.1.dist-info}/METADATA +1 -1
  32. {pyodide_mkdocs_theme-5.3.6.dist-info → pyodide_mkdocs_theme-5.4.1.dist-info}/RECORD +35 -38
  33. pyodide_mkdocs_theme/scripts/de/main.py +0 -141
  34. pyodide_mkdocs_theme/scripts/en/main.py +0 -140
  35. pyodide_mkdocs_theme/scripts/fr/main.py +0 -144
  36. {pyodide_mkdocs_theme-5.3.6.dist-info → pyodide_mkdocs_theme-5.4.1.dist-info}/LICENSE +0 -0
  37. {pyodide_mkdocs_theme-5.3.6.dist-info → pyodide_mkdocs_theme-5.4.1.dist-info}/WHEEL +0 -0
  38. {pyodide_mkdocs_theme-5.3.6.dist-info → pyodide_mkdocs_theme-5.4.1.dist-info}/entry_points.txt +0 -0
@@ -67,9 +67,10 @@ parser.add_argument(
67
67
  parser.add_argument(
68
68
  '--lang', action='extend', nargs='*', choices=LANGS, default=[],
69
69
  help=f'Optional. Choices: { ", ".join(LANGS) }. '
70
- 'Print the base python code to customize some messages. '
71
- 'Can also be used with other arguments to get the information in languages other '
72
- 'than "fr", when relevant.'
70
+ 'Can be used with other arguments to get the information/files in languages other '
71
+ 'than "fr", when relevant. '
72
+ '([DEPRECATED]: Print the base python code to customize some messages. From PMT 5.3.0, '
73
+ "use the plugin's configuration to change PMT messages.)"
73
74
  )
74
75
  parser.add_argument( # Effect strictly equivalent to --lang, but present for semantic
75
76
  '-M', '--macros', action='store_true',
@@ -247,8 +248,7 @@ def main():
247
248
  'plot': 'pyodide_plot.py',
248
249
  'py': 'docs/exo.py',
249
250
  'toolbox': 'toolbox.py',
250
- 'yml': 'mkdocs.yml',
251
- 'lang': 'main.py' ,
251
+ 'yml': 'mkdocs.yml'
252
252
  }
253
253
 
254
254
  if args.basthonP5:
@@ -282,7 +282,10 @@ def main():
282
282
 
283
283
  if not did_some and args.lang:
284
284
  did_some = True
285
- handle_one_file(args, 'lang')
285
+ print(
286
+ "From PMT 5.3.0, you should update Lang messages directly through the plugin's configuration. "
287
+ "The old `env.lang.overload` way is still supported, but it should not be used anymore."
288
+ )
286
289
 
287
290
 
288
291
  if raise_toolbox:
@@ -1 +1 @@
1
- __version__ = "5.3.6"
1
+ __version__ = "5.4.1"
@@ -22,9 +22,6 @@ If not, see <https://www.gnu.org/licenses/>.
22
22
  from functools import wraps
23
23
  from typing import Optional
24
24
 
25
- from mkdocs.exceptions import BuildError
26
-
27
-
28
25
 
29
26
  from ..tools_and_constants import MACROS_WITH_INDENTS, HtmlClass, P5BtnLocation
30
27
  from .. import html_builder as Html
@@ -528,6 +528,12 @@ class IdeManagerMdHtmlGenerator(IdeSectionsManager):
528
528
  Generic html handling (ids, buttons, ...)
529
529
  """
530
530
 
531
+ FORCE_PROJECT_ID_IN_HASH: ClassVar[bool] = False
532
+ """
533
+ Some kind of IDEs (generated ones: IDE_tester, IDE_playground) have to use the project id,
534
+ otherwise their html id _will_ always collide between different projects.
535
+ """
536
+
531
537
  editor_name: str = ''
532
538
  """ tail part of most html elements' ids, in the shape of 'editor_{32 bits hexadecimal}' """
533
539
 
@@ -546,89 +552,187 @@ class IdeManagerMdHtmlGenerator(IdeSectionsManager):
546
552
 
547
553
 
548
554
 
549
- def generate_id(self):
555
+ def _build_string_to_be_hashed(self):
550
556
  """
551
- Generate an id number for the current element, in the form:
557
+ Generate hash part of the html id for the current element, in the form:
552
558
 
553
559
  "{ self.PREFIX_ }{ 32 chars hex value }"
554
560
 
561
+ Uniqueness of the resulting hash is verified and PmtMacrosNonUniqueIdError is raised
562
+ if two identical hashes are encountered.
563
+
564
+ ---
565
+
555
566
  <br><br>
556
567
 
557
- ## CONSTRAINTS:
568
+ ## CONSTRAINTS on the html ids:
558
569
 
559
- - Unique to every runner used throughout the whole website.
560
- - Stable, so that it can be used to identify what IDE goes with what file or what
570
+ 1. Stable, so that it can be used to identify what IDE goes with what file or what
561
571
  localStorage data.
562
- - For IDEs:
563
- * It must be possible to differentiate IDEs from different pages using the same
564
- base python file
565
- * It must be possible to identify unambiguously IDEs in different pages that do
566
- not use any python file.
572
+
573
+ 2. Unique to every runner used throughout the whole website, and specifically for IDEs:
574
+ * IDEs using the same python file in different pages must have different ids.
575
+ * IDEs NOT using any python file must have different ids in any page.
576
+ * The uniqueness of the ids across different PMT projects should be "guaranteed"
577
+ if they are hosted on the same domain, so that IDEs of different projects do not
578
+ override each others in the localStorage.
579
+
580
+ 3. It must be possible to guarantee the backward compatibility if the id values when
581
+ desired by the redactor. It may not be possible for all projects at the same time after
582
+ the update to 5.4+, but redactors should have a way to maintain them when it's possible.
583
+
584
+ 4. If ever two identical ids from different projects are found at runtime (JS layer), the
585
+ user should be warned, with sufficient information to correct the problem (aka, adding an
586
+ ID argument to the IDE of the current project => this IDE must be fully identifiable).
587
+ This is not handled in the `generate_id` method.
588
+
589
+ ---
567
590
 
568
591
  <br><br>
569
592
 
570
- ## STRATEGIES:
571
-
572
- NOTE: The cache has been deactivated manually and isn't accessible to the user
573
- anymore, but the implementation still makes reference to it, if ever I put
574
- it back in place, one day... (unlikely: removed because mainly useless).
575
-
576
- The string to hash is built in the following ways:
577
- - For elements with python file(s):
578
- * use the absolute path (unresolved) to the main side fail (first argument if
579
- `py_names` is a varargs).
580
- * non IDE macros see the macro name added to the string (to differentiate them
581
- from IDEs, while keeping backward compatibility for IDEs' ids)
582
- * the ID argument _will_ often be needed to differentiate the runners/macros,
583
- while allowing cache capabilities without much ambiguity when the user is
584
- adding, deleting or moving macro calls around in the md page.
585
- This can be turned down with `build.activate_cache: false`: then all non IDE
586
- macros fall back to the behavior below.
587
- * IDEs specific: the "mode" (/_v) is appended to the string before hashing (legacy).
588
-
589
- - For elements without a python file, or for non IDEs with `build.activate_cache: false`:
590
- * use the page url, with the macro name, then a counter of that kind of macro calls.
591
-
592
- Uniqueness of the resulting hash is verified and BuildError is raised if two identical
593
- hashes are encountered.
594
- """
595
- is_ide = PmtPyMacrosName.is_ide(self.MACRO_NAME)
593
+ ## RATIONALS:
596
594
 
597
- if self.exo_py and (is_ide or self.env.ACTIVATE_CACHE):
598
- # IDE ids have to stay consistent with previous implementations, to not brake the
599
- # localeStorage saves of the users.
600
595
 
601
- # The macro name is added in the string generating the hash for non IDE elements,
602
- # so that using the same source file for different kind of macros won't generate
603
- # equivalent hashes (ease the way for the users, _and_ more consistent with previous
604
- # behaviors... Even if that is probably a breaking change).
605
- less_ID_needs = "" if is_ide else ':'+self.MACRO_NAME
596
+ An id redundancy can occur in the following cases:
597
+
598
+ * IDEs without python files at the same location in the docs_dir will result in
599
+ identical html ids, whatever the `ides_id_hash_mode` value.
600
+
601
+ * With `ides_id_hash_mode: relative`, ides at equivalent locations in the docs_dir
602
+ and using the same python file (name/location) and the same ID argument will result
603
+ in two identical html ids.
604
+
605
+ Note that, using `ides_id_hash_mode: legacy`, the redundancy is limited to the
606
+ intrinsic hash collision probability, so almost non existant. So no need to
607
+ disambiguate IDE WITH python files in that mode. Though, a project_id value will
608
+ still be needed to disambiguate entries in the localStorage when using the trashcan
609
+ button, if several PMT projects are hosted on the same domain.
610
+
611
+ So, the chosen strategies are the following:
612
+
613
+ ---
614
+
615
+ For non IDEs elements:
616
+
617
+ - They don't have to worry about the multi-projects aspects. Ids unique throughout the
618
+ page are more than enough.
619
+ - Consistency of the generated ids through time is more important than anything else.
620
+ - The ids are built using:
621
+ * the page url (relative to the docs_dir).
622
+ * the macro name (so that the counts for IDEs is not affected by adding other
623
+ elements earlier in the page -> stability guarantee).
624
+ * a counter specific to the macro name and the page
625
+
626
+
627
+ For IDE elements:
606
628
 
607
- runner_path = self.exo_py
608
- if is_ide and not HashPathMode.is_legacy(self.env):
609
- # Avoid any dependency on the domain/site name, if needed:
629
+ - Priority must be given to the consistency of the ids through time, WHEN POSSIBLE.
630
+ - Second most important property is uniqueness across the localStorage, meaning handling
631
+ the multi-projects aspects is a "must have", at the best possible extent.
632
+
633
+ For IDE elements without associated python file:
634
+
635
+ - These are more often subject to side effects across different projects, because the
636
+ html ids are generated using the PAGE URL (relative to the docs_dir), concatenated with
637
+ various things that are specific to the page or the macro. So different website with the
638
+ same relative URL _will_ clash in the localStorage. These require the use of a project_id
639
+ value.
640
+ - Note that the value of `ides_id_hash_mode` has no effect on these IDEs and these actually
641
+ behave the same way as IDEs with python files and `ides_id_hash_mode: relative` is used,
642
+ hence the previous point.
643
+
644
+ For IDE elements with a python file:
645
+
646
+ - The python file location is used in "unresolved" fashion, whatever the value of
647
+ `ides_id_hash_mode` is. Meaning: `xxx/A/../B/exo.py` is used as is, instead of resolving
648
+ it to `xxx/B/exo.py`. This allows to reduce the occurrences where the ID argument has to
649
+ be added to the macro call.
650
+ - Projects using `ides_id_hash_mode: legacy`, despite all the problems that go with it,
651
+ are not subject to localStorage ids clashes for these IDEs, BUT, the trashcan button still
652
+ requires the project_id value to differentiate the source of each entry.
653
+ <br>This means the user CAN maintain backward compatibility of the ids by skipping the
654
+ project_id part when building the hash, even if it has been provided for the trashcan
655
+ functionality. The `project_disambiguate_local_storage` option allow to control this.
656
+ - For legacy reasons (PM), ids for IDEv macros see the `"_v"` element added to the string
657
+ before the hash is computed. THIS IS NOT APPLIED to IDEv WITHOUT PYTHON FILE (PMT legacy).
658
+ - Projects using `ides_id_hash_mode: relative` ARE way more subject to ids clashes, so the
659
+ project_id has to be used.
660
+
661
+ For backward compatibility, the redactor has two options:
662
+ 1. Set the project id of one project to `""` and maintain backward compatibility for this
663
+ project, and use a unique value for other projects. These will get new ids for all IDEs
664
+ with a python file and the localStorage content will be lost.
665
+ 2. Set `project_disambiguate_local_storage` to False along with a project_id value for
666
+ each project. This is kinda "relying on luck", but could work well enough: the redactor
667
+ hopes a minimal number of clashes and waits for the users to signal the troubles when they
668
+ occur, so that they can fix the clashes individually by adding ID arguments where needed.
669
+
670
+ ---
671
+
672
+ ___NOTE about the cache:___
673
+
674
+ The cache has been deactivated manually and isn't accessible to the user anymore, but the
675
+ implementation still makes reference to it, if ever I put it back in place, one day...
676
+ (unlikely: removed because mainly useless, by now).
677
+
678
+
679
+ ___NOTE about `ides_id_hash_mode: legacy`:___
680
+
681
+ The `runner_path` (to the python file) used in that case is "absolute + unresolved".
682
+ <br>When building the site during a pipeline, the paths look like this:
683
+
684
+ /builds/frederic-zinelli/pyodide-mkdocs-theme/docs/redactors/sequential_examples/ide4.py
685
+
686
+ This has kind of "opposite" consequences:
687
+
688
+ 1. The ids are automatically disambiguated considering different projects hosted in the same
689
+ GtiLab account/group, and probabilities of hashes collisions,event if not inexistant, are
690
+ probabilistically close to zero.
691
+
692
+ 2. When using `mkdocs serve`:
693
+ - The ids during serve ARE NOT IDENTICAL to those of the same IDE on the online site.
694
+ - The localStorage during serve sees ALL the IDEs entries of ALL the projects on the
695
+ local machine.
696
+ """
697
+ is_ide = PmtPyMacrosName.is_ide(self.MACRO_NAME)
698
+ is_relative = not self.env.is_legacy
699
+ runner_path = self.exo_py
700
+ has_py_file = bool(runner_path)
701
+ project_id = self.env.project_id or ""
702
+
703
+ need_project_id = is_ide and self.env.project_disambiguate_local_storage and project_id and (
704
+ not has_py_file or is_relative
705
+ ) or self.FORCE_PROJECT_ID_IN_HASH
706
+ # The project_id is needed to disambiguate the html ids in the localStorage only if:
707
+ # 1. The element is an IDE
708
+ # 2. The user actually gave a value for env.project_id
709
+ # 3. The user _wants_ the project_id added to compute the html ids
710
+ # 4. Either...:
711
+ # - the ides_id_hash_mode is set to relative
712
+ # - Or there is no python file for the IDE
713
+
714
+ project_id = f':_{ project_id }' * bool(need_project_id)
715
+
716
+ if has_py_file and (is_ide or self.env.ACTIVATE_CACHE):
717
+
718
+ less_ID_needs = "" if is_ide else ':'+self.MACRO_NAME
719
+ if is_ide and is_relative:
610
720
  runner_path = Path(self.exo_py).relative_to(self.env.docs_dir_path)
611
721
 
612
- to_hash = f"{ runner_path }{ self.IDE_VERT }{ less_ID_needs }"
613
- # PROBLEM for IDEs in ides_id_hash_mode:"legacy":
614
- #
615
- # `runner_path` is "absolute unresolved", in that case. When building the site during
616
- # a pipeline, the paths look like this:
617
- #
618
- # /builds/frederic-zinelli/pyodide-mkdocs-theme/docs/redactors/sequential_examples/ide4.py
619
- #
620
- # This means the ids are disambiguated considering different projects hosted in the same
621
- # GtiLab account/group, and probabilities of hashes collisions are not inexistant, but
622
- # probabilistically close to zero.
722
+ to_hash = f"{ runner_path }{ self.IDE_VERT }{ less_ID_needs }{ project_id }"
623
723
 
624
724
  else:
625
725
  count = self.env.macros_counters[ self.MACRO_NAME ].inc()
626
- to_hash = f"{ self.env.page.url }-{ self.MACRO_NAME }-{ count }"
627
- # DO NOT lstrip, even if it looks ugly on the home page (nobody but me can see
628
- # it anyway... :rolleyes:), to keep implementation consistent for users...
726
+ to_hash = f"{ self.env.page.url }-{ self.MACRO_NAME }-{ count }{ project_id }"
727
+ # DO NOT lstrip `to_hash`, to keep implementation consistent for users, even if it
728
+ # looks ugly on the home page (url is ""). Nobody but me can see it anyway... :rolleyes:
729
+
730
+ return to_hash
629
731
 
630
- hashed = self.id_to_hash(to_hash)
631
- # print(hashed, to_hash)
732
+
733
+ def generate_id(self):
734
+ to_hash = self._build_string_to_be_hashed()
735
+ hashed = self.id_to_hash(to_hash)
632
736
  return hashed
633
737
 
634
738
 
@@ -652,11 +756,11 @@ class IdeManagerMdHtmlGenerator(IdeSectionsManager):
652
756
  "The same html id got generated twice.\n"
653
757
  "If you are trying to use the same set of files for different macros calls, use "
654
758
  "their ID argument (int >= 0) to disambiguate them.\n\n"
655
- )+ self.env.ACTIVATE_CACHE*(
759
+ ) + self.env.ACTIVATE_CACHE * (
656
760
  "If you are encountering this problem with macros other than IDE or IDEv and you "
657
761
  "do not need some extra speed rendering-wise, you also can deactivate the PMT "
658
762
  f"cache, using `{ cache_option }: false`.\n\n"
659
- )+(
763
+ ) + (
660
764
  f"ID values already in use: { self.env.get_registered_ids_for(id_path) }\n"
661
765
  f"Id generated with: { to_hash }\n{ self.env.log() }"
662
766
  )
@@ -19,7 +19,7 @@ If not, see <https://www.gnu.org/licenses/>.
19
19
 
20
20
 
21
21
  from abc import ABCMeta
22
- from typing import Optional
22
+ from typing import ClassVar, Optional
23
23
 
24
24
 
25
25
  from .. import html_builder as Html
@@ -67,6 +67,8 @@ _BTN_MATERIAL_OVERFLOW = admonition_safe_html('''
67
67
 
68
68
  class CommonGeneratedIde(IdeManager, metaclass=ABCMeta):
69
69
 
70
+ FORCE_PROJECT_ID_IN_HASH: ClassVar[bool] = True
71
+
70
72
  @classmethod
71
73
  def get_markdown(cls, use_mermaid:bool):
72
74
  raise NotImplementedError()
@@ -20,17 +20,15 @@ If not, see <https://www.gnu.org/licenses/>.
20
20
 
21
21
  import json
22
22
  from dataclasses import dataclass, field
23
- import re
24
23
  from textwrap import dedent
25
- from typing import Any, Callable, ClassVar, Dict, Iterator, List, TYPE_CHECKING, NewType, Optional, Tuple, Type
24
+ from typing import Any, ClassVar, Dict, List, TYPE_CHECKING, NewType, Optional, Tuple, Type
26
25
 
27
26
 
28
27
 
29
28
 
30
29
 
31
- from ..exceptions import PmtMacrosInvalidArgumentError
32
30
  from .. import html_builder as Html
33
- from ..tools_and_constants import HtmlClass, PageUrl, PmtPyMacrosName, PageInclusion, Prefix, Qcm, ScriptSection, ScriptData
31
+ from ..tools_and_constants import HtmlClass, PageUrl, PmtPyMacrosName, PageInclusion, Prefix, Qcm, ScriptData
34
32
  from ..parsing import compress_LZW
35
33
  from ..html_dependencies.deps_class import DepKind
36
34
  from ..plugin_tools.test_cases import Case
@@ -121,12 +119,12 @@ class IdeTester(CommonGeneratedIde, Ide):
121
119
  Build the code generating the IdeTester object. Insert the MERMAID logistic only if
122
120
  the `mkdocs.yml` holds the custom fences code configuration.
123
121
  """
124
- return dedent(f"""
125
- # Testing all IDEs in the documentation {'{'} data-search-exclude {'}'}
122
+ return dedent(f"""\
123
+ # Testing all IDEs in the documentation {'{'} data-search-exclude {'}'}
126
124
 
127
- <br>
125
+ <br>
128
126
 
129
- {'{{'} IDE_tester(MAX='+', MERMAID={ use_mermaid }, TERM_H=15) {'}}'}
127
+ {'{{'} IDE_tester(MAX='+', MERMAID={ use_mermaid }, TERM_H=15) {'}}'}
130
128
 
131
129
  """)
132
130
 
@@ -22,8 +22,6 @@ from functools import wraps
22
22
  from textwrap import dedent
23
23
  from typing import Any, Dict, List, Tuple
24
24
 
25
- from mkdocs.exceptions import BuildError
26
-
27
25
 
28
26
  from ..pyodide_logger import logger
29
27
  from ..tools_and_constants import MACROS_WITH_INDENTS, HtmlClass, IdeConstants