docstring-to-text 0.0.1__tar.gz → 1.0.0__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.
- docstring_to_text-1.0.0/.github/workflows/publish-release-to-pypi.yml +262 -0
- docstring_to_text-1.0.0/PKG-INFO +71 -0
- docstring_to_text-1.0.0/README.md +56 -0
- {docstring_to_text-0.0.1 → docstring_to_text-1.0.0}/_build.bat +24 -23
- docstring_to_text-1.0.0/_upload-release.bat +24 -0
- docstring_to_text-1.0.0/_upload-test.bat +24 -0
- {docstring_to_text-0.0.1 → docstring_to_text-1.0.0}/pyproject.toml +3 -1
- docstring_to_text-1.0.0/src/docstring_to_text/__init__.py +152 -0
- {docstring_to_text-0.0.1 → docstring_to_text-1.0.0}/src/docstring_to_text/__package_meta.py +1 -1
- docstring_to_text-0.0.1/PKG-INFO +0 -18
- docstring_to_text-0.0.1/README.md +0 -3
- docstring_to_text-0.0.1/src/docstring_to_text/__init__.py +0 -6
- {docstring_to_text-0.0.1 → docstring_to_text-1.0.0}/.gitattributes +0 -0
- {docstring_to_text-0.0.1 → docstring_to_text-1.0.0}/.gitignore +0 -0
- {docstring_to_text-0.0.1 → docstring_to_text-1.0.0}/LICENSE.md +0 -0
@@ -0,0 +1,262 @@
|
|
1
|
+
# Prerequisites:
|
2
|
+
#
|
3
|
+
# - In GitHub repo - create the publishing environment (here, `pypi` / `testpypi`)
|
4
|
+
# https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments
|
5
|
+
#
|
6
|
+
# - Create a "Trusted Publisher" in the project settings on (test)PyPI
|
7
|
+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
|
8
|
+
# https://pypi.org/manage/project/docstring-to-text/settings/publishing/
|
9
|
+
|
10
|
+
# Tutorials:
|
11
|
+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
|
12
|
+
# https://www.youtube.com/watch?v=NMQwzI9hprg
|
13
|
+
# https://github.com/ArjanCodes/moneysnake/blob/main/.github/workflows/release.yaml
|
14
|
+
|
15
|
+
name: Publish Python 🐍 distribution 📦 to PyPI
|
16
|
+
|
17
|
+
# ======= TRIGGERS =======
|
18
|
+
|
19
|
+
#on:
|
20
|
+
# push:
|
21
|
+
# tags:
|
22
|
+
# # Trigger on tags with '[v]<int>.<int>whatever' pattern: 'v1.0.0', 'v2.1.4', etc
|
23
|
+
# # https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#filter-pattern-cheat-sheet
|
24
|
+
# # https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#onpushbranchestagsbranches-ignoretags-ignore
|
25
|
+
# - 'v[0-9]+.[0-9]**'
|
26
|
+
# - '[0-9]+.[0-9]**'
|
27
|
+
|
28
|
+
on:
|
29
|
+
workflow_dispatch:
|
30
|
+
push:
|
31
|
+
branches:
|
32
|
+
- main
|
33
|
+
paths:
|
34
|
+
- "src/docstring_to_text/__package_meta.py"
|
35
|
+
|
36
|
+
# ======= ENV VARS =======
|
37
|
+
|
38
|
+
env:
|
39
|
+
# The name on PyPI:
|
40
|
+
PACKAGE_NAME: 'docstring-to-text'
|
41
|
+
VERSION_MODULE: 'src.docstring_to_text.__package_meta'
|
42
|
+
VERSION_VARIABLE: 'VERSION'
|
43
|
+
|
44
|
+
|
45
|
+
# ========= JOBS =========
|
46
|
+
|
47
|
+
jobs:
|
48
|
+
|
49
|
+
detect-version:
|
50
|
+
# https://emojidb.org/query-emojis
|
51
|
+
name: Parse version 🔢 + add Tag 🏷️
|
52
|
+
if: ${{ github.repository_owner == 'Lex-DRL' }}
|
53
|
+
runs-on: ubuntu-latest
|
54
|
+
permissions:
|
55
|
+
contents: write # Needed for tag creation
|
56
|
+
outputs:
|
57
|
+
tag_name: ${{ steps.parse.outputs.tag_name }}
|
58
|
+
version_full: ${{ steps.parse.outputs.version_full }}
|
59
|
+
version_num: ${{ steps.parse.outputs.version_num }}
|
60
|
+
suffix: ${{ steps.parse.outputs.suffix }}
|
61
|
+
steps:
|
62
|
+
- name: Checkout Code
|
63
|
+
uses: actions/checkout@v4
|
64
|
+
with:
|
65
|
+
fetch-depth: 0 # Fetch full history to avoid issues with tags and branches
|
66
|
+
|
67
|
+
- name: Extract version from package meta 📝
|
68
|
+
id: get_version_string
|
69
|
+
run: |
|
70
|
+
# VERSION=$(grep -oP 'VERSION\s*=\s*["'\'']\K[^"'\'']+' src/docstring_to_text/__package_meta.py)
|
71
|
+
VERSION=$(python -c "from ${{ env.VERSION_MODULE }} import ${{ env.VERSION_VARIABLE }}; print(${{ env.VERSION_VARIABLE }})")
|
72
|
+
echo "Version string: $VERSION"
|
73
|
+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
74
|
+
|
75
|
+
- name: Parse Version 🧱
|
76
|
+
id: parse
|
77
|
+
# The main magic happens in regexps...
|
78
|
+
# - `grep -qP`: verify that the tag matches the given pattern
|
79
|
+
# - `sed -E 's/regex_pattern/replacement/optional_flags'`, with '\1' in replacement meaning first group
|
80
|
+
# The regexp itself:
|
81
|
+
# - '^v?([0-9]+\.[0-9]+\.[0-9]+)' - matches 'v1.2.3' / '1.2.3' from start of the string, 'v' stripped
|
82
|
+
# - '^' - start of the input string.
|
83
|
+
# - 'v?(...)' - optional 'v' prefix (might be missing), and what follows is captured as a group.
|
84
|
+
# - '[0-9]+' - a sequence of 1 or more digits.
|
85
|
+
# - '\.' - literal dot (just '.' matches any character).
|
86
|
+
# - '(-.+)?$' - suffix captured as a group:
|
87
|
+
# - '-' - just a hyphen.
|
88
|
+
# - '.+' - any non-empty string (at least one any character - including another hyphen, dot or digit).
|
89
|
+
# - '(...)?$' - a group that might be present or not.
|
90
|
+
# - '$' - the end of the input string.
|
91
|
+
run: |
|
92
|
+
VERSION_STR="${{ steps.get_version_string.outputs.version }}"
|
93
|
+
echo "Version string: $VERSION_STR"
|
94
|
+
if echo "$VERSION_STR" | grep -qP '^v?[0-9]+\.[0-9]+\.[0-9]+(-.+)?$'; then
|
95
|
+
VERSION_NUMBER=$(echo "$VERSION_STR" | sed -E 's/^v?([0-9]+\.[0-9]+\.[0-9]+)(-.+)?$/\1/')
|
96
|
+
echo "Version number: $VERSION_NUMBER"
|
97
|
+
if echo "$VERSION_STR" | grep -q '-'; then
|
98
|
+
# We can only get into this branch if the initial grep regex worked AND '-' is there
|
99
|
+
# So it's '[v]1.2.3-something'
|
100
|
+
SUFFIX=$(echo "$VERSION_STR" | sed -E 's/^v?([0-9]+\.[0-9]+\.[0-9]+)-(.+)$/\2/')
|
101
|
+
if echo "$SUFFIX" | grep -q '-'; then
|
102
|
+
echo "Invalid suffix (it contains hyphen): $SUFFIX" >&2
|
103
|
+
exit 1
|
104
|
+
fi
|
105
|
+
SUFFIX_WITH_SEP=$(echo "-$SUFFIX")
|
106
|
+
else
|
107
|
+
SUFFIX=""
|
108
|
+
SUFFIX_WITH_SEP=""
|
109
|
+
fi
|
110
|
+
echo "Suffix: $SUFFIX"
|
111
|
+
else
|
112
|
+
echo "Version string doesn't match the '[v]1.2.3[-suffix]' pattern: $VERSION_STR" >&2
|
113
|
+
exit 1
|
114
|
+
fi
|
115
|
+
VERSION_FULL=$(echo "${VERSION_NUMBER}${SUFFIX_WITH_SEP}")
|
116
|
+
echo "Full parsed Version: $VERSION_FULL"
|
117
|
+
TAG_NAME=$(echo "v${VERSION_FULL}")
|
118
|
+
echo "Tag name: $TAG_NAME"
|
119
|
+
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
|
120
|
+
echo "version_full=$VERSION_FULL" >> "$GITHUB_OUTPUT"
|
121
|
+
echo "version_num=$VERSION_NUMBER" >> "$GITHUB_OUTPUT"
|
122
|
+
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
|
123
|
+
|
124
|
+
- name: Create tag 🏷️ from version
|
125
|
+
uses: actions/github-script@v7
|
126
|
+
with:
|
127
|
+
script: |
|
128
|
+
github.rest.git.createRef({
|
129
|
+
owner: context.repo.owner,
|
130
|
+
repo: context.repo.repo,
|
131
|
+
ref: `refs/tags/${process.env.TAG}`,
|
132
|
+
sha: context.sha
|
133
|
+
})
|
134
|
+
env:
|
135
|
+
TAG: ${{ steps.parse.outputs.tag_name }}
|
136
|
+
|
137
|
+
# --------------------------------------------------------
|
138
|
+
|
139
|
+
build:
|
140
|
+
name: Build distribution 📦
|
141
|
+
needs: [detect-version] # No need to even try, if we failed tag parsing
|
142
|
+
# Just to be nice - let's check the GitHub user and prevent unwanted auto-runs on forks made solely for a PR.
|
143
|
+
if: >-
|
144
|
+
github.repository_owner == 'Lex-DRL'
|
145
|
+
# Second condition: only run on tag pushes...
|
146
|
+
# It was in the template from official tutorial, but it got redundant, since the only trigger is `on.push.tags`
|
147
|
+
# && startsWith(github.ref, 'refs/tags/v')
|
148
|
+
runs-on: ubuntu-latest
|
149
|
+
|
150
|
+
steps:
|
151
|
+
- name: Checkout Code
|
152
|
+
uses: actions/checkout@v4
|
153
|
+
with:
|
154
|
+
persist-credentials: false
|
155
|
+
|
156
|
+
- name: Set up Python
|
157
|
+
uses: actions/setup-python@v5
|
158
|
+
with:
|
159
|
+
python-version: "3.x"
|
160
|
+
|
161
|
+
- name: Install pypa/build
|
162
|
+
run: >-
|
163
|
+
python3 -m
|
164
|
+
pip install
|
165
|
+
build
|
166
|
+
--user
|
167
|
+
|
168
|
+
- name: Build a binary wheel and a source tarball
|
169
|
+
run: python3 -m build
|
170
|
+
|
171
|
+
- name: Store the distribution packages
|
172
|
+
uses: actions/upload-artifact@v4
|
173
|
+
with:
|
174
|
+
name: python-package-distributions
|
175
|
+
path: dist/
|
176
|
+
|
177
|
+
# --------------------------------------------------------
|
178
|
+
|
179
|
+
publish-to-pypi:
|
180
|
+
name: >-
|
181
|
+
Publish Python 🐍 distribution 📦 to PyPI ⬆️
|
182
|
+
if: ${{ github.repository_owner == 'Lex-DRL' }}
|
183
|
+
needs:
|
184
|
+
- build # Requires the previous 'build' job to succeed
|
185
|
+
runs-on: ubuntu-latest
|
186
|
+
|
187
|
+
environment:
|
188
|
+
name: pypi
|
189
|
+
url: https://pypi.org/p/${{ env.PACKAGE_NAME }}
|
190
|
+
permissions:
|
191
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
192
|
+
|
193
|
+
steps:
|
194
|
+
- name: Download all the dists
|
195
|
+
uses: actions/download-artifact@v4
|
196
|
+
with:
|
197
|
+
name: python-package-distributions
|
198
|
+
path: dist/
|
199
|
+
|
200
|
+
- name: Publish distribution 📦 to PyPI
|
201
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
202
|
+
|
203
|
+
# --------------------------------------------------------
|
204
|
+
|
205
|
+
# publish-to-testpypi:
|
206
|
+
# name: Publish Python 🐍 distribution 📦 to TestPyPI ❗
|
207
|
+
# if: ${{ github.repository_owner == 'Lex-DRL' }}
|
208
|
+
# needs:
|
209
|
+
# - build # Requires the previous 'build' job to succeed
|
210
|
+
# runs-on: ubuntu-latest
|
211
|
+
#
|
212
|
+
# environment:
|
213
|
+
# #name: testpypi
|
214
|
+
# # Yes, it's "not cool" to use the same environment for testing and publishing,
|
215
|
+
# # but in this particular repo I only use the TestPyPI for initial debugging of the workflow
|
216
|
+
# name: pypi
|
217
|
+
# url: https://test.pypi.org/p/${{ env.PACKAGE_NAME }}
|
218
|
+
# permissions:
|
219
|
+
# id-token: write # IMPORTANT: mandatory for trusted publishing
|
220
|
+
#
|
221
|
+
# steps:
|
222
|
+
# - name: Download all the dists
|
223
|
+
# uses: actions/download-artifact@v4
|
224
|
+
# with:
|
225
|
+
# name: python-package-distributions
|
226
|
+
# path: dist/
|
227
|
+
#
|
228
|
+
# - name: Publish distribution 📦 to TestPyPI
|
229
|
+
# uses: pypa/gh-action-pypi-publish@release/v1
|
230
|
+
# with:
|
231
|
+
# repository-url: https://test.pypi.org/legacy/
|
232
|
+
|
233
|
+
# --------------------------------------------------------
|
234
|
+
|
235
|
+
github_release:
|
236
|
+
name: Create GitHub Release 🔄
|
237
|
+
needs: [build, detect-version]
|
238
|
+
runs-on: ubuntu-latest
|
239
|
+
permissions:
|
240
|
+
contents: write
|
241
|
+
steps:
|
242
|
+
- name: Checkout Code
|
243
|
+
uses: actions/checkout@v4
|
244
|
+
with:
|
245
|
+
fetch-depth: 0 # Fetch full history to avoid issues with tags and branches
|
246
|
+
|
247
|
+
- name: Download artifacts
|
248
|
+
uses: actions/download-artifact@v4
|
249
|
+
with:
|
250
|
+
name: python-package-distributions
|
251
|
+
path: dist/
|
252
|
+
|
253
|
+
- name: Create GitHub Release
|
254
|
+
id: create_release
|
255
|
+
env:
|
256
|
+
GH_TOKEN: ${{ github.token }}
|
257
|
+
run: >-
|
258
|
+
gh release create
|
259
|
+
${{ needs.detect-version.outputs.tag_name }}
|
260
|
+
dist/*
|
261
|
+
--title ${{ needs.detect-version.outputs.tag_name }}
|
262
|
+
--generate-notes
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: docstring-to-text
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A simple pip package converting docstrings into clean text (proper paragraphs and indents)
|
5
|
+
Project-URL: Source Code, https://github.com/Lex-DRL/Py-docstring-to-text
|
6
|
+
Project-URL: Issues, https://github.com/Lex-DRL/Py-docstring-to-text/issues
|
7
|
+
Author: Lex Darlog (Lex-DRL)
|
8
|
+
License-Expression: MPL-2.0
|
9
|
+
License-File: LICENSE.md
|
10
|
+
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Requires-Python: >=3.7
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
|
16
|
+
# docstring-to-text
|
17
|
+
|
18
|
+
A simple pip package converting docstrings into clean text (proper paragraphs and indents).
|
19
|
+
|
20
|
+
For example, here's a class docstring:
|
21
|
+
```python
|
22
|
+
class MyClass:
|
23
|
+
"""
|
24
|
+
Here's a class.
|
25
|
+
|
26
|
+
|
27
|
+
It has sphinx-like paragraphs, which can
|
28
|
+
span multiple lines. Any modern IDE would
|
29
|
+
display them as a single line, that wraps
|
30
|
+
the given width.
|
31
|
+
|
32
|
+
You can't just remove all the new lines
|
33
|
+
in the entire string, because you want
|
34
|
+
to preserve paragraphs themselves.
|
35
|
+
|
36
|
+
Also, when it comes to lists:
|
37
|
+
- You probably want to separate items
|
38
|
+
with new lines.
|
39
|
+
- However, you don't want to preserve
|
40
|
+
lines inside each item.
|
41
|
+
* And you might need various bullet
|
42
|
+
characters.
|
43
|
+
• Including unicode ones.
|
44
|
+
|
45
|
+
And don't forget that the list still needs
|
46
|
+
to be separated from the following text.
|
47
|
+
"""
|
48
|
+
...
|
49
|
+
```
|
50
|
+
|
51
|
+
With this package, you could do:
|
52
|
+
```python
|
53
|
+
from docstring_to_text import *
|
54
|
+
|
55
|
+
clean_text = format_docstring(cleandoc(MyClass.__doc__))
|
56
|
+
clean_text = format_object_docstring(MyClass)
|
57
|
+
```
|
58
|
+
|
59
|
+
Then, the resulting string would be:
|
60
|
+
```text
|
61
|
+
Here's a class.
|
62
|
+
|
63
|
+
It has sphinx-like paragraphs, which can span multiple lines. Any modern IDE would display them as a single line, that wraps the given width.
|
64
|
+
You can't just remove all the new lines in the entire string, because you want to preserve paragraphs themselves.
|
65
|
+
Also, when it comes to lists:
|
66
|
+
- You probably want to separate items with new lines.
|
67
|
+
- However, you don't want to preserve lines inside each item.
|
68
|
+
* And you might need various bullet characters.
|
69
|
+
• Including unicode ones.
|
70
|
+
And don't forget that the list still needs to be separated from the following text.
|
71
|
+
```
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# docstring-to-text
|
2
|
+
|
3
|
+
A simple pip package converting docstrings into clean text (proper paragraphs and indents).
|
4
|
+
|
5
|
+
For example, here's a class docstring:
|
6
|
+
```python
|
7
|
+
class MyClass:
|
8
|
+
"""
|
9
|
+
Here's a class.
|
10
|
+
|
11
|
+
|
12
|
+
It has sphinx-like paragraphs, which can
|
13
|
+
span multiple lines. Any modern IDE would
|
14
|
+
display them as a single line, that wraps
|
15
|
+
the given width.
|
16
|
+
|
17
|
+
You can't just remove all the new lines
|
18
|
+
in the entire string, because you want
|
19
|
+
to preserve paragraphs themselves.
|
20
|
+
|
21
|
+
Also, when it comes to lists:
|
22
|
+
- You probably want to separate items
|
23
|
+
with new lines.
|
24
|
+
- However, you don't want to preserve
|
25
|
+
lines inside each item.
|
26
|
+
* And you might need various bullet
|
27
|
+
characters.
|
28
|
+
• Including unicode ones.
|
29
|
+
|
30
|
+
And don't forget that the list still needs
|
31
|
+
to be separated from the following text.
|
32
|
+
"""
|
33
|
+
...
|
34
|
+
```
|
35
|
+
|
36
|
+
With this package, you could do:
|
37
|
+
```python
|
38
|
+
from docstring_to_text import *
|
39
|
+
|
40
|
+
clean_text = format_docstring(cleandoc(MyClass.__doc__))
|
41
|
+
clean_text = format_object_docstring(MyClass)
|
42
|
+
```
|
43
|
+
|
44
|
+
Then, the resulting string would be:
|
45
|
+
```text
|
46
|
+
Here's a class.
|
47
|
+
|
48
|
+
It has sphinx-like paragraphs, which can span multiple lines. Any modern IDE would display them as a single line, that wraps the given width.
|
49
|
+
You can't just remove all the new lines in the entire string, because you want to preserve paragraphs themselves.
|
50
|
+
Also, when it comes to lists:
|
51
|
+
- You probably want to separate items with new lines.
|
52
|
+
- However, you don't want to preserve lines inside each item.
|
53
|
+
* And you might need various bullet characters.
|
54
|
+
• Including unicode ones.
|
55
|
+
And don't forget that the list still needs to be separated from the following text.
|
56
|
+
```
|
@@ -1,23 +1,24 @@
|
|
1
|
-
@echo off
|
2
|
-
|
3
|
-
call .\venv\Scripts\activate.bat
|
4
|
-
|
5
|
-
echo Where python:
|
6
|
-
echo.
|
7
|
-
where python
|
8
|
-
echo.
|
9
|
-
echo
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
.\venv\Scripts\python.exe -m pip install -U
|
15
|
-
|
16
|
-
|
17
|
-
echo.
|
18
|
-
echo
|
19
|
-
echo
|
20
|
-
echo.
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
call .\venv\Scripts\activate.bat
|
4
|
+
|
5
|
+
echo Where python:
|
6
|
+
echo.
|
7
|
+
where python
|
8
|
+
echo.
|
9
|
+
echo BUILD?
|
10
|
+
echo.
|
11
|
+
|
12
|
+
pause
|
13
|
+
|
14
|
+
.\venv\Scripts\python.exe -m pip install -U pip
|
15
|
+
.\venv\Scripts\python.exe -m pip install -U build
|
16
|
+
|
17
|
+
echo.
|
18
|
+
echo.
|
19
|
+
echo ============================================================
|
20
|
+
echo.
|
21
|
+
echo.
|
22
|
+
|
23
|
+
.\venv\Scripts\python.exe -m build
|
24
|
+
pause
|
@@ -0,0 +1,24 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
call .\venv\Scripts\activate.bat
|
4
|
+
|
5
|
+
echo Where python:
|
6
|
+
echo.
|
7
|
+
where python
|
8
|
+
echo.
|
9
|
+
echo RELEASE?
|
10
|
+
echo.
|
11
|
+
|
12
|
+
pause
|
13
|
+
|
14
|
+
.\venv\Scripts\python.exe -m pip install -U pip
|
15
|
+
.\venv\Scripts\python.exe -m pip install -U twine
|
16
|
+
|
17
|
+
echo.
|
18
|
+
echo.
|
19
|
+
echo ============================================================
|
20
|
+
echo.
|
21
|
+
echo.
|
22
|
+
|
23
|
+
.\venv\Scripts\python.exe -m twine upload dist/*
|
24
|
+
pause
|
@@ -0,0 +1,24 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
call .\venv\Scripts\activate.bat
|
4
|
+
|
5
|
+
echo Where python:
|
6
|
+
echo.
|
7
|
+
where python
|
8
|
+
echo.
|
9
|
+
echo Upload to TEST PyPI?
|
10
|
+
echo.
|
11
|
+
|
12
|
+
pause
|
13
|
+
|
14
|
+
.\venv\Scripts\python.exe -m pip install -U pip
|
15
|
+
.\venv\Scripts\python.exe -m pip install -U twine
|
16
|
+
|
17
|
+
echo.
|
18
|
+
echo.
|
19
|
+
echo ============================================================
|
20
|
+
echo.
|
21
|
+
echo.
|
22
|
+
|
23
|
+
.\venv\Scripts\python.exe -m twine upload --repository testpypi dist/*
|
24
|
+
pause
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# https://packaging.python.org/en/latest/tutorials/packaging-projects/
|
2
|
+
|
1
3
|
[build-system]
|
2
4
|
requires = ["hatchling >= 1.26"]
|
3
5
|
build-backend = "hatchling.build"
|
@@ -23,7 +25,7 @@ classifiers = [
|
|
23
25
|
]
|
24
26
|
|
25
27
|
[project.urls]
|
26
|
-
|
28
|
+
"Source Code" = "https://github.com/Lex-DRL/Py-docstring-to-text"
|
27
29
|
Issues = "https://github.com/Lex-DRL/Py-docstring-to-text/issues"
|
28
30
|
|
29
31
|
[tool.hatch.version]
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
"""
|
3
|
+
A simple pip package converting docstrings into clean text (proper paragraphs and indents).
|
4
|
+
"""
|
5
|
+
|
6
|
+
import typing as _t
|
7
|
+
|
8
|
+
from inspect import cleandoc, getdoc
|
9
|
+
import re as _re
|
10
|
+
|
11
|
+
from .__package_meta import VERSION
|
12
|
+
from .__package_meta import VERSION as __version__
|
13
|
+
|
14
|
+
|
15
|
+
_re_indent_match = _re.compile(r"(\t*)( +)(\t*)(.*?)$").match
|
16
|
+
_re_tab_indent_match = _re.compile(r"(\t+)(.*?)$").match
|
17
|
+
_re_list_line_match = _re.compile(
|
18
|
+
r"(\s*)("
|
19
|
+
r"[-*•]+"
|
20
|
+
r"|"
|
21
|
+
r"[a-zA-Z]\s*[.)]"
|
22
|
+
r"|"
|
23
|
+
r"[0-9+]\s*[.)]"
|
24
|
+
r")\s+"
|
25
|
+
).match
|
26
|
+
|
27
|
+
|
28
|
+
def _recover_tab_indents(line: str, tab_size: int):
|
29
|
+
"""Turn indenting spaces back to tabs using regexp. Half-tab indents are rounded."""
|
30
|
+
assert bool(line) and isinstance(line, str)
|
31
|
+
|
32
|
+
n_tabs = 0.0
|
33
|
+
|
34
|
+
match = _re_indent_match(line)
|
35
|
+
while match:
|
36
|
+
pre_tabs, spaces, post_tabs, line = match.groups()
|
37
|
+
n_tabs_from_spaces = float(len(spaces)) / tab_size + 0.00001
|
38
|
+
n_post_tabs = len(post_tabs)
|
39
|
+
if n_post_tabs > 0:
|
40
|
+
# There are tabs after spaces. Don't preserve the fractional spaces-indent, truncate it:
|
41
|
+
n_tabs_from_spaces = int(n_tabs_from_spaces)
|
42
|
+
n_tabs += len(pre_tabs) + n_tabs_from_spaces + n_post_tabs
|
43
|
+
match = _re_indent_match(line)
|
44
|
+
|
45
|
+
if n_tabs < 0.5:
|
46
|
+
return line
|
47
|
+
|
48
|
+
tabs_prefix = '\t' * int(n_tabs + 0.50001)
|
49
|
+
return f"{tabs_prefix}{line}"
|
50
|
+
|
51
|
+
|
52
|
+
def _join_paragraph_and_format_tabs(paragraph: _t.List[str], tab_size: int):
|
53
|
+
"""
|
54
|
+
Given "continuous" paragraph (i.e., with no empty newlines between chunks), recover tabs for each chunk
|
55
|
+
and join them together into a single actual line.
|
56
|
+
Works as a generator to account for blocks with different indents - to make each its own line.
|
57
|
+
"""
|
58
|
+
pending_indent = 0
|
59
|
+
pending_chunks: _t.List[str] = list()
|
60
|
+
|
61
|
+
def join_pending_chunks() -> str:
|
62
|
+
return "{}{}".format('\t' * pending_indent, ' '.join(pending_chunks))
|
63
|
+
|
64
|
+
for chunk in paragraph:
|
65
|
+
chunk = _recover_tab_indents(chunk, tab_size)
|
66
|
+
|
67
|
+
cur_indent = 0
|
68
|
+
match = _re_tab_indent_match(chunk)
|
69
|
+
if match:
|
70
|
+
tab_indent, chunk = match.groups() # We've detected indent. Now, get rid of it.
|
71
|
+
cur_indent = len(tab_indent)
|
72
|
+
|
73
|
+
match_list_line = _re_list_line_match(chunk)
|
74
|
+
# In case of a bulleted/numbered list, we'll need to start a new block, too.
|
75
|
+
if cur_indent == pending_indent and not match_list_line:
|
76
|
+
pending_chunks.append(chunk)
|
77
|
+
continue
|
78
|
+
|
79
|
+
# Indent mismatch or a list line:
|
80
|
+
# we're either ended one block or entered another. Either way, the previous block ends.
|
81
|
+
if pending_chunks:
|
82
|
+
yield join_pending_chunks()
|
83
|
+
pending_chunks = list()
|
84
|
+
assert not pending_chunks
|
85
|
+
pending_chunks.append(chunk)
|
86
|
+
pending_indent = cur_indent
|
87
|
+
|
88
|
+
if pending_chunks:
|
89
|
+
yield join_pending_chunks()
|
90
|
+
|
91
|
+
|
92
|
+
def _formatted_paragraphs_gen(doc: str, tab_size: int):
|
93
|
+
"""
|
94
|
+
Generator, which splits docstring into lines and transforms them into an actual printable output:
|
95
|
+
- From each bulk of empty lines, the first one is skipped...
|
96
|
+
- ... thus, non-empty lines are joined into continuous paragraphs.
|
97
|
+
- Recover tabs in the beginning oh lines (``inspect.cleandoc()`` converts them into spaces).
|
98
|
+
"""
|
99
|
+
if not doc:
|
100
|
+
return
|
101
|
+
doc = str(doc)
|
102
|
+
if not doc.strip():
|
103
|
+
return
|
104
|
+
|
105
|
+
tab_size = max(int(tab_size), 1)
|
106
|
+
|
107
|
+
cur_paragraph: _t.List[str] = list()
|
108
|
+
|
109
|
+
for line in doc.splitlines():
|
110
|
+
line: str = line.rstrip()
|
111
|
+
if line:
|
112
|
+
cur_paragraph.append(line)
|
113
|
+
continue
|
114
|
+
|
115
|
+
assert not line
|
116
|
+
if cur_paragraph:
|
117
|
+
for block in _join_paragraph_and_format_tabs(cur_paragraph, tab_size):
|
118
|
+
yield block
|
119
|
+
cur_paragraph = list()
|
120
|
+
# Just skip the current empty line entirely - do nothing with it.
|
121
|
+
continue
|
122
|
+
|
123
|
+
# We're in a chain of empty lines, and we've already skipped the first one. Preserve the remaining ones:
|
124
|
+
yield ''
|
125
|
+
|
126
|
+
# Return the last paragraph post-loop:
|
127
|
+
if cur_paragraph:
|
128
|
+
for block in _join_paragraph_and_format_tabs(cur_paragraph, tab_size):
|
129
|
+
yield block
|
130
|
+
|
131
|
+
|
132
|
+
def format_docstring(doc: str, tab_size: int = 8) -> str:
|
133
|
+
"""
|
134
|
+
Turn a pre-cleaned-up docstring (with tabs as spaces and newlines mid-sentence)
|
135
|
+
into an actually printable output:
|
136
|
+
- mid-paragraph new lines are replaced with spaces...
|
137
|
+
- ... while still keeping indented blocks separate.
|
138
|
+
|
139
|
+
Remember to pass a pre-cleaned-up docstring - i.e., with one of:
|
140
|
+
- format_docstring(inspect.cleandoc(__doc__))
|
141
|
+
- format_docstring(inspect.getdoc(class_or_function))
|
142
|
+
"""
|
143
|
+
return '\n'.join(_formatted_paragraphs_gen(doc, tab_size))
|
144
|
+
|
145
|
+
|
146
|
+
def format_object_docstring(_obj, tab_size: int = 8) -> str:
|
147
|
+
"""Find the object's docstring and format it with ``format_docstring()``"""
|
148
|
+
doc = getdoc(_obj)
|
149
|
+
if not doc:
|
150
|
+
return ''
|
151
|
+
# noinspection PyArgumentList
|
152
|
+
return format_docstring(doc, tab_size=tab_size)
|
docstring_to_text-0.0.1/PKG-INFO
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: docstring-to-text
|
3
|
-
Version: 0.0.1
|
4
|
-
Summary: A simple pip package converting docstrings into clean text (proper paragraphs and indents)
|
5
|
-
Project-URL: Homepage, https://github.com/Lex-DRL/Py-docstring-to-text
|
6
|
-
Project-URL: Issues, https://github.com/Lex-DRL/Py-docstring-to-text/issues
|
7
|
-
Author: Lex Darlog (Lex-DRL)
|
8
|
-
License-Expression: MPL-2.0
|
9
|
-
License-File: LICENSE.md
|
10
|
-
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
|
11
|
-
Classifier: Operating System :: OS Independent
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
13
|
-
Requires-Python: >=3.7
|
14
|
-
Description-Content-Type: text/markdown
|
15
|
-
|
16
|
-
# docstring-to-text
|
17
|
-
|
18
|
-
A simple pip package converting docstrings into clean text (proper paragraphs and indents)
|
File without changes
|
File without changes
|
File without changes
|