docstring-to-text 1.0.0__tar.gz → 1.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.
@@ -31,24 +31,34 @@ on:
31
31
  branches:
32
32
  - main
33
33
  paths:
34
- - "src/docstring_to_text/__package_meta.py"
34
+ - "src/docstring_to_text/___package_meta.py"
35
+
36
+ # ====== CONCURRENCY ======
37
+
38
+ # Prevent multiple simultaneous builds for the same version:
39
+ concurrency:
40
+ group: pypi-publish
41
+ # To group by version:
42
+ #group: pypi-publish-${{ github.ref }}-${{ hashFiles('src/docstring_to_text/___package_meta.py') }}
43
+ cancel-in-progress: false # the second pending run is put into a queue, the third one is cancelled (GitHub limitation)
35
44
 
36
45
  # ======= ENV VARS =======
37
46
 
38
47
  env:
39
48
  # The name on PyPI:
40
49
  PACKAGE_NAME: 'docstring-to-text'
41
- VERSION_MODULE: 'src.docstring_to_text.__package_meta'
50
+ VERSION_FILE: 'src/docstring_to_text/___package_meta.py'
51
+ VERSION_MODULE: 'src.docstring_to_text.___package_meta'
42
52
  VERSION_VARIABLE: 'VERSION'
43
53
 
44
-
45
54
  # ========= JOBS =========
46
55
 
47
56
  jobs:
48
57
 
49
58
  detect-version:
50
59
  # https://emojidb.org/query-emojis
51
- name: Parse version 🔢 + add Tag 🏷️
60
+ name: Parse version 🔢
61
+ # Just to be nice - let's check the GitHub user and prevent unwanted auto-runs on forks made solely for a PR:
52
62
  if: ${{ github.repository_owner == 'Lex-DRL' }}
53
63
  runs-on: ubuntu-latest
54
64
  permissions:
@@ -64,15 +74,53 @@ jobs:
64
74
  with:
65
75
  fetch-depth: 0 # Fetch full history to avoid issues with tags and branches
66
76
 
67
- - name: Extract version from package meta 📝
77
+ - name: Set up Python
78
+ uses: actions/setup-python@v5
79
+ with:
80
+ python-version: "3.x"
81
+
82
+ - name: Extract version 🔢 from package meta 📝
68
83
  id: get_version_string
69
84
  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 }})")
85
+ # Try doing it with Python first:
86
+ VERSION=$(
87
+ python -c \
88
+ "from ${{ env.VERSION_MODULE }} import ${{ env.VERSION_VARIABLE }}; print(${{ env.VERSION_VARIABLE }})" \
89
+ 2>/dev/null \
90
+ | head -1
91
+ )
92
+ if [ $? -ne 0 ] || [ -z "$VERSION" ]; then # previous command had non-zero exit status or version is empty
93
+ echo "Failed to retrieve version with python. Attempting to parse it directly from file, with regexp..."
94
+ VERSION=$(
95
+ grep -oP "^\s*${{ env.VERSION_VARIABLE }}\s*=\s*['\"]\K[^'\"]+" "${{ env.VERSION_FILE }}" \
96
+ 2>/dev/null \
97
+ | head -1
98
+ )
99
+ fi
100
+ if [ $? -ne 0 ] || [ -z "$VERSION" ]; then
101
+ echo "Error: Failed to retrieve version." >&2
102
+ exit 1
103
+ fi
72
104
  echo "Version string: $VERSION"
73
105
  echo "version=${VERSION}" >> $GITHUB_OUTPUT
74
106
 
75
- - name: Parse Version 🧱
107
+ # TODO: get rid of the following bash insanity and just parse it with a special python script / shared module.
108
+ # Writing the output would use:
109
+ # with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
110
+ # print(f"{key}={value}", file=fh)
111
+ # - name: Parse Version with Python
112
+ # id: parse-with-python
113
+ # run: >-
114
+ # python parse_version.py
115
+ # "${{ steps.get_version_string.outputs.version }}"
116
+ # # Alternatively:
117
+ # #run: |
118
+ # # python -c "
119
+ # # # The entire python script inline
120
+ # # version_str = '${{ steps.get_version_string.outputs.version }}'.lstrip('v')
121
+ # # "
122
+
123
+ - name: Parse Version into parts 🧱
76
124
  id: parse
77
125
  # The main magic happens in regexps...
78
126
  # - `grep -qP`: verify that the tag matches the given pattern
@@ -121,29 +169,16 @@ jobs:
121
169
  echo "version_num=$VERSION_NUMBER" >> "$GITHUB_OUTPUT"
122
170
  echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
123
171
 
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
172
  # --------------------------------------------------------
138
173
 
139
174
  build:
140
175
  name: Build distribution 📦
141
176
  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
177
  if: >-
144
178
  github.repository_owner == 'Lex-DRL'
145
179
  # 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`
180
+ # It was in the template from official tutorial, but it got redundant with our deep version parsing and verification
181
+ # Kept here just as a condition example:
147
182
  # && startsWith(github.ref, 'refs/tags/v')
148
183
  runs-on: ubuntu-latest
149
184
 
@@ -165,6 +200,8 @@ jobs:
165
200
  build
166
201
  --user
167
202
 
203
+ # TODO: run tests before the build
204
+
168
205
  - name: Build a binary wheel and a source tarball
169
206
  run: python3 -m build
170
207
 
@@ -233,30 +270,43 @@ jobs:
233
270
  # --------------------------------------------------------
234
271
 
235
272
  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
273
+ name: GitHub Tag 🏷️ + Release 🔄
274
+ needs: [build, detect-version]
275
+ runs-on: ubuntu-latest
276
+ permissions:
277
+ contents: write
278
+ steps:
279
+ - name: Checkout Code
280
+ uses: actions/checkout@v4
281
+ with:
282
+ fetch-depth: 0 # Fetch full history to avoid issues with tags and branches
283
+
284
+ - name: Download artifacts
285
+ uses: actions/download-artifact@v4
286
+ with:
287
+ name: python-package-distributions
288
+ path: dist/
289
+
290
+ - name: Create tag 🏷️ from version
291
+ uses: actions/github-script@v7
292
+ with:
293
+ script: |
294
+ github.rest.git.createRef({
295
+ owner: context.repo.owner,
296
+ repo: context.repo.repo,
297
+ ref: `refs/tags/${process.env.TAG}`,
298
+ sha: context.sha
299
+ })
300
+ env:
301
+ TAG: ${{ needs.detect-version.outputs.tag_name }}
302
+
303
+ - name: Create GitHub Release 🔄
304
+ id: create_release
305
+ env:
306
+ GH_TOKEN: ${{ github.token }}
307
+ run: >-
308
+ gh release create
309
+ ${{ needs.detect-version.outputs.tag_name }}
310
+ dist/*
311
+ --title ${{ needs.detect-version.outputs.tag_name }}
312
+ --generate-notes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring-to-text
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: A simple pip package converting docstrings into clean text (proper paragraphs and indents)
5
5
  Project-URL: Source Code, https://github.com/Lex-DRL/Py-docstring-to-text
6
6
  Project-URL: Issues, https://github.com/Lex-DRL/Py-docstring-to-text/issues
@@ -13,15 +13,26 @@ Classifier: Programming Language :: Python :: 3
13
13
  Requires-Python: >=3.7
14
14
  Description-Content-Type: text/markdown
15
15
 
16
+ <div align="center">
17
+
16
18
  # docstring-to-text
17
19
 
20
+ [![PyPI][pypi-shield]][pypi-url]
21
+ [![][github-release-shield]][github-release-url]
22
+
23
+ [pypi-shield]: https://img.shields.io/pypi/v/docstring-to-text?logo=pypi
24
+ [pypi-url]: https://pypi.org/p/docstring-to-text
25
+ [github-release-shield]: https://img.shields.io/github/v/release/Lex-DRL/Py-docstring-to-text?logo=github
26
+ [github-release-url]: https://github.com/Lex-DRL/Py-docstring-to-text/releases/latest
27
+ </div>
28
+
18
29
  A simple pip package converting docstrings into clean text (proper paragraphs and indents).
19
30
 
20
31
  For example, here's a class docstring:
21
32
  ```python
22
33
  class MyClass:
23
34
  """
24
- Here's a class.
35
+ This is a class docstring.
25
36
 
26
37
 
27
38
  It has sphinx-like paragraphs, which can
@@ -34,12 +45,14 @@ class MyClass:
34
45
  to preserve paragraphs themselves.
35
46
 
36
47
  Also, when it comes to lists:
37
- - You probably want to separate items
48
+ - You probably want to separate items
38
49
  with new lines.
39
- - However, you don't want to preserve
50
+ - However, you don't want to preserve
40
51
  lines inside each item.
41
- * And you might need various bullet
42
- characters.
52
+
53
+ And...
54
+ * ... you might need various bullet
55
+ characters.
43
56
  • Including unicode ones.
44
57
 
45
58
  And don't forget that the list still needs
@@ -58,14 +71,15 @@ clean_text = format_object_docstring(MyClass)
58
71
 
59
72
  Then, the resulting string would be:
60
73
  ```text
61
- Here's a class.
74
+ This is a class docstring.
62
75
 
63
76
  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
77
  You can't just remove all the new lines in the entire string, because you want to preserve paragraphs themselves.
65
78
  Also, when it comes to lists:
66
79
  - You probably want to separate items with new lines.
67
80
  - However, you don't want to preserve lines inside each item.
68
- * And you might need various bullet characters.
81
+ And...
82
+ * ... you might need various bullet characters.
69
83
  • Including unicode ones.
70
84
  And don't forget that the list still needs to be separated from the following text.
71
85
  ```
@@ -1,12 +1,23 @@
1
+ <div align="center">
2
+
1
3
  # docstring-to-text
2
4
 
5
+ [![PyPI][pypi-shield]][pypi-url]
6
+ [![][github-release-shield]][github-release-url]
7
+
8
+ [pypi-shield]: https://img.shields.io/pypi/v/docstring-to-text?logo=pypi
9
+ [pypi-url]: https://pypi.org/p/docstring-to-text
10
+ [github-release-shield]: https://img.shields.io/github/v/release/Lex-DRL/Py-docstring-to-text?logo=github
11
+ [github-release-url]: https://github.com/Lex-DRL/Py-docstring-to-text/releases/latest
12
+ </div>
13
+
3
14
  A simple pip package converting docstrings into clean text (proper paragraphs and indents).
4
15
 
5
16
  For example, here's a class docstring:
6
17
  ```python
7
18
  class MyClass:
8
19
  """
9
- Here's a class.
20
+ This is a class docstring.
10
21
 
11
22
 
12
23
  It has sphinx-like paragraphs, which can
@@ -19,12 +30,14 @@ class MyClass:
19
30
  to preserve paragraphs themselves.
20
31
 
21
32
  Also, when it comes to lists:
22
- - You probably want to separate items
33
+ - You probably want to separate items
23
34
  with new lines.
24
- - However, you don't want to preserve
35
+ - However, you don't want to preserve
25
36
  lines inside each item.
26
- * And you might need various bullet
27
- characters.
37
+
38
+ And...
39
+ * ... you might need various bullet
40
+ characters.
28
41
  • Including unicode ones.
29
42
 
30
43
  And don't forget that the list still needs
@@ -43,14 +56,15 @@ clean_text = format_object_docstring(MyClass)
43
56
 
44
57
  Then, the resulting string would be:
45
58
  ```text
46
- Here's a class.
59
+ This is a class docstring.
47
60
 
48
61
  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
62
  You can't just remove all the new lines in the entire string, because you want to preserve paragraphs themselves.
50
63
  Also, when it comes to lists:
51
64
  - You probably want to separate items with new lines.
52
65
  - However, you don't want to preserve lines inside each item.
53
- * And you might need various bullet characters.
66
+ And...
67
+ * ... you might need various bullet characters.
54
68
  • Including unicode ones.
55
69
  And don't forget that the list still needs to be separated from the following text.
56
70
  ```
@@ -29,4 +29,4 @@ classifiers = [
29
29
  Issues = "https://github.com/Lex-DRL/Py-docstring-to-text/issues"
30
30
 
31
31
  [tool.hatch.version]
32
- path = "src/docstring_to_text/__package_meta.py"
32
+ path = "src/docstring_to_text/___package_meta.py"
@@ -1,3 +1,3 @@
1
1
  # encoding: utf-8
2
2
 
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.2"
@@ -3,13 +3,32 @@
3
3
  A simple pip package converting docstrings into clean text (proper paragraphs and indents).
4
4
  """
5
5
 
6
+ # This Source Code Form is subject to the terms of the Mozilla Public
7
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+
6
10
  import typing as _t
7
11
 
8
12
  from inspect import cleandoc, getdoc
9
13
  import re as _re
10
14
 
11
- from .__package_meta import VERSION
12
- from .__package_meta import VERSION as __version__
15
+ from .___package_meta import VERSION
16
+ from .___package_meta import VERSION as __version__
17
+
18
+ # TODO:
19
+ # - lists
20
+ # formatted with indents
21
+ # in all lines except for the first one
22
+ #
23
+ # Also...
24
+ # - preserve indents
25
+ # - of the entire list
26
+ #
27
+ # And...
28
+ # - ensure
29
+ # that
30
+ # - it all works
31
+ # with nested lists
13
32
 
14
33
 
15
34
  _re_indent_match = _re.compile(r"(\t*)( +)(\t*)(.*?)$").match