Skip to main content

Tool for automatically adding a header to files in the form of a comment.

Project description

coverage badge CI PyPI version

Ceader

Tool for automatically adding a header to files in the form of a comment.
Based on the file extensions, Ceader detects the programming language and selects the comment character accordingly.

Header sample, created by this software:

                    _                _
   ___ ___ _ __ ___| |__  _ __ ___  (_) ___
  / __/ _ \ '__/ _ \ '_ \| '__/ _ \ | |/ _ \
 | (_|  __/ | |  __/ |_) | | |  __/_| | (_) |
  \___\___|_|  \___|_.__/|_|  \___(_)_|\___/

Proprietary software created by CEREBRE.
© CEREBRE, USA. All rights reserved.
Visit us at: https://www.cerebre.io

Sample output:

.py file without header:

print("Hello world!")

.py file with header:

#                    _                _
#   ___ ___ _ __ ___| |__  _ __ ___  (_) ___
#  / __/ _ \ '__/ _ \ '_ \| '__/ _ \ | |/ _ \
# | (_|  __/ | |  __/ |_) | | |  __/_| | (_) |
#  \___\___|_|  \___|_.__/|_|  \___(_)_|\___/
#
#Proprietary software created by CEREBRE.
#© CEREBRE, USA. All rights reserved.
#Visit us at: https://www.cerebre.io
print("Hello world!")

If the header already exists, in the same form as in the given ${HEADER_PATH} file, the header will not be added a second time.

Installation

From PyPi

pip install ceader

Exemplary cli usage

ceader --mode add_header --files ${FILES} --header-path ${HEADER_PATH} --extensions ${EXTENSIONS}  --prefer-multiline-comment --debug --skip-hidden

Pre-commit plugin

In order to use ceader in pre-commit, the following two configs are recommended:

  • always run on the specified files.
  • run at certain stages (by default repo ceader use stages: all stages, check pre-commit documentation).
Always run

Add the following configuration to your .pre-commit-config.yaml:

repos:
    - repo: https://github.com/cerebre-io/ceader
        rev: 0.0.6
        hooks:
        - id: ceader
            args:[
                '--mode', ${MODE},
                '--header-path', ${HEADER_PATH},
                '--extensions', ${EXTENSIONS},
                '--debug',
                '--skip-hidden',
                '--files', ${FILES}]
            pass_filenames: false

With this config ceader will try to change ${FILES} every time.

Run at certain stages

Add the following configuration to your .pre-commit-config.yaml:

repos:
    - repo: https://github.com/cerebre-io/ceader
        rev: 0.0.6
        hooks:
        - id: ceader
            args:[
                '--mode', ${MODE},
                '--header-path', ${HEADER_PATH},
                '--extensions', ${EXTENSIONS},
                '--debug',
                '--skip-hidden',
                '--files']
            stages: "add stages here"

With this config ceader will try to change files provided by pre-commit on given stages. stages is optional, because by default stages: all stages

FILES

This is the List of Paths to folders or directly to files that need to be changed. In folders, files will be searched recursively.

HEADER_PATH

Path to the file in .txt format with the header to be added.

EXTENSIONS

Files with these extensions will be searched for in the ${FILES}.
The programming language will be recognized by this information and an appropriate comment will be added. Supported extensions and languages can be found here.

DEBUG

An optional boolean value that allows checking the status of adding headers. If you are using precommit, verbose: true must be provided in config.

PREFER_MULTILINE_COMMENT

Some languages ​​support block comments and also single comments and some of them only one type of comment.
By default ceader will use try to use single comment if possible. If this is not possible it will use block comment.
Use --prefer-multiline-comment if you want to reverse logic.

SKIP_HIDDEN

An optional boolean that allows you to ignore hidden files, even if they meet the extension condition.

MODE

There are two modes at the moment:
- add_header adds the indicated header to files, if header already exists in the file it does nothing.
- remove_header removes the indicated header to files, but only if header exists in the file.

TODO

  • user validation (e.g: lint)
  • files backup - pre-commit provides backup but the app itself not
  • change extensions arg to optional - if not used, change all files

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

ceader-0.0.9.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

ceader-0.0.9-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file ceader-0.0.9.tar.gz.

File metadata

  • Download URL: ceader-0.0.9.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for ceader-0.0.9.tar.gz
Algorithm Hash digest
SHA256 c6ad39debcdb48c6feb2084f4c499a2882f0aee8d66bda13ede9b4303782567e
MD5 9cdd9afee45e6f2b7191332b79025caf
BLAKE2b-256 c211010752666a8580304080377164e0def41010246d0bfe8e8ef2853b6a01e5

See more details on using hashes here.

File details

Details for the file ceader-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: ceader-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for ceader-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6a00874d7a88b74a5afb77e949210dfd9727d96640a5455d85148ff1b0ffac7a
MD5 af034894cd6cad80f5b75681e9d5cbc4
BLAKE2b-256 fe38e9ed65d4534f60f7f2b07a5606b0594c2869b469f4ac66fa450d525cb8c6

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