1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
Comment Parser
Python module used to extract comments from source code files of various types.
Installation
Prerequisites
- libmagic
Linux/Unix
sudo pip3 install comment_parser
OSX and Windows
Additionally, complete the special installation requirements for python-magic.
Usage
To use, simply run:
>>> from comment_parser import comment_parser
>>> # Returns a list of comment_parser.parsers.common.Comments
>>> comment_parser.extract_comments('/path/to/source_file')
>>> # Or
>>> comment_parser.extract_comments_from_str('...')
extract_comments signatures
def extract_comments(filename, mime=None):
"""Extracts and returns the comments from the given source file.
Args:
filename: String name of the file to extract comments from.
mime: Optional MIME type for file (str). Note some MIME types accepted
don't comply with RFC2045. If not given, an attempt to deduce the
MIME type will occur.
Returns:
Python list of parsers.common.Comment in the order that they appear in
the source file.
Raises:
UnsupportedError: If filename is of an unsupported MIME type.
"""
pass
def extract_comments_from_str(code, mime=None):
"""Extracts and returns comments from the given source string.
Args:
code: String containing code to extract comments from.
mime: Optional MIME type for code (str). Note some MIME types accepted
don't comply with RFC2045. If not given, an attempt to deduce the
MIME type will occur.
Returns:
Python list of parsers.common.Comment in the order that they appear in
the source code.
Raises:
UnsupportedError: If code is of an unsupported MIME type.
"""
pass
Comments Interface
class Comment(object):
"""Represents comments found in source files."""
def text(self):
"""Returns the comment's text.
Returns:
String
"""
pass
def line_number(self):
"""Returns the line number the comment was found on.
Returns:
Int
"""
pass
def is_multiline(self):
"""Returns whether this comment was a multiline comment.
Returns:
True if comment was a multiline comment, False if not.
"""
pass
def __str__(self):
pass
def __eq__(self, other):
pass
Development
Install Dependencies
pip install -r requirements.txt -r requirements-dev.txt
Running locally
Start python in the base of repository.
from comment_parser import comment_parser
comment_parser.extract_comments('foo.c', mime='text/x-c')
Running tests
python -m pytest
Running pylint
pylint comment_parser
Running formatter
yapf -rip .
Deploying to PyPi
python setup.py sdist
twine upload dist/*
Supported Programming Languages
| Language | Mime String |
|---|---|
| C | text/x-c |
| C++/C# | text/x-c++ |
| Go | text/x-go |
| HTML | text/html |
| Java | text/x-java-source |
| Javascript | application/javascript |
| Python | text/x-python |
| Python | text/x-script.python |
| Ruby | text/x-ruby |
| Shell | text/x-shellscript |
| XML | text/xml |
And more to come!
Check comment_parser.py for corresponding MIME types.
Release files for comment-parser 1.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| comment_parser-1.2.5.tar.gz | 8.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| comment_parser-1.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.1 kB
Release files / comment_parser-1.2.5.tar.gz
| Download URL | comment_parser-1.2.5.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5606b769228cafce03d538e361472896581b386f3bc44bd62f4b61ff45ff05ec
|
|
BLAKE2b-256 checksum How to use checksums |
376a354d8e640b5f90996ac07c002189a552226a0ddaad85efd14863166aaa14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 25, 2024.
Transparency logRelease files / comment_parser-1.2.5-py3-none-any.whl
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | comment_parser-1.2.5-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb3dee8f351ebd1cfc22d3f19dabf93a4f7d4c9ea13b2092242de086a4449d9e
|
|
BLAKE2b-256 checksum How to use checksums |
785312ceba92ce55851a3d34123b2774a32689f745ce4c0c9bebca1a2a07e266
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|