Giter Club home page Giter Club logo

shellfuncs's Introduction

shellfuncs

Build Status PyPI package version PyPI python versions

Python API to execute functions written in shell script.

Let's assume you have a shell script counters.sh like this:

count_python_imports() {
    find -name '*.py' | xargs grep -e '^import os$' -e '^import sys$' -e '^import re$' | cut -d: -f2 | sort | uniq -c
}

And you want to execute the count_python_imports function within Python. Instead of using cumbersome subprocess wouldn't it be awesome to do something like this:

import shellfuncs

from counters import count_python_imports

returncode, stdout, stderr = count_python_imports()

Yeah, yeah, I know about easier ways of achieving the above, too. Thanks.

Why should I use that?

  • use existing shell scripts in a pythonic way
  • complex piping stuff might be easier to implement in shell script
  • testing shell scripts is a pain in the a** - with Python it'll be easier

Installation

The recommended way to install shellfuncs is to use pip:

pip install shellfuncs

Usage

shellfuncs can be configured on different levels.

The following configuration variables are available:

  • shell (defaults to /bin/sh)
  • env (defaults to os.environ)

Configuration via environment variables

Set the default shell via SHELLFUNCS_DEFAULT_SHELL environment variable:

export SHELLFUNCS_DEFAULT_SHELL=/bin/bash

Configuration via context manager

Set the configuration block-wise with a context manager:

import shellfuncs

with shellfuncs.config(shell='/bin/bash'):
    from counters import count_python_imports

count_python_imports()  # the shell used will be /bin/bash

Configuration for specific function call

Set the configuration when function is executed:

import shellfuncs

from counters import count_python_imports

count_python_imports(shell='/bin/bash')

This project is published under MIT.
A Timo Furrer project.
- ๐ŸŽ‰ -

shellfuncs's People

Contributors

timofurrer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.