nuclear

Binding glue for CLI Python applications

https://github.com/igrek51/nuclear

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary

Keywords

argparse arguments cli command-line parser python

Keywords from Contributors

interactive serializer cycles packaging network-simulation shellcodes hacking autograding observability genomics
Last synced: 6 months ago · JSON representation

Repository

Binding glue for CLI Python applications

Basic Info
Statistics
  • Stars: 17
  • Watchers: 3
  • Forks: 1
  • Open Issues: 2
  • Releases: 0
Topics
argparse arguments cli command-line parser python
Created about 8 years ago · Last pushed 8 months ago
Metadata Files
Readme License

README.md

☢️ Nuclear

GitHub version (latest SemVer) PyPI Github Pages Documentation Status codecov GitHub Workflow Status

GitHub - PyPI - Documentation

Nuclear is a binding glue for CLI applications. It consists of tools for building CLI applications in Python, including:

CLI Demo

```python from nuclear import CliBuilder

cli = CliBuilder()

@cli.addcommand('hello') def sayhello(name: str, decode: bool = False, repeat: int = 1): """ Say hello :param decode: Decode name as base64 """ message = f"I'm a {b64decode(name).decode() if decode else name}!" print(' '.join([message] * repeat))

@cli.addcommand('calculate', 'factorial') def calculatefactorial(n: int): """Calculate factorial""" print(reduce(lambda x, y: x * y, range(1, n + 1)))

@cli.addcommand('calculate', 'primes') def calculateprimes(n: int): """List prime numbers using Sieve of Eratosthenes""" print(sorted(reduce((lambda r, x: r - set(range(x**2, n, x)) if (x in r) else r), range(2, n), set(range(2, n)))))

cli.run() ```

See demo.py for a complete example.

Installation

bash python3 -m pip install --upgrade nuclear

You need Python 3.8 or newer.

📜 Sublog

Sublog is a nuclear's contextual logging system that allows you to:

  • display variables besides log messages: logger.debug('message', airspeed=20),
  • wrap errors with context: with add_context('ignition'),
  • catch errors and show traceback in a concise, pretty format: with error_handler().

```python from nuclear.sublog import logger, errorhandler, addcontext

with errorhandler(): logger.debug('checking engine', temperature=85.0, pressure='12kPa') with addcontext('ignition', request=42): logger.info('ignition ready', speed='zero') with add_context('liftoff'): raise RuntimeError('explosion') ```

sublog demo

Context logger

Use nuclear.sublog.logger to log message with a pretty format out of the box.

Pass additional context variables as keyword arguments to display them in the log message.

```python from nuclear.sublog import logger

logger.info('info log') logger.debug('debug log', var1=1, var2='two') logger.info('not great not terrible', radioactivity=3.6) logger.error('this is bad') logger.exception(RuntimeError('this is worse')) ```

Error handler

Use nuclear.sublog.error_handler to catch errors and show traceback in a concise, pretty format.

```python from nuclear.sublog import error_handler

with error_handler(): raise RuntimeError('explosion') ```

Wrapping context

Use nuclear.sublog.add_context to wrap code with additional context information. This will be included in in the log message, if an error occurs.

```python from nuclear.sublog import add_context

with addcontext('reloading plugins'): with addcontext('loading config'): raise RuntimeError('file is missing') This will produce an error with the following message: reloading plugins: loading config: file is missing ```

Note that while each individual part of the message may not provide a comprehensive explanation of the error, when combined, the whole message becomes highly informative. This is the core principle behind enriching errors with context.

🐌 Shell utilities

Nuclear provides utilities for running system shell commands.

Basic usage:

```python from nuclear import shell

window_id: str = shell('xdotool getactivewindow') ```

shell function captures the stdout & stderr output of the shell command and returns it as a string. It may also print live stdout in real time (line by line) and capture output in case of errors.

It has a lot of possibilities thanks to its parameters:

  • cmd: str - shell command to run
  • workdir: Optional[Path] = None - working directory for the command
  • print_stdout: bool = False - whether to print live stdout in real time (line by line) from a subprocess
  • print_log: bool = False - whether to print a log message about running the command
  • raw_output: bool = False - whether to let subprocess manage stdout/stderr on its own instead of capturing it
  • independent: bool = False - whether to start an independent process that can outlive the caller process
  • output_file: Optional[Path] = None - optional file to write the output in real time

It returns the stdout of the command combined with stderr. In case of non-zero command exit code, shell raises CommandError exception.

Owner

  • Login: igrek51
  • Kind: user

GitHub Events

Total
  • Watch event: 1
  • Delete event: 1
  • Push event: 8
  • Pull request event: 3
  • Create event: 2
Last Year
  • Watch event: 1
  • Delete event: 1
  • Push event: 8
  • Pull request event: 3
  • Create event: 2

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 325
  • Total Committers: 4
  • Avg Commits per committer: 81.25
  • Development Distribution Score (DDS): 0.252
Past Year
  • Commits: 55
  • Committers: 2
  • Avg Commits per committer: 27.5
  • Development Distribution Score (DDS): 0.018
Top Committers
Name Email Commits
igrek51 i****v@g****m 243
igrek51 i****s@o****l 61
iszulc i****c@r****l 20
dependabot[bot] 4****] 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 4
  • Total pull requests: 7
  • Average time to close issues: 29 days
  • Average time to close pull requests: 14 days
  • Total issue authors: 3
  • Total pull request authors: 2
  • Average comments per issue: 4.0
  • Average comments per pull request: 0.43
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 4
Past Year
  • Issues: 2
  • Pull requests: 4
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 4 days
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 3.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 2
Top Authors
Issue Authors
  • jnoortheen (2)
  • igrek51 (1)
  • phiadaarr (1)
Pull Request Authors
  • igrek51 (7)
  • dependabot[bot] (6)
Top Labels
Issue Labels
Pull Request Labels
dependencies (6)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 396 last-month
  • Total dependent packages: 3
  • Total dependent repositories: 8
  • Total versions: 38
  • Total maintainers: 1
pypi.org: nuclear

Declarative parser for command line interfaces

  • Versions: 38
  • Dependent Packages: 3
  • Dependent Repositories: 8
  • Downloads: 396 Last month
Rankings
Dependent packages count: 3.1%
Dependent repos count: 5.2%
Average: 12.2%
Downloads: 12.5%
Stargazers count: 17.7%
Forks count: 22.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • mkdocs-material *
requirements-dev.txt pypi
  • backoff ==1.11.1 development
  • backoff ==2.0.1 development
  • coverage ==6.2 development
  • coverage ==6.3.2 development
  • mkdocs ==1.3.0 development
  • mkdocs-material ==8.2.14 development
  • mock ==4.0.3 development
  • pytest ==7.0.1 development
  • pytest ==7.1.2 development
  • setuptools ==59.6.0 development
  • setuptools ==62.2.0 development
  • twine ==4.0.0 development
  • twine ==3.8.0 development
  • wheel ==0.37.1 development
requirements.txt pypi
  • colorama *
  • dataclasses *
.github/workflows/gh-pages.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite