{ "info": { "author": "Paul Joseph Davis", "author_email": "paul.joseph.davis@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "runfunc\n=======\n\nI liked optfunc but it hasn't been put on PyPI for actual use so I went ahead\nand rewrote it to use a different syntax to be able to include option help\nand input validators.\n\nBasic Example\n=============\n\n import sys\n import runfunc as rf\n \n class Help(rf.Help):\n \"\"\"\\\n This is a blurb about this program. Its very entertaining to\n watch and think about what we might do with it.\n \n Look ma. Formatted text.\n \n And stuff\n \"\"\"\n usage = \"%prog [options] value\"\n \n value = rf.Check(int, \"A value to multiply.\")\n factor = rf.Check(float, \"A factor by which to multiply.\", opt='f')\n random = rf.Stream(\"r\", \"An input file to read from.\", opt='r')\n verbose = rf.Flag(\"Multiply verbosely.\", opt='v')\n \n def main(value, factor=2.0, random=sys.stdin, verbose=False):\n newval = value * factor\n if verbose:\n print \"%d * %s = %s\" % (value, factor, newval)\n else:\n print newval\n \n rf.run(main, Help())\n\n\nHelp Class\n==========\n\nThe basic outline for using `runfunc` is to create a subclass of `runfunc.Help`\nand use provide this class when running the function. This subclass is\nresponsible for specifying all of the possible arguments to be passed to the\nfunction. It can contain extra arguments that are ignored so that the same\nsubclass can be reused for multiple command line scripts.\n\n class Help(rf.Help):\n \"\"\"\\\n This is a blurb about this program. Its very entertaining to\n watch and think about what we might do with it.\n \n Look ma. Formatted text.\n \n And stuff\n \"\"\"\n usage = \"%prog [options] value\"\n \n value = rf.Check(int, \"A value to multiply.\")\n factor = rf.Check(float, \"A factor by which to multiply.\", opt='f')\n random = rf.Stream(\"r\", \"An input file to read from.\", opt='r')\n verbose = rf.Flag(\"Multiply verbosely.\", opt='v')\n\nA couple points to note:\n\n* The class's doc string will be used as the program's help description\n* If a `usage` attribute is present, it will be used for the program's help\n* Any other attributes that inherit from `runfunc.Arg` will be available for use as a program argument.\n\nRunning a function\n==================\n\n runfunc.run(callable, help_object, argv=None, check=True)\n\n* `callable` is callable object.\n* `help_object` is an instance of a class that inherits from `runfunc.Help`.\n* `argv` is a list of arguments. If None, `sys.argv[1:]` is used\n* `check=True` will prevent the function from running when imported as a module.\n\nValidator Types\n===============\n\nCheck(func, desc, opt=None)\n---------------------------\n\nUse an arbitrary function to validate an input.\n\n* func - A callable taking a single argument. Raises an exception on error.\n* desc - Help message that describes the option\n* opt - A single character option name.\n\nFlag(desc, opt=None)\n--------------------\n\nPasses true based on the presence of an option. Generally only useful for\nkeyword arguments.\n\n* desc - Help message that describes the option\n* opt - A single character option name.\n\nList(desc, opt=None, validator=None)\n--------------------------\n\nAppend each value seen to a list. Validator is applied before appending each\nvalue.\n\n* desc - Help message that describes the option\n* opt - A single character option name.\n* validator - A callable taking a single argument. Raises an exception on error.\n\nChoice(choices, desc, opt=None, validator=None)\n-----------------------------------------------\n\nLimit input to a specified set of values. Validator is applied before testing\nfor membership in the set.\n\n* choices - A on object providing item access to test if an option is allowable.\n* desc - Help message that describes the option\n* opt - A single character option name.\n* validator - A callable taking a single argument. Raises an exception on error.\n\nRegexp(pattern, desc, opt=None, flags=0)\n----------------------------------------\n\nRequire input to match a regular expression.\n\n* pattern - A string acceptable for `re.compile(pattern, flags)`\n* desc - Help message that describes the option\n* opt - A single character option name.\n* flags - Any modifiers for compiling the regular expression\n\nEmail(desc, opt=None)\n---------------------\n\nRequire input to look like a valid email address. Subclass of Regexp\n\n* desc - Help message that describes the option\n* opt - A single character option name.\n\nIpAddr(desc, opt=None)\n----------------------\n\nRequire input to look like a valid IP Address. Subclass of Regexp.\n\n* desc - Help message that describes the option\n* opt - A single character option name.\n\nPath(flags, desc, opt=None)\n---------------------------\n\nRequire that input specifies a path. Tests are executed depending on the flags\npassed. FILE requires that the path looks like a file (no trailing path\nspecifier). DIR requires the trailing path specifier. EXISTS will check if the\npath actually exists. PARENT requires that the path's parent exist. Any\ncombination of flags can be passed though passing FILE | DIR would guarantee an\nerror during validation.\n \n* flags - An OR of FILE, DIR, EXISTS, PARENT\n* desc - Help message that describes the option\n* opt - A single character option name.\n\nStream(mode, desc, opt=None)\n----------------------------\n\nOpen a path for use as a `file` object. A useful pattern is to use a default\nvalue of `sys.stdin`, `sys.stdout`, or `sys.stderr` for common command line\nsemantics.\n\n* mode - Passed to `open(path, mode)` when opening the stream \n* desc - Help message that describes the option\n* opt - A single character option name.\n\nCustom Validators\n=================\n\nCustom validators can be created by subclassing the Arg class and overriding\nthe validate method.\n\nAn example for specifying a Range validator would look something like this:\n\n import runfunc as rf\n \n class Range(rf.Arg):\n def __init__(self, func, left, right, desc, opt=None):\n super(Range, self).__init__(desc, opt=opt)\n self.func = func\n self.left = left\n self.right = right\n \n def validate(self, option, optstr, value, parser):\n value = self.func(value)\n if value < self.left or value > self.right:\n raise rf.OptionValueError(\"Value is outside range.\")\n setattr(parser.values, option.dest, value)\n\nNotice that func is specifiable so that users can convert the raw value to\nan appropriate data type.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/davisp/runfunc", "keywords": "optparse command-line help", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "runfunc", "package_url": "https://pypi.org/project/runfunc/", "platform": "any", "project_url": "https://pypi.org/project/runfunc/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/davisp/runfunc" }, "release_url": "https://pypi.org/project/runfunc/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "An alternative syntax for optparse", "version": "0.0.1" }, "last_serial": 799142, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "7d4563702db96f0de73245f1a1efeb56", "sha256": "561fd0f2b496159f5df2b464d4f8237dd3f3f593130664f1c1577df965d1c169" }, "downloads": -1, "filename": "runfunc-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7d4563702db96f0de73245f1a1efeb56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10655, "upload_time": "2009-07-24T19:52:52", "url": "https://files.pythonhosted.org/packages/e1/a3/2ff0bd3bac895bff131d33ef5f4b13bf35ee3be46b0cb88643030cbf14aa/runfunc-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7d4563702db96f0de73245f1a1efeb56", "sha256": "561fd0f2b496159f5df2b464d4f8237dd3f3f593130664f1c1577df965d1c169" }, "downloads": -1, "filename": "runfunc-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7d4563702db96f0de73245f1a1efeb56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10655, "upload_time": "2009-07-24T19:52:52", "url": "https://files.pythonhosted.org/packages/e1/a3/2ff0bd3bac895bff131d33ef5f4b13bf35ee3be46b0cb88643030cbf14aa/runfunc-0.0.1.tar.gz" } ] }