Package: cdmpyparser
cdm-pythonparsercdm-pythonparser
projectis a
Python 3 (Python 2 support is limited) extension module. The module
provided functions can take a file with a python code or a character
buffer, parse it and provide back what is found in the code: functions,
classes, global variables etc.The module is used in theCodimension Python
IDEto show in a structured way a content of
an arbitrary python code and for some other features however, it could
be used in other projects which need a python code retrospection.Python 3 Installation and BuildingThemaster
branchon github
contains code for Python 3 (3.5/3.6/3.7/3.8/3.9 grammar is covered).The module can be installed using pip:pipinstallcdmpyparserYou can also retrieve the full source code which in addition has some
utilities. In order to do that you can follow these steps:gitclonehttps://github.com/SergeySatskiy/cdm-pythonparser.gitcdcdm-pythonparsermakemakecheckmakelocalinstallPython 3 UsageSuppose there is the following file ~/my-file.py with the following
content:#!/bin/env pythonimportsys# global variablea=154classC(BaseClass):"""Class docstring"""@staticmethoddefgetValue(arg):"""Method docstring"""returnarg+154Then the following python session may take place:$pythonPython3.6.2(default,Aug92017,11:11:12)[GCC4.8.520150623(RedHat4.8.5-11)]onlinuxType"help","copyright","credits"or"license"formoreinformation.>>>importcdmpyparser>>>c=cdmpyparser.getBriefModuleInfoFromFile('my-file.py')>>>print(c.niceStringify())Import[2:8:25]:'sys'Global[5:1:48]:'a'Class[7:1:7:7:63:7:19]:'C'Baseclass:'BaseClass'Docstring[8]:'Class docstring'Function[10:5:10:9:129:10:22]:'getValue'Argument:'arg'Decorator[9:6:108]:'staticmethod'Docstring[11]:'Method docstring'>>>len(c.imports)1>>>c.imports[0].name'sys'>>>c.imports[0].line2>>>c.imports[0].pos8Note:Python 3 and Python 2 modules use different names. Python 3
usescdmpyparser. Python 2 usescdmbriefparser.See the ‘cdmpyparser.py’ file for the members which are supplied along
with all the recognized items.Python 2 Installation and BuildingAttention:Python 2 version is not supported anymore. There will be
no more Python 2 releases.The latest Python 2 release is 2.0.1. Both pre-built modules and source
code are available in the releases area on github:latest Python 2
release
2.0.1.To build a Python 2 module from sources please follow these steps:cdwgethttps://github.com/SergeySatskiy/cdm-pythonparser/archive/v2.0.1.tar.gzgunzipv2.0.1.tar.gztar-xfv2.0.1.tarcdcdm-pythonparser-2.0.1/makemakelocalinstallmakecheckPython 2 UsageSuppose there is the following file ~/my-file.py with the following
content:#!/bin/env pythonimportsys# global variablea=154classC(BaseClass):"""Class docstring"""@staticmethoddefgetValue(arg):"""Method docstring"""returnarg+154Then the following python session may take place:$pythonPython2.7.12(default,Sep132016,16:46:03)[GCC4.8.520150623(RedHat4.8.5-4)]onlinux2Type"help","copyright","credits"or"license"formoreinformation.>>>importcdmbriefparser>>>c=cdmbriefparser.getBriefModuleInfoFromFile('my-file.py')>>>printc.niceStringify()Import[2:8:25]:'sys'Global[5:1:48]:'a'Class[7:1:7:7:63:7:19]:'C'Baseclass:'BaseClass'Docstring[8]:'Class docstring'Function[10:5:10:9:129:10:22]:'getValue'Argument:'arg'Decorator[9:6:108]:'staticmethod'Docstring[11]:'Method docstring'>>>len(c.imports)1>>>c.imports[0].name'sys'>>>c.imports[0].line2>>>c.imports[0].pos8Note:Python 3 and Python 2 modules use different names. Python 3
usescdmpyparser. Python 2 usescdmbriefparser.See the ‘cdmbriefparser.py’ file for the members which are supplied
along with all the recognized items.Comparison to the Standard pyclbr ModuleNote:the comparison results are provided for the Python 2 module.
The Python 3 module yeilds pretty much the same results in terms of
performance while extracts more information because the grammar was
extended for Python 3.The table below shows the comparison between the standardpyclbrmodule and the Codimension’scdmbriefparsermodule.featurepyclbrcdmbriefparserExtracting coding
stringNYExtracting module
docstringNYExtracting global
variablesNYExtracting
importsNYExtracting top
level functionsYYExtracting nested
functionsNYExtracting
functions
argumentsNYExtracting
functions
docstringsNYExtracting
functions
decoratorsNYExtracting
classesYYExtracting base
classesYYExtracting class
attributesNYExtracting class
instance
attributesNYExtracting class
methodsYYExtracting class
methods argumentsNYExtracting nested
classesNYExtracting
classes
docstringsNYExtracting class
methods
docstringsNYExtracting
classes
decoratorsNYExtracting
decorators
argumentsNYKeeping the
hierarchy of the
classes/functions
of the arbitrary
depthNYAbility to work
with partially
syntactically
correct filesY (silent)Y (error messages are
provided)Ability to parse
python code from
a fileYYAbility to parse
python code from
memoryNYExtracting
classes and
functions with
the same namesNYSupported python
versionANYUp to 2.7 (series 3 has not
been tested)Time to process
11365 python
files (python 2.7
distribution and
some third party
packages).2 min 37 sec24 secEssential LinksCodimension Python IDEhome pagelatest Python 2 release
2.0.1Python 3 Pypi
packagepage