Skip to main content

Parse comments from various source files.

Project description

Comment Parser

PyPI status PyPI version shields.io PyPI license PyPI pyversions

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')

extract_comments signature

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.
    """

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

Running locally

Start python3 in the base of repository.

from comment_parser import comment_parser
comment_parser.extract_comments('foo.c', mime='text/x-c')

Running tests

python3 setup.py test

Deploying to PyPi

python3 setup.py sdist
twine upload dist/*

Supported Programming Languages

Language Mime String
C text/x-c
C++ text/x-c++
Go text/x-go
HTML text/html
Java text/x-java-source
Javascript text/x-javascript
Shell text/x-shellscript
XML text/xml

And more to come!

Check comment_parser.py for corresponding MIME types.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comment_parser-1.0.7.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file comment_parser-1.0.7.tar.gz.

File metadata

  • Download URL: comment_parser-1.0.7.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/33.1.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.13

File hashes

Hashes for comment_parser-1.0.7.tar.gz
Algorithm Hash digest
SHA256 153871390ad5d7093b7a83077c6548afc84027e0bcafdc0b6cb005c09fcf98f7
MD5 d7a144e93811d431c779e463bea14413
BLAKE2b-256 8a1ada14653906a0547903313bad95f31c39c6c41f9a99f5370675d78c86a143

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page