Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Python package for extracting comments from source code.
Multiple programming and markup languages are supported: see list.
$ pip3 install commie
from pathlib import Path
import commie
for comment in commie.iter_comments(Path("/path/to/source.cpp")):
# something like "/* sample */"
print("Comment code:", comment.code)
print("Comment code location:", comment.code_span.start, comment.code_span.end)
# something like " sample "
print("Comment inner text:", comment.text)
print("Comment text location:", comment.text_span.start, comment.text_span.end)
Method | Works for |
---|---|
commie.iter_comments_c | C, C++, C#, Java, Objective-C, JavaScript, Dart, TypeScript |
commie.iter_comments_go | Go |
commie.iter_comments_ruby | Ruby |
commie.iter_comments_python | Python |
commie.iter_comments_shell | Bash, Sh |
commie.iter_comments_html | HTML, XML, SGML |
commie.iter_comments_css | CSS |
commie.iter_comments_sass | SASS |
import commie
source_code_in_golang:str = ...
for comment in commie.iter_comments_go(source_code_in_golang):
# ... process comment ...
pass
Method commie.iter_comments
will try to guess the file format from the provided filename.
from pathlib import Path
import commie
filename: str = "/path/to/mycode.go"
source_code: str = Path(filename).read_text()
for comment in commie.iter_comments(source_code, filename=filename):
# ... process comment ...
pass
When single-line comments are adjacent, it makes sense to consider them together:
// Group A: A short comment
// Group B: It consists of three
// single-line comments with
// no empty lines between them
// Group C: This paragraph loosely
// stretched into two lines
The comments from the example above can be combined into three groups as follows:
from commie import iter_comments, group_singleline_comments
for group in group_singleline_comments(iter_comments(...)):
# ... each group is a list of Comment objects ...
pass
Multi-line comments will also be returned. They will not be grouped with their neighbors.
This project was forked from comment_parser in 2021. Motivation:
comment_parser | commie |
---|---|
Returns only a line number | Returns positions where the comment starts and ends. Just like regular string search |
Returns only the text of a comment | Respects markup as well, making it possible to remove or replace the entire comment |
Depends on python-magic that requires an optional installation of binaries | Pure Python. Easy to install with pip |
FAQs
Extracts comments from source code in different programming languages
We found that commie demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.