Skip to main content

jumon is a small framework for sub commands.

The jumon is a small framework for implementing the sub command. You can be implemented sub commands, as the hierarchial structure of the sub modules in the packages. It finds importable sub module from the arguments passed, Runs main function in the importable sub module with arguments.

You can be displayed the hierarchial structure of the sub commands with tree command etc, because it be implementing sub commands as the hierarchial structure of the sub module. It will be easy to see where sub command has been implemented.

Please consider to use jumon, if you are trying to implement the sub commands.

Installing

Use setup.py in the source code root directory:

$ python setup.py install

by pip (from PyPI)

$ pip install jumon

How to use

This is a description of how to use the jumon. Let create a package called “testcmd”, and sub package called “testcmd.command”.

$ mkdir testcmd
$ touch testcmd/__init__.py
$ mkdir testcmd/command

Let implementing sub commands in “testcmd.command” subordinate.

First, create top level command.:

$ touch testcmd/command/__init__.py

testcmd/command/__init__.py:

import jumon

def main():
    jumon.entry(__name__)

Under this package is the search range of sub commands.

Next, create sub command.:

$ touch testcmd/command/aaa.py

testcmd/command/aaa.py:

def main(argv):
    print 'OK'
    return 0

This commamd is printed string “OK”, and end with exit code 0.

You can be implemented sub command of sub command.:

$ mkdir testcmd/command/bbb
$ touch testcmd/command/bbb/__init__.py
$ touch testcmd/command/bbb/ccc.py

testcmd/command/bbb/__init__.py:

def main(argv):
    print 'bbb'
    return 1

testcmd/command/bbb/ccc.py:

def main(argv):
    print 'ccc'
    return 2

I implemented sub commands, called “bbb” and “bbb ccc”. This commamd “bbb” is printed string “bbb”, and end with exit code 1. This commamd “bbb ccc” is printed string “ccc”, and end with exit code 2.

Next, install “testcmd”.:

$ cp testcmd $SITE_PACKAGES -R

Last, create command.:

$ touch test.py

test.py:

#! /usr/bin/env python
import testcmd.command

def main():
    testcmd.command.main()

if __name__ == '__main__':
    main()

Add permission:

$ chmod 755 test.py

Run, displayed usage.:

$ ./test.py
Usage: test.py [options]

test.py: error: Command Not Found:

Run sub command “aaa”.:

$ ./test.py aaa
OK
$ echo $?
0

Run sub command “bbb”.:

$ ./test.py bbb
bbb
$ echo $?
1

Run sub command “bbb ccc”.:

$ ./test.py bbb ccc
ccc
$ echo $?
2

Do you want to created command with setup.py?

setup.py:

#-*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
    name='testcmd',
    version='1',
    license='BSD',
    author='TakesxiSximada',
    author_email='takesxi.sximada@gmail.com',
    packages=find_packages(),
    entry_points = """\
    [console_scripts]
    testcmd = testcmd.command:main
    """
)

This is important:

entry_points = """\
[console_scripts]
testcmd = testcmd.command:main
"""

Do you want to transparenting the undefined options?

You can use jumon.TransparentOptionParser() class.

>>> import jumon
>>> parser = jumon.TransparentOptionParser()
>>> opts, args = parser.parse_args(['-f', '-n', '1'])
>>> args
['-f', '-n', '1']

Requirements

  • Python 2.6 or laterr (not supprt 3.x)

License

Apache License 2.0

Release files for jumon 1.1.4

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

Source distribution (sdist)

Source distribution for jumon 1.1.4
File Size Uploaded
jumon-1.1.4.tar.gz 6.5 kB Details

Release files / jumon-1.1.4.tar.gz

Download URL jumon-1.1.4.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
09b5772c949c7b69bc954575ee9006da88a11b635cd49acad0c766714e2451d2
BLAKE2b-256 checksum
How to use checksums
8d566dc3988907755276db463ff3badc6498e57b7e82ee0b4988f05db16428aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.1.11

1 release file

1.1.10

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

This release

1.1.4 This release

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.2

1 release file

1.0.1

2 release files

1.0.0

1 release file

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