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.
- markdown_include_variants-0.0.1/.github/workflows/check-labels.yml → markdown_include_variants-0.0.2/.github/workflows/labeler.yml +13 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/publish.yml +1 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/smokeshow.yml +2 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/test.yml +5 -5
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/PKG-INFO +39 -10
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/README.md +38 -9
- markdown_include_variants-0.0.2/release-notes.md +22 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/src/markdown_include_variants/_main.py +53 -19
- markdown_include_variants-0.0.2/src/markdown_include_variants/_version.py +1 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_all_variants.py +3 -3
- markdown_include_variants-0.0.2/tests/test_another_preferred_variant.py +57 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_no_py39.py +1 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_only_py310.py +1 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_only_py_no_an.py +1 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_up_to_py39.py +2 -2
- markdown_include_variants-0.0.1/.github/workflows/add-labels.yml +0 -16
- markdown_include_variants-0.0.1/release-notes.md +0 -3
- markdown_include_variants-0.0.1/src/markdown_include_variants/_version.py +0 -1
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/DISCUSSION_TEMPLATE/questions.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/FUNDING.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/ISSUE_TEMPLATE/privileged.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/dependabot.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/labeler.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/issue-manager.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/latest-changes.yml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.gitignore +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.pre-commit-config.yaml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.python-version +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/CITATION.cff +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/LICENSE +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_an.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_an_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_an_py39.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/all_variants/tutorial001_py39.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001_an.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001_an_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py310/tutorial001_an_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py310/tutorial001_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py_no_an/tutorial001.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py_no_an/tutorial001_py310.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/only_py_no_an/tutorial001_py39.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/simple/tutorial001.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001_an.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001_an_py39.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/up_to_py39/tutorial001_py39.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/pyproject.toml +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/scripts/format.sh +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/scripts/lint.sh +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/scripts/test.sh +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/src/markdown_include_variants/__init__.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/src/markdown_include_variants/py.typed +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_hl.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_ln.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_ln_hl.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_no_configs.py +0 -0
- {markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/uv.lock +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name:
|
|
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
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/smokeshow.yml
RENAMED
|
@@ -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:
|
|
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
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/.github/workflows/test.yml
RENAMED
|
@@ -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:
|
|
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:
|
|
102
|
-
- run:
|
|
103
|
-
- run:
|
|
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.
|
|
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 `
|
|
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
|
|
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/
|
|
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
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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 `
|
|
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
|
|
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/
|
|
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
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|
88
|
+
if an_p38_path.exists():
|
|
67
89
|
v = Variant(
|
|
68
|
-
path=
|
|
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
|
|
96
|
+
if p38_path.exists():
|
|
72
97
|
v = Variant(
|
|
73
|
-
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
|
|
104
|
+
elif p38_path.exists():
|
|
80
105
|
v = Variant(
|
|
81
|
-
path=
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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)
|
|
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
|
|
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(
|
|
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"
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_all_variants.py
RENAMED
|
@@ -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/
|
|
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/
|
|
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/
|
|
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
|
+
)
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_up_to_py39.py
RENAMED
|
@@ -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/
|
|
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/
|
|
52
|
+
{* docs_src/up_to_py39/tutorial001_an_py39.py ln[3:5] hl[4:5] *}
|
|
53
53
|
"""
|
|
54
54
|
)
|
|
55
55
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/no_py39/tutorial001.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/docs_src/simple/tutorial001.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_ln_hl.py
RENAMED
|
File without changes
|
{markdown_include_variants-0.0.1 → markdown_include_variants-0.0.2}/tests/test_simple_no_configs.py
RENAMED
|
File without changes
|
|
File without changes
|