Skip to main content

Nirjas ~ নির্যাস

A Python library for Comments and Source Code Extraction

✨ 🍰 ✨

python version Unit Tests status License LGPL-2.1 release Slack Channel stars

Description

A source code file usually contains various vital information such as license text, function/class documentation, code/logic explanation, etc in the form of comments (block & line).

Nirjas is a fully dedicated python library to extract the comments and source code out of your file(s). The extracted comments can be processed in various ways to detect licenses, generate documentation, process info, etc.

Apart from that the library serves you with all the required metadata about your Code, Comments and File(s)

Requirements

  • Python 3

Installing Python on Linux machines:

$ sudo apt-get install python3 python3-pip

For macOS and Windows, packages are available at Python.org

Supported Languages

We Support almost all the major programming languages. If you want any other language to be added, feel free to raise an issue.

The Languages we support till now:

  • C
  • C#
  • C++
  • CSS
  • Dart
  • Go
  • Haskell
  • HTML
  • Java
  • JavaScript
  • JSX
  • Kotlin
  • MATLAB
  • Perl
  • PHP
  • Python
  • R
  • Ruby
  • Rust
  • Scala
  • Scss
  • Shell
  • Swift
  • TypeScript
  • TSX

Installation

Install using pip

You’ll need to make sure you have pip available. You can check this by running:

pip --version

If you installed Python from source, with an installer from python.org, you should already have pip. If you’re on Linux and installed using your OS package manager, you may have to install pip separately.

Haven’t installed pip? Visit: https://pip.pypa.io/en/stable/installing/

Install the latest official release via pip. This is the best approach for most users. It will provide a stable version and are available for most platforms.

  • Update pip to the latest stable version
pip3 install --upgrade pip
  • Install Nirjas
pip3 install nirjas
  • Upgrading Nirjas

Upgrade already installed Nirjas library to the latest version from PyPI.

pip3 install --upgrade Nirjas

Install using source

If you are interested in contributing to Nirjas development, running the latest source code, or just like to build everything yourself, it is not difficult to install & build Nirjas from the source.

  • Fork the repo

  • Clone on your local system

git clone https://github.com/fossology/Nirjas.git
  • Change directory
cd Nirjas/
  • Install the package
pip3 install .

This will install Nirjas on your system.

  • Check if Nirjas is installed correctly or get help, Run:

    nirjas -h or nirjas --help

Docker image

Nirjas also hosts Docker images on Docker hub. They can be pulled using

docker pull fossology/nirjas:latest

To scan with Docker image, just mount the directory you want to analyze and pass the path as argument.

docker run --rm -v $(pwd):/opt/ fossology/nirjas:latest /opt/<file_to_analyze>

Example Usage

  • For help
nirjas -h
  • To extract comments from a single file
nirjas <path to file>
  • To extract strings which assigned to variables from a source code file (Not yet implemented)
nirjas <path to source code file>
  • To extract comments from all the files in directory/sub-directory
nirjas <path to directory>
  • To extract only source code (excludes commented part) out of a file
nirjas -i <target file> <new file name including extension>

or for default file generation (default file: source.txt)

nirjas -i <target file>

Tests

To run a test for Nirjas, execute the following script:

python3 testScript.py

This will download all the test files into nirjas/languages/tests/TestFiles folder and will run the tests as well.

Documentation

We maintain our entire documentation at GitHub wiki. Feel free to switch from code to wiki or just click here - Nirjas Documentation

Contributing

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.

A detailed overview on how to contribute can be found in the contributing guide.

Feel free to ask questions or discuss suggestions on Slack

License

This repository is licensed under the terms of LGPL-2.1. Check the LICENSE file for more details.

Release files for Nirjas 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Nirjas 1.0.1
File Size Uploaded
Nirjas-1.0.1.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Nirjas 1.0.1
File Interpreter ABI Platform
Nirjas-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 124.4 kB

Release files / Nirjas-1.0.1.tar.gz

Download URL Nirjas-1.0.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
557e0d841b4398c10cd69b86522e52a8135a78665cd9a3ce281685405179eb5f
BLAKE2b-256 checksum
How to use checksums
61fde818576550b2403710d4b262891867ac7b41bdbff50ea5e6d100bd1fc54c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

Release files / Nirjas-1.0.1-py3-none-any.whl

Download URL Nirjas-1.0.1-py3-none-any.whl
Size 101.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3682ef943dfcde5a56e5ac1021c1e7edd9a3e9e060731efe3336d799ee6a8383
BLAKE2b-256 checksum
How to use checksums
b273c6e0bf1496fe794deb73dec0586443d912297cf02b772a26e4db34bf9523
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page