markdown-include-variants 0.0.1__tar.gz → 0.0.3__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 (62) hide show
  1. markdown_include_variants-0.0.1/.github/workflows/check-labels.yml → markdown_include_variants-0.0.3/.github/workflows/labeler.yml +13 -1
  2. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/workflows/publish.yml +1 -1
  3. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/workflows/smokeshow.yml +2 -1
  4. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/workflows/test.yml +5 -5
  5. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/PKG-INFO +39 -10
  6. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/README.md +38 -9
  7. markdown_include_variants-0.0.3/release-notes.md +28 -0
  8. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/src/markdown_include_variants/_main.py +69 -27
  9. markdown_include_variants-0.0.3/src/markdown_include_variants/_version.py +1 -0
  10. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_all_variants.py +7 -7
  11. markdown_include_variants-0.0.3/tests/test_another_preferred_variant.py +57 -0
  12. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_no_py39.py +1 -1
  13. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_only_py310.py +1 -1
  14. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_only_py_no_an.py +1 -1
  15. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_simple_ln_hl.py +11 -11
  16. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_up_to_py39.py +3 -3
  17. markdown_include_variants-0.0.1/.github/workflows/add-labels.yml +0 -16
  18. markdown_include_variants-0.0.1/release-notes.md +0 -3
  19. markdown_include_variants-0.0.1/src/markdown_include_variants/_version.py +0 -1
  20. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/DISCUSSION_TEMPLATE/questions.yml +0 -0
  21. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/FUNDING.yml +0 -0
  22. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  23. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/ISSUE_TEMPLATE/privileged.yml +0 -0
  24. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/dependabot.yml +0 -0
  25. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/labeler.yml +0 -0
  26. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/workflows/issue-manager.yml +0 -0
  27. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.github/workflows/latest-changes.yml +0 -0
  28. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.gitignore +0 -0
  29. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.pre-commit-config.yaml +0 -0
  30. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/.python-version +0 -0
  31. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/CITATION.cff +0 -0
  32. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/LICENSE +0 -0
  33. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/all_variants/tutorial001.py +0 -0
  34. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/all_variants/tutorial001_an.py +0 -0
  35. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/all_variants/tutorial001_an_py310.py +0 -0
  36. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/all_variants/tutorial001_an_py39.py +0 -0
  37. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/all_variants/tutorial001_py310.py +0 -0
  38. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/all_variants/tutorial001_py39.py +0 -0
  39. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/no_py39/tutorial001.py +0 -0
  40. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/no_py39/tutorial001_an.py +0 -0
  41. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/no_py39/tutorial001_an_py310.py +0 -0
  42. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/no_py39/tutorial001_py310.py +0 -0
  43. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/only_py310/tutorial001_an_py310.py +0 -0
  44. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/only_py310/tutorial001_py310.py +0 -0
  45. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/only_py_no_an/tutorial001.py +0 -0
  46. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/only_py_no_an/tutorial001_py310.py +0 -0
  47. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/only_py_no_an/tutorial001_py39.py +0 -0
  48. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/simple/tutorial001.py +0 -0
  49. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/up_to_py39/tutorial001.py +0 -0
  50. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/up_to_py39/tutorial001_an.py +0 -0
  51. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/up_to_py39/tutorial001_an_py39.py +0 -0
  52. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/docs_src/up_to_py39/tutorial001_py39.py +0 -0
  53. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/pyproject.toml +0 -0
  54. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/scripts/format.sh +0 -0
  55. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/scripts/lint.sh +0 -0
  56. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/scripts/test.sh +0 -0
  57. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/src/markdown_include_variants/__init__.py +0 -0
  58. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/src/markdown_include_variants/py.typed +0 -0
  59. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_simple_hl.py +0 -0
  60. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_simple_ln.py +0 -0
  61. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/tests/test_simple_no_configs.py +0 -0
  62. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.3}/uv.lock +0 -0
@@ -1,4 +1,4 @@
1
- name: Check Labels
1
+ name: Labels
2
2
  on:
3
3
  pull_request_target:
4
4
  types:
@@ -10,7 +10,19 @@ on:
10
10
  - unlabeled
11
11
 
12
12
  jobs:
13
+ labeler:
14
+ permissions:
15
+ contents: read
16
+ pull-requests: write
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/labeler@v5
20
+ if: ${{ github.event.action != 'labeled' && github.event.action != 'unlabeled' }}
21
+ - run: echo "Done adding labels"
22
+ # Run this after labeler applied labels
13
23
  check-labels:
24
+ needs:
25
+ - labeler
14
26
  permissions:
15
27
  pull-requests: read
16
28
  runs-on: ubuntu-latest
@@ -27,4 +27,4 @@ jobs:
27
27
  - name: Build distribution
28
28
  run: python -m build
29
29
  - name: Publish
30
- uses: pypa/gh-action-pypi-publish@v1.9.0
30
+ uses: pypa/gh-action-pypi-publish@v1.10.3
@@ -23,6 +23,7 @@ jobs:
23
23
  env:
24
24
  GITHUB_CONTEXT: ${{ toJson(github) }}
25
25
  run: echo "$GITHUB_CONTEXT"
26
+ - uses: actions/checkout@v4
26
27
  - uses: actions/setup-python@v5
27
28
  with:
28
29
  python-version: '3.9'
@@ -39,7 +40,7 @@ jobs:
39
40
  path: htmlcov
40
41
  github-token: ${{ secrets.GITHUB_TOKEN }}
41
42
  run-id: ${{ github.event.workflow_run.id }}
42
- - run: uvx smokeshow upload htmlcov
43
+ - run: uv run smokeshow upload htmlcov
43
44
  env:
44
45
  SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}
45
46
  SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 100
@@ -33,7 +33,7 @@ jobs:
33
33
  - name: Install Dependencies
34
34
  run: uv sync
35
35
  - name: Lint
36
- run: bash scripts/lint.sh
36
+ run: uv run bash scripts/lint.sh
37
37
 
38
38
  test:
39
39
  runs-on: ubuntu-latest
@@ -61,7 +61,7 @@ jobs:
61
61
  run: uv sync
62
62
  - run: mkdir coverage
63
63
  - name: Test
64
- run: uvx bash scripts/test.sh
64
+ run: uv run bash scripts/test.sh
65
65
  env:
66
66
  COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
67
67
  CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
@@ -98,9 +98,9 @@ jobs:
98
98
  merge-multiple: true
99
99
  - run: uv sync
100
100
  - run: ls -la coverage
101
- - run: uvx coverage combine coverage
102
- - run: uvx coverage report
103
- - run: uvx coverage html --title "Coverage for ${{ github.sha }}"
101
+ - run: uv run coverage combine coverage
102
+ - run: uv run coverage report
103
+ - run: uv run coverage html --title "Coverage for ${{ github.sha }}"
104
104
  - name: Store coverage HTML
105
105
  uses: actions/upload-artifact@v4
106
106
  with:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: markdown-include-variants
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: Markdown extension to expand directives to include source example files to also include their variants. Only useful to tiangolo's projets. Don't use it. 😅
5
5
  Project-URL: Homepage, https://github.com/tiangolo/markdown-include-variants
6
6
  Project-URL: Repository, https://github.com/tiangolo/markdown-include-variants
@@ -43,25 +43,54 @@ There are no guarantees about behavior, it is made to suit the needs of these pr
43
43
 
44
44
  If you're still here it's probably because you are getting involved in one of the projects that use it. 🤓
45
45
 
46
- Here's how it works:
46
+ Here's how it works. 🚀
47
+
48
+ ### Configure Plugin in MkDocs Material
49
+
50
+ Make sure `mkdocs.yml` has a section with at least these configs:
51
+
52
+ ```yaml
53
+ markdown_extensions:
54
+ # Python Markdown Extensions
55
+ pymdownx.highlight:
56
+ pymdownx.superfences:
57
+
58
+ # pymdownx blocks
59
+ pymdownx.blocks.admonition:
60
+ types:
61
+ - tip
62
+ pymdownx.blocks.details:
63
+ pymdownx.blocks.tab:
64
+ alternate_style: True
65
+
66
+ # Other extensions
67
+ mdx_include:
68
+ markdown_include_variants:
69
+ ```
70
+
71
+ The last config is the one specific to this extension, `markdown-include-variants`.
72
+
73
+ The other configs are for the extensions that actually render the output, this extension (`markdown-include-variants`) just generates the content to be rendered by those other extensions.
74
+
75
+ ### Workflow
47
76
 
48
77
  * You add a Python source example to the `docs_src` directory, with the minimum Python version supported by the project, and using the old format without `Annotated`, if that applies, it would be named something like `tutorial001.py`.
49
- * Copy the file and update it to use `Annotated` (if that applies), and name the file with a "tag" (a prefix) of `an`, like: `tutorial001_an.py`.
78
+ * Copy the file and update it to use `Annotated` (if that applies), and name the file with a "tag" (a prefix) of `_an`, like: `tutorial001_an.py`.
50
79
  * Run the internal script to generate the variants of the files for superior versions of Python, like `3.9`, `3.10`, etc. (this internal script is in the project itself). This would generate files like `tutorial001_py39.py`, `tutorial001_py310.py`, etc. and `tutorial001_an_py39.py`, `tutorial001_an_py310.py`, etc.
51
- * In the Markdown file, include the simplest version of the file, using this syntax:
80
+ * In the Markdown file, include the preferred version of the file, using this syntax:
52
81
 
53
82
  ```markdown
54
- {* ./docs_src/first_steps/tutorial001.py *}
83
+ {* ./docs_src/first_steps/tutorial001_an_py310.py *}
55
84
  ```
56
85
 
57
- That will be automatically expanded with [mdx-include](https://github.com/neurobin/mdx_include) to include the recommended version of the file (the highest version of Python, using `Annotated`), and will include the variants below in a collapsed `details` box.
86
+ That will be automatically expanded with [mdx-include](https://github.com/neurobin/mdx_include) to include the other variants below in a collapsed `details` box.
58
87
 
59
88
  ### Include Lines
60
89
 
61
90
  To include specific line ranges, use the config `ln`:
62
91
 
63
92
  ```markdown
64
- {* ./docs_src/first_steps/tutorial001.py ln[3:6,8,10:11] *}
93
+ {* ./docs_src/first_steps/tutorial001_an_py310.py ln[3:6,8,10:11] *}
65
94
  ```
66
95
 
67
96
  That will include only:
@@ -83,7 +112,7 @@ If you include specific lines, it will also add another collapsed `details` box
83
112
  You can highlight specific lines using the config `hl`:
84
113
 
85
114
  ```markdown
86
- {* ./docs_src/first_steps/tutorial001.py hl[3,5:7,10] *}
115
+ {* ./docs_src/first_steps/tutorial001_an_py310.py hl[3,5:7,10] *}
87
116
  ```
88
117
 
89
118
  That will highlight:
@@ -101,7 +130,7 @@ So, when deciding which lines to highlight, do that based on the highest version
101
130
  You can combine both `ln` and `hl`:
102
131
 
103
132
  ```markdown
104
- {* ./docs_src/first_steps/tutorial001.py ln[3:6,8,10:11] hl[3,5:6,10] *}
133
+ {* ./docs_src/first_steps/tutorial001_an_py310.py ln[3:6,8,10:11] hl[3,5:6,10] *}
105
134
  ```
106
135
 
107
136
  The highlighted lines refer to the source file (for the highest/recommended version), not the final rendered code block.
@@ -125,7 +154,7 @@ print("line 7")
125
154
  Using a declaration like this:
126
155
 
127
156
  ```markdown
128
- {* ./docs_src/first_steps/tutorial001.py ln[5:7] hl[6] *}
157
+ {* ./docs_src/first_steps/tutorial001_an_py310.py ln[5:7] hl[6] *}
129
158
  ```
130
159
 
131
160
  Could render something like:
@@ -26,25 +26,54 @@ There are no guarantees about behavior, it is made to suit the needs of these pr
26
26
 
27
27
  If you're still here it's probably because you are getting involved in one of the projects that use it. 🤓
28
28
 
29
- Here's how it works:
29
+ Here's how it works. 🚀
30
+
31
+ ### Configure Plugin in MkDocs Material
32
+
33
+ Make sure `mkdocs.yml` has a section with at least these configs:
34
+
35
+ ```yaml
36
+ markdown_extensions:
37
+ # Python Markdown Extensions
38
+ pymdownx.highlight:
39
+ pymdownx.superfences:
40
+
41
+ # pymdownx blocks
42
+ pymdownx.blocks.admonition:
43
+ types:
44
+ - tip
45
+ pymdownx.blocks.details:
46
+ pymdownx.blocks.tab:
47
+ alternate_style: True
48
+
49
+ # Other extensions
50
+ mdx_include:
51
+ markdown_include_variants:
52
+ ```
53
+
54
+ The last config is the one specific to this extension, `markdown-include-variants`.
55
+
56
+ The other configs are for the extensions that actually render the output, this extension (`markdown-include-variants`) just generates the content to be rendered by those other extensions.
57
+
58
+ ### Workflow
30
59
 
31
60
  * You add a Python source example to the `docs_src` directory, with the minimum Python version supported by the project, and using the old format without `Annotated`, if that applies, it would be named something like `tutorial001.py`.
32
- * Copy the file and update it to use `Annotated` (if that applies), and name the file with a "tag" (a prefix) of `an`, like: `tutorial001_an.py`.
61
+ * Copy the file and update it to use `Annotated` (if that applies), and name the file with a "tag" (a prefix) of `_an`, like: `tutorial001_an.py`.
33
62
  * Run the internal script to generate the variants of the files for superior versions of Python, like `3.9`, `3.10`, etc. (this internal script is in the project itself). This would generate files like `tutorial001_py39.py`, `tutorial001_py310.py`, etc. and `tutorial001_an_py39.py`, `tutorial001_an_py310.py`, etc.
34
- * In the Markdown file, include the simplest version of the file, using this syntax:
63
+ * In the Markdown file, include the preferred version of the file, using this syntax:
35
64
 
36
65
  ```markdown
37
- {* ./docs_src/first_steps/tutorial001.py *}
66
+ {* ./docs_src/first_steps/tutorial001_an_py310.py *}
38
67
  ```
39
68
 
40
- That will be automatically expanded with [mdx-include](https://github.com/neurobin/mdx_include) to include the recommended version of the file (the highest version of Python, using `Annotated`), and will include the variants below in a collapsed `details` box.
69
+ That will be automatically expanded with [mdx-include](https://github.com/neurobin/mdx_include) to include the other variants below in a collapsed `details` box.
41
70
 
42
71
  ### Include Lines
43
72
 
44
73
  To include specific line ranges, use the config `ln`:
45
74
 
46
75
  ```markdown
47
- {* ./docs_src/first_steps/tutorial001.py ln[3:6,8,10:11] *}
76
+ {* ./docs_src/first_steps/tutorial001_an_py310.py ln[3:6,8,10:11] *}
48
77
  ```
49
78
 
50
79
  That will include only:
@@ -66,7 +95,7 @@ If you include specific lines, it will also add another collapsed `details` box
66
95
  You can highlight specific lines using the config `hl`:
67
96
 
68
97
  ```markdown
69
- {* ./docs_src/first_steps/tutorial001.py hl[3,5:7,10] *}
98
+ {* ./docs_src/first_steps/tutorial001_an_py310.py hl[3,5:7,10] *}
70
99
  ```
71
100
 
72
101
  That will highlight:
@@ -84,7 +113,7 @@ So, when deciding which lines to highlight, do that based on the highest version
84
113
  You can combine both `ln` and `hl`:
85
114
 
86
115
  ```markdown
87
- {* ./docs_src/first_steps/tutorial001.py ln[3:6,8,10:11] hl[3,5:6,10] *}
116
+ {* ./docs_src/first_steps/tutorial001_an_py310.py ln[3:6,8,10:11] hl[3,5:6,10] *}
88
117
  ```
89
118
 
90
119
  The highlighted lines refer to the source file (for the highest/recommended version), not the final rendered code block.
@@ -108,7 +137,7 @@ print("line 7")
108
137
  Using a declaration like this:
109
138
 
110
139
  ```markdown
111
- {* ./docs_src/first_steps/tutorial001.py ln[5:7] hl[6] *}
140
+ {* ./docs_src/first_steps/tutorial001_an_py310.py ln[5:7] hl[6] *}
112
141
  ```
113
142
 
114
143
  Could render something like:
@@ -0,0 +1,28 @@
1
+ # Release Notes
2
+
3
+ ## Latest Changes
4
+
5
+ ## 0.0.3
6
+
7
+ ### Features
8
+
9
+ * ✨ Add highlight for full file preview. PR [#10](https://github.com/tiangolo/markdown-include-variants/pull/10) by [@tiangolo](https://github.com/tiangolo).
10
+
11
+ ## 0.0.2
12
+
13
+ ### Refactors
14
+
15
+ * ♻️ Make the preferred variant the one used in the include. PR [#9](https://github.com/tiangolo/markdown-include-variants/pull/9) by [@tiangolo](https://github.com/tiangolo).
16
+
17
+ ### Docs
18
+
19
+ * 📝 Fix MkDocs config example. PR [#8](https://github.com/tiangolo/markdown-include-variants/pull/8) by [@tiangolo](https://github.com/tiangolo).
20
+ * 📝 Update README with mkdocs.yml configs. PR [#6](https://github.com/tiangolo/markdown-include-variants/pull/6) by [@tiangolo](https://github.com/tiangolo).
21
+
22
+ ### Internal
23
+
24
+ * ⬆ Bump pypa/gh-action-pypi-publish from 1.9.0 to 1.10.3. PR [#1](https://github.com/tiangolo/markdown-include-variants/pull/1) by [@dependabot[bot]](https://github.com/apps/dependabot).
25
+ * 👷 Tweak labeler GitHub Action. PR [#7](https://github.com/tiangolo/markdown-include-variants/pull/7) by [@tiangolo](https://github.com/tiangolo).
26
+ * 👷 Fix smokeshow setup. PR [#4](https://github.com/tiangolo/markdown-include-variants/pull/4) by [@tiangolo](https://github.com/tiangolo).
27
+ * 👷 Tweak labeler GitHub Action to not change labels on manual labels. PR [#5](https://github.com/tiangolo/markdown-include-variants/pull/5) by [@tiangolo](https://github.com/tiangolo).
28
+ * 👷 Tweak CI and types. PR [#2](https://github.com/tiangolo/markdown-include-variants/pull/2) by [@tiangolo](https://github.com/tiangolo).
@@ -1,7 +1,7 @@
1
1
  import re
2
2
  from dataclasses import dataclass
3
3
  from pathlib import Path
4
- from typing import Literal, Union
4
+ from typing import Any, Literal, Union
5
5
 
6
6
  from markdown import Extension, Markdown
7
7
  from markdown.preprocessors import Preprocessor
@@ -15,8 +15,17 @@ class Variant:
15
15
  version: Literal["py38", "py39", "py310"]
16
16
 
17
17
 
18
+ def remove_suffixes(base_name: str, suffixes: list[str]) -> str:
19
+ for suffix in suffixes:
20
+ if base_name.endswith(suffix):
21
+ base_name = base_name[: -len(suffix)]
22
+ return remove_suffixes(base_name, suffixes)
23
+ return base_name
24
+
25
+
18
26
  def calculate_variants(base_path: Path) -> dict[tuple[str, Union[bool, None]], Variant]:
19
- base_name = base_path.stem
27
+ preferred_name = base_path.stem
28
+ base_name = remove_suffixes(preferred_name, ["_an", "_py39", "_py310"])
20
29
  base_dir = base_path.parent
21
30
  variants: dict[tuple[str, Union[bool, None]], Variant] = {}
22
31
  an = "_an"
@@ -24,12 +33,16 @@ def calculate_variants(base_path: Path) -> dict[tuple[str, Union[bool, None]], V
24
33
  py310 = "_py310"
25
34
  an_p310_path = base_dir / f"{base_name}{an}{py310}.py"
26
35
  an_p39_path = base_dir / f"{base_name}{an}{py39}.py"
27
- an_path = base_dir / f"{base_name}{an}.py"
36
+ an_p38_path = base_dir / f"{base_name}{an}.py"
28
37
  p310_path = base_dir / f"{base_name}{py310}.py"
29
38
  p39_path = base_dir / f"{base_name}{py39}.py"
39
+ p38_path = base_dir / f"{base_name}.py"
30
40
  if an_p310_path.exists():
31
41
  v = Variant(
32
- path=an_p310_path, title="Python 3.10+", is_annotated=True, version="py310"
42
+ path=an_p310_path,
43
+ title="Python 3.10+",
44
+ is_annotated=True,
45
+ version="py310",
33
46
  )
34
47
  variants[(v.version, v.is_annotated)] = v
35
48
  if p310_path.exists():
@@ -42,12 +55,18 @@ def calculate_variants(base_path: Path) -> dict[tuple[str, Union[bool, None]], V
42
55
  variants[(v.version, v.is_annotated)] = v
43
56
  elif p310_path.exists():
44
57
  v = Variant(
45
- path=p310_path, title="Python 3.10+", is_annotated=None, version="py310"
58
+ path=p310_path,
59
+ title="Python 3.10+",
60
+ is_annotated=None,
61
+ version="py310",
46
62
  )
47
63
  variants[(v.version, v.is_annotated)] = v
48
64
  if an_p39_path.exists():
49
65
  v = Variant(
50
- path=an_p39_path, title="Python 3.9+", is_annotated=True, version="py39"
66
+ path=an_p39_path,
67
+ title="Python 3.9+",
68
+ is_annotated=True,
69
+ version="py39",
51
70
  )
52
71
  variants[(v.version, v.is_annotated)] = v
53
72
  if p39_path.exists():
@@ -60,25 +79,34 @@ def calculate_variants(base_path: Path) -> dict[tuple[str, Union[bool, None]], V
60
79
  variants[(v.version, v.is_annotated)] = v
61
80
  elif p39_path.exists():
62
81
  v = Variant(
63
- path=p39_path, title="Python 3.9+", is_annotated=None, version="py39"
82
+ path=p39_path,
83
+ title="Python 3.9+",
84
+ is_annotated=None,
85
+ version="py39",
64
86
  )
65
87
  variants[(v.version, v.is_annotated)] = v
66
- if an_path.exists():
88
+ if an_p38_path.exists():
67
89
  v = Variant(
68
- path=an_path, title="Python 3.8+", is_annotated=True, version="py38"
90
+ path=an_p38_path,
91
+ title="Python 3.8+",
92
+ is_annotated=True,
93
+ version="py38",
69
94
  )
70
95
  variants[(v.version, v.is_annotated)] = v
71
- if base_path.exists():
96
+ if p38_path.exists():
72
97
  v = Variant(
73
- path=base_path,
98
+ path=p38_path,
74
99
  title="Python 3.8+ - non-Annotated",
75
100
  is_annotated=False,
76
101
  version="py38",
77
102
  )
78
103
  variants[(v.version, v.is_annotated)] = v
79
- elif base_path.exists():
104
+ elif p38_path.exists():
80
105
  v = Variant(
81
- path=base_path, title="Python 3.8+", is_annotated=None, version="py38"
106
+ path=p38_path,
107
+ title="Python 3.8+",
108
+ is_annotated=None,
109
+ version="py38",
82
110
  )
83
111
  variants[(v.version, v.is_annotated)] = v
84
112
  return variants
@@ -139,6 +167,16 @@ def calculate_includes(
139
167
  return lines_groups
140
168
 
141
169
 
170
+ def generate_hl_string(hl_lines: list[tuple[int, int]]) -> str:
171
+ hl_lines_strs: list[str] = []
172
+ for hl_line in hl_lines:
173
+ if hl_line[0] == hl_line[1]:
174
+ hl_lines_strs.append(str(hl_line[0]))
175
+ else:
176
+ hl_lines_strs.append(f"{hl_line[0]}-{hl_line[1]}")
177
+ return " ".join(hl_lines_strs)
178
+
179
+
142
180
  re_line = r"^\{\*\s*(\S+)\s*(.*)\*\}$"
143
181
  re_config = r"(\w+)\[([^\]]+)\]"
144
182
 
@@ -175,25 +213,23 @@ class IncludeVariantsPreprocessor(Preprocessor):
175
213
  use_hl_lines.extend(info.computed_hl_lines())
176
214
  else:
177
215
  use_hl_lines = highlight_lines
178
- use_hl_lines_strs: list[str] = []
179
- for hl_line in use_hl_lines:
180
- if hl_line[0] == hl_line[1]:
181
- use_hl_lines_strs.append(str(hl_line[0]))
182
- else:
183
- use_hl_lines_strs.append(f"{hl_line[0]}-{hl_line[1]}")
184
- use_hl_lines_str = " ".join(use_hl_lines_strs)
216
+ use_hl_lines_str = generate_hl_string(use_hl_lines)
185
217
 
186
218
  variants = calculate_variants(base_path)
187
219
  if len(variants) == 0:
188
220
  raise FileNotFoundError(f"Could not find any variants for {base_path}")
189
221
  sorted_variants: list[Variant] = []
222
+ preferred_variant = None
190
223
  for an in [True, False, None]:
191
224
  for version in ["py310", "py39", "py38"]:
192
225
  v = variants.get((version, an))
193
226
  if v:
194
- sorted_variants.append(v)
195
- assert sorted_variants
196
- preferred_variant = sorted_variants[0]
227
+ if v.path == base_path:
228
+ assert preferred_variant is None
229
+ preferred_variant = v
230
+ else:
231
+ sorted_variants.append(v)
232
+ assert preferred_variant is not None
197
233
  content_lines = preferred_variant.path.read_text().splitlines()
198
234
 
199
235
  internal_block_lines: list[str] = []
@@ -243,11 +279,15 @@ class IncludeVariantsPreprocessor(Preprocessor):
243
279
  ]
244
280
  )
245
281
  if include_lines:
282
+ first_line_full = "```python"
283
+ if highlight_lines:
284
+ hl_lines_full_str = generate_hl_string(highlight_lines)
285
+ first_line_full += f' hl_lines="{hl_lines_full_str}"'
246
286
  block_lines.extend(
247
287
  [
248
288
  "//// details | 👀 Full file preview",
249
289
  "",
250
- "```python",
290
+ first_line_full,
251
291
  f"{{!{preferred_variant.path}!}}",
252
292
  "```",
253
293
  "",
@@ -255,7 +295,7 @@ class IncludeVariantsPreprocessor(Preprocessor):
255
295
  "",
256
296
  ]
257
297
  )
258
- if len(sorted_variants) > 1:
298
+ if len(sorted_variants):
259
299
  block_lines.extend(
260
300
  [
261
301
  "///// details | 🤓 Other versions and variants",
@@ -263,7 +303,7 @@ class IncludeVariantsPreprocessor(Preprocessor):
263
303
  ]
264
304
  )
265
305
 
266
- for variant in sorted_variants[1:]:
306
+ for variant in sorted_variants:
267
307
  block_lines.extend([f"//// tab | {variant.title}", ""])
268
308
  if variant.is_annotated is False:
269
309
  block_lines.extend(
@@ -304,5 +344,7 @@ class IncludeVariantsExtension(Extension):
304
344
  )
305
345
 
306
346
 
307
- def makeExtension(*args, **kwargs): # pragma: no cover
347
+ def makeExtension(
348
+ *args: Any, **kwargs: Any
349
+ ) -> IncludeVariantsExtension: # pragma: no cover
308
350
  return IncludeVariantsExtension(*args, **kwargs)
@@ -0,0 +1 @@
1
+ __version__ = "0.0.3"
@@ -12,7 +12,7 @@ from markdown_include_variants import IncludeVariantsExtension
12
12
  def test_all_variants_plain():
13
13
  input_md = inspect.cleandoc(
14
14
  """
15
- {* docs_src/all_variants/tutorial001.py *}
15
+ {* docs_src/all_variants/tutorial001_an_py310.py *}
16
16
  """
17
17
  )
18
18
 
@@ -63,7 +63,7 @@ def test_all_variants_plain():
63
63
  def test_all_variants_ln_hl():
64
64
  input_md = inspect.cleandoc(
65
65
  """
66
- {* docs_src/all_variants/tutorial001.py ln[3:5] hl[4:5] *}
66
+ {* docs_src/all_variants/tutorial001_an_py310.py ln[3:5] hl[4:5] *}
67
67
  """
68
68
  )
69
69
 
@@ -79,7 +79,7 @@ def test_all_variants_ln_hl():
79
79
  <p>```</p>
80
80
  <p>////</p>
81
81
  <p>//// details | 👀 Full file preview</p>
82
- <p><code>python
82
+ <p><code>python hl_lines="4-5"
83
83
  {!docs_src/all_variants/tutorial001_an_py310.py!}</code></p>
84
84
  <p>////</p>
85
85
  <p>///// details | 🤓 Other versions and variants</p>
@@ -121,7 +121,7 @@ def test_all_variants_ln_hl():
121
121
  def test_all_variants_ln_hl_include():
122
122
  input_md = inspect.cleandoc(
123
123
  """
124
- {* docs_src/all_variants/tutorial001.py ln[3:5] hl[4:5] *}
124
+ {* docs_src/all_variants/tutorial001_an_py310.py ln[3:5] hl[4:5] *}
125
125
  """
126
126
  )
127
127
 
@@ -151,9 +151,9 @@ def test_all_variants_ln_hl_include():
151
151
  <div class="highlight"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 1&quot;</span><span class="p">)</span>
152
152
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 2&quot;</span><span class="p">)</span>
153
153
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 3&quot;</span><span class="p">)</span>
154
- <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 4&quot;</span><span class="p">)</span>
155
- <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 5&quot;</span><span class="p">)</span>
156
- <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 6&quot;</span><span class="p">)</span>
154
+ <span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 4&quot;</span><span class="p">)</span>
155
+ </span><span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 5&quot;</span><span class="p">)</span>
156
+ </span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 6&quot;</span><span class="p">)</span>
157
157
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 7&quot;</span><span class="p">)</span>
158
158
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 8&quot;</span><span class="p">)</span>
159
159
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;an py310 line 9&quot;</span><span class="p">)</span>
@@ -0,0 +1,57 @@
1
+ import inspect
2
+
3
+ import markdown
4
+ from inline_snapshot import snapshot
5
+
6
+ from markdown_include_variants import IncludeVariantsExtension
7
+
8
+
9
+ def test_all_variants_plain():
10
+ input_md = inspect.cleandoc(
11
+ """
12
+ {* docs_src/all_variants/tutorial001_an_py39.py *}
13
+ """
14
+ )
15
+
16
+ result = markdown.markdown(input_md, extensions=[IncludeVariantsExtension()])
17
+ assert result == snapshot(
18
+ inspect.cleandoc(
19
+ """
20
+ <p>//// tab | Python 3.9+
21
+ <code>python
22
+ {!docs_src/all_variants/tutorial001_an_py39.py!}</code></p>
23
+ <p>////</p>
24
+ <p>///// details | 🤓 Other versions and variants</p>
25
+ <p>//// tab | Python 3.10+</p>
26
+ <p><code>python
27
+ {!docs_src/all_variants/tutorial001_an_py310.py!}</code>
28
+ ////
29
+ //// tab | Python 3.8+</p>
30
+ <p><code>python
31
+ {!docs_src/all_variants/tutorial001_an.py!}</code>
32
+ ////
33
+ //// tab | Python 3.10+ - non-Annotated</p>
34
+ <p>/// tip</p>
35
+ <p>Prefer to use the <code>Annotated</code> version if possible.</p>
36
+ <p>///</p>
37
+ <p><code>python
38
+ {!docs_src/all_variants/tutorial001_py310.py!}</code>
39
+ ////
40
+ //// tab | Python 3.9+ - non-Annotated</p>
41
+ <p>/// tip</p>
42
+ <p>Prefer to use the <code>Annotated</code> version if possible.</p>
43
+ <p>///</p>
44
+ <p><code>python
45
+ {!docs_src/all_variants/tutorial001_py39.py!}</code>
46
+ ////
47
+ //// tab | Python 3.8+ - non-Annotated</p>
48
+ <p>/// tip</p>
49
+ <p>Prefer to use the <code>Annotated</code> version if possible.</p>
50
+ <p>///</p>
51
+ <p><code>python
52
+ {!docs_src/all_variants/tutorial001.py!}</code>
53
+ ////</p>
54
+ <p>/////</p>
55
+ """
56
+ )
57
+ )
@@ -9,7 +9,7 @@ from markdown_include_variants import IncludeVariantsExtension
9
9
  def test_all_variants_plain():
10
10
  input_md = inspect.cleandoc(
11
11
  """
12
- {* docs_src/no_py39/tutorial001.py *}
12
+ {* docs_src/no_py39/tutorial001_an_py310.py *}
13
13
  """
14
14
  )
15
15
 
@@ -9,7 +9,7 @@ from markdown_include_variants import IncludeVariantsExtension
9
9
  def test_all_variants_plain():
10
10
  input_md = inspect.cleandoc(
11
11
  """
12
- {* docs_src/only_py310/tutorial001.py *}
12
+ {* docs_src/only_py310/tutorial001_an_py310.py *}
13
13
  """
14
14
  )
15
15
 
@@ -9,7 +9,7 @@ from markdown_include_variants import IncludeVariantsExtension
9
9
  def test_all_variants_plain():
10
10
  input_md = inspect.cleandoc(
11
11
  """
12
- {* docs_src/only_py_no_an/tutorial001.py *}
12
+ {* docs_src/only_py_no_an/tutorial001_py310.py *}
13
13
  """
14
14
  )
15
15
 
@@ -32,7 +32,7 @@ def test_simple_ln_hl():
32
32
  <p>```</p>
33
33
  <p>////</p>
34
34
  <p>//// details | 👀 Full file preview</p>
35
- <p><code>python
35
+ <p><code>python hl_lines="1-3"
36
36
  {!docs_src/simple/tutorial001.py!}</code></p>
37
37
  <p>////</p>
38
38
  """
@@ -64,7 +64,7 @@ def test_simple_ln_hl_middle_block():
64
64
  <p>```</p>
65
65
  <p>////</p>
66
66
  <p>//// details | 👀 Full file preview</p>
67
- <p><code>python
67
+ <p><code>python hl_lines="2-3"
68
68
  {!docs_src/simple/tutorial001.py!}</code></p>
69
69
  <p>////</p>
70
70
  """
@@ -97,7 +97,7 @@ def test_simple_ln_hl_middle_block_end_block():
97
97
  ```</p>
98
98
  <p>////</p>
99
99
  <p>//// details | 👀 Full file preview</p>
100
- <p><code>python
100
+ <p><code>python hl_lines="2-3 8-10"
101
101
  {!docs_src/simple/tutorial001.py!}</code></p>
102
102
  <p>////</p>
103
103
  """
@@ -132,7 +132,7 @@ def test_simple_ln_hl_middle_block_middle_block_end_block():
132
132
  ```</p>
133
133
  <p>////</p>
134
134
  <p>//// details | 👀 Full file preview</p>
135
- <p><code>python
135
+ <p><code>python hl_lines="2-3 5-6 8-10"
136
136
  {!docs_src/simple/tutorial001.py!}</code></p>
137
137
  <p>////</p>
138
138
  """
@@ -167,7 +167,7 @@ def test_simple_ln_hl_middle_middle_block_end():
167
167
  ```</p>
168
168
  <p>////</p>
169
169
  <p>//// details | 👀 Full file preview</p>
170
- <p><code>python
170
+ <p><code>python hl_lines="2 5-6 10"
171
171
  {!docs_src/simple/tutorial001.py!}</code></p>
172
172
  <p>////</p>
173
173
  """
@@ -201,7 +201,7 @@ def test_simple_ln_hl_first_middle_end():
201
201
  ```</p>
202
202
  <p>////</p>
203
203
  <p>//// details | 👀 Full file preview</p>
204
- <p><code>python
204
+ <p><code>python hl_lines="1 6-8 10"
205
205
  {!docs_src/simple/tutorial001.py!}</code></p>
206
206
  <p>////</p>
207
207
  """
@@ -234,7 +234,7 @@ def test_simple_ln_hl_middle_block_end_block_hl_middle_block():
234
234
  ```</p>
235
235
  <p>////</p>
236
236
  <p>//// details | 👀 Full file preview</p>
237
- <p><code>python
237
+ <p><code>python hl_lines="2"
238
238
  {!docs_src/simple/tutorial001.py!}</code></p>
239
239
  <p>////</p>
240
240
  """
@@ -267,7 +267,7 @@ def test_simple_ln_hl_middle_block_end_block_hl_end_block():
267
267
  ```</p>
268
268
  <p>////</p>
269
269
  <p>//// details | 👀 Full file preview</p>
270
- <p><code>python
270
+ <p><code>python hl_lines="8-9"
271
271
  {!docs_src/simple/tutorial001.py!}</code></p>
272
272
  <p>////</p>
273
273
  """
@@ -316,9 +316,9 @@ def test_simple_ln_hl_middle_block_end_block_hl_end_block_include():
316
316
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 5&quot;</span><span class="p">)</span>
317
317
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 6&quot;</span><span class="p">)</span>
318
318
  <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 7&quot;</span><span class="p">)</span>
319
- <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 8&quot;</span><span class="p">)</span>
320
- <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 9&quot;</span><span class="p">)</span>
321
- <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 10&quot;</span><span class="p">)</span>
319
+ <span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 8&quot;</span><span class="p">)</span>
320
+ </span><span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 9&quot;</span><span class="p">)</span>
321
+ </span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;simple line 10&quot;</span><span class="p">)</span>
322
322
  </code></pre></div>
323
323
  <p>////</p>
324
324
  """
@@ -9,7 +9,7 @@ from markdown_include_variants import IncludeVariantsExtension
9
9
  def test_all_variants_plain():
10
10
  input_md = inspect.cleandoc(
11
11
  """
12
- {* docs_src/up_to_py39/tutorial001.py *}
12
+ {* docs_src/up_to_py39/tutorial001_an_py39.py *}
13
13
  """
14
14
  )
15
15
 
@@ -49,7 +49,7 @@ def test_all_variants_plain():
49
49
  def test_all_variants_ln_hl():
50
50
  input_md = inspect.cleandoc(
51
51
  """
52
- {* docs_src/up_to_py39/tutorial001.py ln[3:5] hl[4:5] *}
52
+ {* docs_src/up_to_py39/tutorial001_an_py39.py ln[3:5] hl[4:5] *}
53
53
  """
54
54
  )
55
55
 
@@ -65,7 +65,7 @@ def test_all_variants_ln_hl():
65
65
  <p>```</p>
66
66
  <p>////</p>
67
67
  <p>//// details | 👀 Full file preview</p>
68
- <p><code>python
68
+ <p><code>python hl_lines="4-5"
69
69
  {!docs_src/up_to_py39/tutorial001_an_py39.py!}</code></p>
70
70
  <p>////</p>
71
71
  <p>///// details | 🤓 Other versions and variants</p>
@@ -1,16 +0,0 @@
1
- name: Add Labels
2
- on:
3
- pull_request_target:
4
- types:
5
- - opened
6
- - synchronize
7
- - reopened
8
-
9
- jobs:
10
- labeler:
11
- permissions:
12
- contents: read
13
- pull-requests: write
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/labeler@v5
@@ -1,3 +0,0 @@
1
- # Release Notes
2
-
3
- ## Latest Changes
@@ -1 +0,0 @@
1
- __version__ = "0.0.1"