markdown-include-variants 0.0.1__tar.gz → 0.0.2__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.2/.github/workflows/labeler.yml +13 -1
  2. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/publish.yml +1 -1
  3. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/smokeshow.yml +2 -1
  4. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/test.yml +5 -5
  5. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/PKG-INFO +39 -10
  6. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/README.md +38 -9
  7. markdown_include_variants-0.0.2/release-notes.md +22 -0
  8. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/src/markdown_include_variants/_main.py +53 -19
  9. markdown_include_variants-0.0.2/src/markdown_include_variants/_version.py +1 -0
  10. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_all_variants.py +3 -3
  11. markdown_include_variants-0.0.2/tests/test_another_preferred_variant.py +57 -0
  12. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_no_py39.py +1 -1
  13. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_only_py310.py +1 -1
  14. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_only_py_no_an.py +1 -1
  15. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_up_to_py39.py +2 -2
  16. markdown_include_variants-0.0.1/.github/workflows/add-labels.yml +0 -16
  17. markdown_include_variants-0.0.1/release-notes.md +0 -3
  18. markdown_include_variants-0.0.1/src/markdown_include_variants/_version.py +0 -1
  19. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/DISCUSSION_TEMPLATE/questions.yml +0 -0
  20. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/FUNDING.yml +0 -0
  21. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  22. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/ISSUE_TEMPLATE/privileged.yml +0 -0
  23. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/dependabot.yml +0 -0
  24. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/labeler.yml +0 -0
  25. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/issue-manager.yml +0 -0
  26. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/latest-changes.yml +0 -0
  27. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.gitignore +0 -0
  28. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.pre-commit-config.yaml +0 -0
  29. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.python-version +0 -0
  30. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/CITATION.cff +0 -0
  31. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/LICENSE +0 -0
  32. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001.py +0 -0
  33. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_an.py +0 -0
  34. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_an_py310.py +0 -0
  35. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_an_py39.py +0 -0
  36. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_py310.py +0 -0
  37. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_py39.py +0 -0
  38. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001.py +0 -0
  39. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001_an.py +0 -0
  40. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001_an_py310.py +0 -0
  41. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001_py310.py +0 -0
  42. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py310/tutorial001_an_py310.py +0 -0
  43. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py310/tutorial001_py310.py +0 -0
  44. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py_no_an/tutorial001.py +0 -0
  45. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py_no_an/tutorial001_py310.py +0 -0
  46. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py_no_an/tutorial001_py39.py +0 -0
  47. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/simple/tutorial001.py +0 -0
  48. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001.py +0 -0
  49. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001_an.py +0 -0
  50. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001_an_py39.py +0 -0
  51. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001_py39.py +0 -0
  52. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/pyproject.toml +0 -0
  53. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/scripts/format.sh +0 -0
  54. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/scripts/lint.sh +0 -0
  55. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/scripts/test.sh +0 -0
  56. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/src/markdown_include_variants/__init__.py +0 -0
  57. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/src/markdown_include_variants/py.typed +0 -0
  58. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_hl.py +0 -0
  59. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_ln.py +0 -0
  60. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_ln_hl.py +0 -0
  61. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_no_configs.py +0 -0
  62. {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/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.2
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,22 @@
1
+ # Release Notes
2
+
3
+ ## Latest Changes
4
+
5
+ ## 0.0.2
6
+
7
+ ### Refactors
8
+
9
+ * ♻️ 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).
10
+
11
+ ### Docs
12
+
13
+ * 📝 Fix MkDocs config example. PR [#8](https://github.com/tiangolo/markdown-include-variants/pull/8) by [@tiangolo](https://github.com/tiangolo).
14
+ * 📝 Update README with mkdocs.yml configs. PR [#6](https://github.com/tiangolo/markdown-include-variants/pull/6) by [@tiangolo](https://github.com/tiangolo).
15
+
16
+ ### Internal
17
+
18
+ * ⬆ 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).
19
+ * 👷 Tweak labeler GitHub Action. PR [#7](https://github.com/tiangolo/markdown-include-variants/pull/7) by [@tiangolo](https://github.com/tiangolo).
20
+ * 👷 Fix smokeshow setup. PR [#4](https://github.com/tiangolo/markdown-include-variants/pull/4) by [@tiangolo](https://github.com/tiangolo).
21
+ * 👷 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).
22
+ * 👷 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
@@ -187,13 +215,17 @@ class IncludeVariantsPreprocessor(Preprocessor):
187
215
  if len(variants) == 0:
188
216
  raise FileNotFoundError(f"Could not find any variants for {base_path}")
189
217
  sorted_variants: list[Variant] = []
218
+ preferred_variant = None
190
219
  for an in [True, False, None]:
191
220
  for version in ["py310", "py39", "py38"]:
192
221
  v = variants.get((version, an))
193
222
  if v:
194
- sorted_variants.append(v)
195
- assert sorted_variants
196
- preferred_variant = sorted_variants[0]
223
+ if v.path == base_path:
224
+ assert preferred_variant is None
225
+ preferred_variant = v
226
+ else:
227
+ sorted_variants.append(v)
228
+ assert preferred_variant is not None
197
229
  content_lines = preferred_variant.path.read_text().splitlines()
198
230
 
199
231
  internal_block_lines: list[str] = []
@@ -255,7 +287,7 @@ class IncludeVariantsPreprocessor(Preprocessor):
255
287
  "",
256
288
  ]
257
289
  )
258
- if len(sorted_variants) > 1:
290
+ if len(sorted_variants):
259
291
  block_lines.extend(
260
292
  [
261
293
  "///// details | 🤓 Other versions and variants",
@@ -263,7 +295,7 @@ class IncludeVariantsPreprocessor(Preprocessor):
263
295
  ]
264
296
  )
265
297
 
266
- for variant in sorted_variants[1:]:
298
+ for variant in sorted_variants:
267
299
  block_lines.extend([f"//// tab | {variant.title}", ""])
268
300
  if variant.is_annotated is False:
269
301
  block_lines.extend(
@@ -304,5 +336,7 @@ class IncludeVariantsExtension(Extension):
304
336
  )
305
337
 
306
338
 
307
- def makeExtension(*args, **kwargs): # pragma: no cover
339
+ def makeExtension(
340
+ *args: Any, **kwargs: Any
341
+ ) -> IncludeVariantsExtension: # pragma: no cover
308
342
  return IncludeVariantsExtension(*args, **kwargs)
@@ -0,0 +1 @@
1
+ __version__ = "0.0.2"
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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"