Add feature to parse Python docstrings

This commit is contained in:
2026-04-13 14:44:04 +02:00
parent 16852f3d68
commit b71b93000e
5 changed files with 58 additions and 11 deletions
+14 -8
View File
@@ -3,27 +3,33 @@ Third-Party Notices
This software uses the following third-party libraries. Full license texts are available in the 'licenses/' directory. This software uses the following third-party libraries. Full license texts are available in the 'licenses/' directory.
1. iniconfig 2.3.0 1. docstring-parser 0.17.0
Author: Marcin Kurczewski
License: MIT License
See licenses/docstring-parser.txt for full license text.
2. iniconfig 2.3.0
Author: Holger Krekel and others Author: Holger Krekel and others
License: MIT License License: MIT License
See licenses/iniconfig.txt for full license text. See licenses/iniconfig.txt for full license text.
2. packaging 26.0 3. packaging 26.0
Author: Donald Stufft and individual contributors Author: Donald Stufft and individual contributors
License: Apache License 2.0 License: Apache License 2.0
URL: None
See licenses/packaging.txt for full license text. See licenses/packaging.txt for full license text.
3. pluggy 1.6.0 4. pluggy 1.6.0
Author: Holger rekel Author: Holger Krekel
License: MIT License License: MIT License
See licenses/pluggy.txt for full license text. See licenses/pluggy.txt for full license text.
4. pygments 2.18.0 5. pygments 2.18.0
Author: Georg Brandl, Tim Hatch, Armin Ronacher, Others Author: Georg Brandl, Tim Hatch, Armin Ronacher, Others
License: BSD-2-Clause License: BSD-2-Clause
See licenses/pygments.txt for full license text. See licenses/pygments.txt for full license text.
5. pytest 9.0.2 6. pytest 9.0.2
Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin, Others (See AUTHORS) Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin, Others
License: MIT License License: MIT License
See licenses/pytest.txt for full license text. See licenses/pytest.txt for full license text.
+2 -1
View File
@@ -20,4 +20,5 @@
- Add classes for Python definitions - Add classes for Python definitions
- Add class for Python modules - Add class for Python modules
- Add feature to get the signature representation of a Python function argument - Add feature to get the signature representation of a Python function argument
- Add class for Python docstrings - Add class for Python docstrings
- Add feature to parse Python docstrings
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 Marcin Kurczewski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1 -1
View File
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "jcloud-docsgen" name = "jcloud-docsgen"
version = "0.1.0" version = "0.1.0"
description = "A project documentation generator" description = "A project documentation generator"
dependencies = [] dependencies = ["docstring-parser"]
license = "Apache-2.0" license = "Apache-2.0"
[project.scripts] [project.scripts]
+20 -1
View File
@@ -12,10 +12,19 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from enum import Enum
import docstring_parser
__all__ = [ __all__ = [
'PythonDocstringStyle',
'PythonDocstring' 'PythonDocstring'
] ]
class PythonDocstringStyle(Enum):
SPHINX = 'sphinx'
NUMPY = 'numpy'
GOOGLE = 'google'
class PythonDocstring: class PythonDocstring:
''' '''
Represents a Python docstring. Represents a Python docstring.
@@ -33,4 +42,14 @@ class PythonDocstring:
def __eq__(self, value) -> bool: def __eq__(self, value) -> bool:
if not isinstance(value, type(self)): if not isinstance(value, type(self)):
return False return False
return self.docstring == value.docstring return self.docstring == value.docstring
def parse(self) -> docstring_parser.Docstring:
'''
Parses the docstring.
:return: The parsed docstring.
:rtype: docstring_parser.Docstring
'''
return docstring_parser.parse(self.docstring)