Package: pymanage
ManageFeaturesWithmanageyou add acommand line managerto your Python project and
also it comes with an interactive shell with iPython support.All you have to do isinityour project directory (creating the manage.yml file)$pipinstallmanage$cd/my_project_root_folder$manageinitcreating manage.yml....The filemanage.ymldescribes howmanagecommand should discover your app modules and custom commands and also it defines which objects should be loaded in to theshellNote:Windows users may need to install proper version of PyYAML depending on the version of that thing you call an operating system, installable available in:https://pypi.python.org/pypi/PyYAMLor consider using Linux and don't worry about this as everything works well in Linux except games, photoshop and solitary game :)The ShellBy default the commandmanage shellis included, it is a simple Python REPL console with some configurable options.You can change the banner message to say anything you want,e.g: "Welcome to my shell!"and you can also specify some objects to be automatically imported in to the shell context so when you enter in to the shell you already have your project's common objects available.Also you can specify a custom function to run or a string based code block to run, useful to init and configure the objects.Consolesmanage shellcan start different consoles by passing the optionsmanage shell --ipython- This is the default (if ipython installed)manage shell --ptpythonmanage shell --bpythonmanage shell --python- This is thedefault Python consoleincluding support for autocomplete. (will be default when no other is installed)The first thing you can do withmanageis customizing the objects that will be automatically loaded in to shell, saving you from importing and initializing a lot of stuff every time you need to play with your app via console.Editmanage.ymlwith:project_name:My Awesome Projecthelp_text:|This is the {project_name} interactive shell!shell:console:bpythonreadline_enabled:false# MacOS has no readline completion supportbanner:enabled:truemessage:'Welcometo{project_name}shell!'auto_import:display:trueobjects:my_system.config.settings:my_system.my_module.MyClass:my_system.my_module.OtherClass:as:NiceClasssys.path:as:spinit:insert:args:-0-/path/to/be/added/automatically/to/sys/pathinit_script:|from my_system.config import settingsprint("Initializing settings...")settings.configure()Then the abovemanage.yamlwill give you a shell like this:$manageshellInitializing settings...Welcome to My Awesome Project shell!Auto imported: ['sp', 'settings', 'MyClass', 'NiceCLass']>>>  NiceClass. <tab> # autocomplete enabledWatch the demo:Check more examples in:manage/tree/master/examples/The famousnaval fateexample (used in docopt and click) is in:manage/tree/master/examples/navalProjects using manageQuokka CMS (A Flask based CMS) is using manageRed Hat Satellite QE tesitng framework (robottelo) is using manageCustom CommandsSometimes you need to add custom commands in to your project
e.g: A command to add users to your system:$managecreate_user--name=Bruno--passwd=1234Creating the user...managehas some different ways for you to define custom commands,
you can useclick commandsdefined in your project modules,
you can also usefunction_commandsdefined anywhere in your project,
and if really needed can defineinline_commandsinside themanage.ymlfile1. Using a custom click_commands module (single file)Lets say you have a commands module in your application, you write your custom command there andmanagewill load it# myproject/commands.pyimportclick@click.command()@click.option('--name')@click.option('--passwd')defcreate_user(name,passwd):"""Create a new user"""click.echo('Creating the user...')mysystem.User.create(name,password)Now you go to yourmanage.ymlor.manage.ymland specify your custom command module.click_commands:-module:commandsNow you runmanage --help$manage--help...Commands:create_user  Create a new userdebug        Shows the parsed manage fileinit         Initialize a manage shell in current...shell        Runs a Python shell with contextUsing a click_commands package (multiple files)It is common to have different files to hold your commands so you may prefer having
acommands/package and somepythonmodules inside it to hold commands.# myproject/commands/user.pyimportclick@click.command()@click.option('--name')@click.option('--passwd')defcreate_user(name,passwd):"""Create a new user"""click.echo('Creating the user...')mysystem.User.create(name,password)# myproject/commands/system.pyimportclick@click.command()defclear_cache():"""Clear the system cache"""click.echo('The cache will be erased...')mysystem.cache.clear()So now you want to add all those commands to yourmanageediting your manage file with.click_commands:-module:commandsNow you runmanage --helpand you have commands from both modules$manage--help...Commands:create_user  Create a new userclear_cache  Clear the system cachedebug        Shows the parsed manage fileinit         Initialize a manage shell in current...shell        Runs a Python shell with contextCustom click_command namesSometimes the name of commands differ from the name of the function so you can
customize it.click_commands:-module:commands.systemconfig:clear_cache:name:reset_cachehelp_text:This resets the cache-module:commands.userconfig:create_user:name:new_userhelp_text:This creates new userHaving different namespacesIf customizing the name looks too much work for you, and you are only trying to handle naming conflicts you can use namespaced commands.namespaced:trueclick_commands:-module:commandsNow you runmanage --helpand you can see all the commands in the same module will be namespaced bymodulename$manage--help...Commands:user_create_user    Create a new usersystem_clear_cache  Clear the system cachedebug        Shows the parsed manage fileinit         Initialize a manage shell in current...shell        Runs a Python shell with contextAnd you can even customize namespace for each module separatelyIfnamespacedis true all commands will be namespaced, set it to false in order to define separatelyclick_commands:-module:commands.systemnamespace:sys-module:commands.usernamespace:userNow you runmanage --helpand you can see all the commands in the same module will be namespaced.$manage--help...Commands:user_create_user  Create a new usersys_clear_cache  Clear the system cachedebug        Shows the parsed manage fileinit         Initialize a manage shell in current...shell        Runs a Python shell with context2. Defining your inline commands in manage file directlySometimes your command is so simple that you do not want (or can't) have a custom module,
so you can put all your commands in yaml file directly.inline_commands:-name:clear_cachehelp_text:Executes inline code to clear the cachecontext:-sys-pprintoptions:--days:default:100code:|pprint.pprint({'clean_days': days, 'path': sys.path})Now runningmanage --help$manage--help...Commands:clear_cache  Executes inline code to clear the cachedebug        Shows the parsed manage fileinit         Initialize a manage shell in current...shell        Runs a Python shell with contextAnd you can run using$manageclear_cache--days153. Using general functions as commandsAnd if you already has some defined function (any callable works).# my_system.functions.pydefcreate_user(name,password):print("Creating user%s"%name)function_commands:-function:my_system.functions.create_username:new_userhelp_text:Create new useroptions:--name:required:true--password:required:trueNow runningmanage --help$manage--help...Commands:new_user     Create new userdebug        Shows the parsed manage fileinit         Initialize a manage shell in current...shell        Runs a Python shell with context$managenew_user--name=Bruno--password=1234Creating user BrunoFurther ExplanationsYou can say,how this is useful?, There's no need to get a separate package and configure everything in yaml, just use iPython to do it. Besides, IPython configuration has a lot more options and capabilities.So I say: Nice!If you don't like it, dont't use it!CreditsThis is inspired byDjango's manage.py commandThis is based onclickThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.Similar projectsCobra is amanagefor Go languagehttps://github.com/spf13/cobraHistory0.2 (2021-01-10)Bump version.0.1.15 (2021-01-10)Fork with minor fixes.Update to bump2version.0.1.12 (2016-08-15)Readline is optional because of MacOS compat0.1.11 (2016-08-15)Submodules importmultiple 'as' names0.1.10 (2016-07-04)Bpython added0.1.9 (2016-07-03)Bpython added0.1.8 (2016-07-03)Python 3 dict fixes0.1.7 (2016-06-26)exec bug fix for py30.1.6 (2016-06-26)exec bug fix0.1.5 (2016-06-25)added support to commands collector (see quokka cms)0.1.4 (2016-06-22)Fix missing deps0.1.3 (2016-06-19)Support to function_commands0.1.2 (2016-06-17)Support to inline_commands0.1.1 (2016-06-14)Support to custom and hidden manage_file0.1.0 (2016-06-09)First release on PyPI.