kabaret.subprocess-manager


Namekabaret.subprocess-manager JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://gitlab.com/kabaretstudio/kabaret.subprocess_manager
SummarySubprocess Management extension for the Kabaret framework
upload_time2024-10-25 14:52:17
maintainerNone
docs_urlNone
authorDamien "dee" Coureau
requires_python!=3.0.*,!=3.1.*,!=3.2.*,>=2.7
licenseLGPLv3+
keywords kabaret vfx animation pipeline dataflow workflow subprocess
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # kabaret.subprocess_manager

Subprocess Manager for Kabaret.

Provides an Actor, Views and Flow Objects to manage collections of  environment + command-lines, as well as running & controling them.


# Synopsis 

### Runners

You implement your `Runners` by subclassing `kabaret.subprocess_manager.runner_factory.Runner`. *Runners* have a name, some tags, a liste of supported versions, an icon, etc...

At runtime, you add your *Runners* to a `Factory`. A *Factory* has a name, can lookup *Runners* based on name and tags, etc...
You will probably have several factories.

### SubprocessManager Actor

In order to use them, you will *Add* them to the `SubprocessManager` Actor. There is 2 places where you may want to do it:

- In your Session, when creating the Action. This is nice for generic stuff (explorer, shell, text editors, ...) 
- In your Flow, when a project is instaciated. This is nice for production specific tools where the environment and the version are precisely defined (scene editing, baking, render, ...)
 
### LaunchToolBar and SubprocessView

If you add the LaunchToolBar to your *Session*, you will be able to run your Runner by clicking on the toolbar buttons.

Those run take no parameters.

If you add the SubprocessView, you will see a list of process you ran, with their outputs, and you will have opportinities to remove/kill/rerun...

### Flow RunAction 

A big majority of your Runner will be ran from your flows though. 

The `kabaret.subprocess_manager.flow.RunAction` Action will let the user trigger your Runners with the usual `flow.Action` fonctionnalities.

By using the *RunAction*, you will be able to access your flow to configure your *Runners* runs. For example using project settings to get the project resolution and frame rate...

### Logs

Each runner's log is stored in the user's temporary folder and in a subfolder called `.kabaret`. If you want to change the path, you can set it with the `KABARET_SUBPROCESS_LOG_PATH` environment variable.

# Usage:

## Define your process Runners:
```
from kabaret.subprocess_manager.runner_factory import Runner

class MyStuffToRun(Runner):

    ICON = ('icons.gui', 'team-lead')
    TAGS = ['Team', 'Lead', 'Blah']

    def supported_versions(self):
        return ['v1', 'v2]

    def executable(self):
        return '/path/to/{}/executable'.format(self.version)

    def argv(self):
        index = 'https://blah.blu.tv'
        if self.version == 'v2':
            index = 'https://blah2022.blu.tv'

        argv = ['--user', current_user, '--index', index]

        # To allow configured run, you must
        # use self.extra_argv:
        return argv+self.extra_argv

    def env(self):
        env = os.environ.copy()
        env['MY_STUFF_CONFIGVAR] = 'my_stuff_config_value'

        # To allow configured run, you must
        # use self.extra_argv:
        env.update(self.extra_env)

        return env

```
There are more tunning options, like terminal hidding etc... 

Everything is procedural (method call, no static/declarative thingy) so you're in full control ;)

If you want the Runner icon or tags to depend on the date or the current user your can override the classmethods `runner_icon()` and `runner_tags()`


## Configure your Session:

In your session class, add the `SubprocessView` and the `LaunchToolBar` to
the registered view types.

```
class MySession(gui.KabaretStandaloneGUISession):

    def register_view_types(self):
        super(MySession, self).register_view_types()

        type_name = self.register_view_type(SubprocessView)
        self.add_view(type_name, hidden=True)

        type_name = self.register_view_type(LauncherToolBar)
        self.add_view(
            type_name, hidden=False, 
            area=QtCore.Qt.RightToolBarArea
        )
```

In the `_create_actors()` method, you will create the `SubprocessManager` Actor and configure it with your generic runners:

```
    def _create_actors(self):
        # Add the Actor to the session:
        subprocess_manager = SubprocessManager(self)

        # Create your factory:
        site_factory = factories.create_new_factory('Studio Tools')

        # Ensure your Runners are known there:
        site_factory.ensure_runner_type(my_runners.Blender)
        site_factory.ensure_runner_type(my_runners.Godot)
        site_factory.ensure_runner_type(my_runners.Krita)

        # Register your factory to the Actor:
        subprocess_manager.ensure_factory(site_factory)

```

Now you have an awesome toolbar with buttons to launch each 
version of the runner you registered \o/
(They appear grouped by the first tag of each Runner)

## Configure your Project

Some *Runner*s will be specific to flow type.
For example, not all pipelines will supported USDView...

So you need to define Runners inside your flow and have them show up in the toolbar only if you entered a project using this flow.

One way to do so is to use your Project's `_fill_ui()` as a trigger for installation:

```
class MyProject(flow.Object):

    episodes = flow.Child(Episodes).ui(show_filter=True)
    admin = flow.Child(Admin)

    _RUNNERS_FACTORY = None

    def ensure_runners_loaded(self):
        session = self.root().session()
        subprocess_manager = session.get_actor('SubprocessManager')

        if self._RUNNERS_FACTORY is None:
            self._RUNNERS_FACTORY = subprocess_manager.create_new_factory(
                'Best Pipeline Eva'
            )
            self._RUNNERS_FACTORY.ensure_runner_type(
                my_runners.USDView,
                my_runners.USDBlast,
            )
        subprocess_manager.ensure_factory(self._RUNNERS_FACTORY)

    def _fill_ui(self, ui):
        # We can't setup runner in the constructor because
        # it needs access to self.session() which is set
        # *after* constructor :/
        # So we set them up the first time the project is displayed:
        if self._RUNNERS_FACTORY is None:
            self.ensure_runners_loaded()


``` 

## Run Subprocesses from the Flow

This is the most important since running stuff within 
a context is what we want 90% of time :p

In order to use your Runners from the flow and to have them use
some values from your flow (filename, env var, flag, etc...), you
will use the Action `kabaret.subprocess_manager.flow.RunAction`:

Here we define a RunAction that uses the parent's `filename` Param as a command line argument to a `TextEdit` runner:
```
class EditAction(RunAction):

    _scene = flow.Parent()

    def runner_name_and_tags(self):
        # Specifying None for tags means 'accept all'
        return 'TextEdit', None

    def needs_dialog(self):
        return False

    def extra_argv(self):
        # All strings returned here will be
        # appended to the runner command line:
        return [self._scene_.filename.get()]
``` 

You can also provide `extra_env`, let the user select the version
of the runner, etc... 

You can ask for more examples and support in the kabaret discord:
    https://www.kabaretstudio.com/support

Happy Running ! :)



            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/kabaretstudio/kabaret.subprocess_manager",
    "name": "kabaret.subprocess-manager",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7",
    "maintainer_email": null,
    "keywords": "kabaret vfx animation pipeline dataflow workflow subprocess",
    "author": "Damien \"dee\" Coureau",
    "author_email": "kabaret-dev@googlegroups.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/48/bc4300dd892ce74937f18fa6173399d4c51e99152cf70a3f719ac815b97a/kabaret_subprocess_manager-1.2.1.tar.gz",
    "platform": null,
    "description": "# kabaret.subprocess_manager\n\nSubprocess Manager for Kabaret.\n\nProvides an Actor, Views and Flow Objects to manage collections of  environment + command-lines, as well as running & controling them.\n\n\n# Synopsis \n\n### Runners\n\nYou implement your `Runners` by subclassing `kabaret.subprocess_manager.runner_factory.Runner`. *Runners* have a name, some tags, a liste of supported versions, an icon, etc...\n\nAt runtime, you add your *Runners* to a `Factory`. A *Factory* has a name, can lookup *Runners* based on name and tags, etc...\nYou will probably have several factories.\n\n### SubprocessManager Actor\n\nIn order to use them, you will *Add* them to the `SubprocessManager` Actor. There is 2 places where you may want to do it:\n\n- In your Session, when creating the Action. This is nice for generic stuff (explorer, shell, text editors, ...) \n- In your Flow, when a project is instaciated. This is nice for production specific tools where the environment and the version are precisely defined (scene editing, baking, render, ...)\n \n### LaunchToolBar and SubprocessView\n\nIf you add the LaunchToolBar to your *Session*, you will be able to run your Runner by clicking on the toolbar buttons.\n\nThose run take no parameters.\n\nIf you add the SubprocessView, you will see a list of process you ran, with their outputs, and you will have opportinities to remove/kill/rerun...\n\n### Flow RunAction \n\nA big majority of your Runner will be ran from your flows though. \n\nThe `kabaret.subprocess_manager.flow.RunAction` Action will let the user trigger your Runners with the usual `flow.Action` fonctionnalities.\n\nBy using the *RunAction*, you will be able to access your flow to configure your *Runners* runs. For example using project settings to get the project resolution and frame rate...\n\n### Logs\n\nEach runner's log is stored in the user's temporary folder and in a subfolder called `.kabaret`. If you want to change the path, you can set it with the `KABARET_SUBPROCESS_LOG_PATH` environment variable.\n\n# Usage:\n\n## Define your process Runners:\n```\nfrom kabaret.subprocess_manager.runner_factory import Runner\n\nclass MyStuffToRun(Runner):\n\n    ICON = ('icons.gui', 'team-lead')\n    TAGS = ['Team', 'Lead', 'Blah']\n\n    def supported_versions(self):\n        return ['v1', 'v2]\n\n    def executable(self):\n        return '/path/to/{}/executable'.format(self.version)\n\n    def argv(self):\n        index = 'https://blah.blu.tv'\n        if self.version == 'v2':\n            index = 'https://blah2022.blu.tv'\n\n        argv = ['--user', current_user, '--index', index]\n\n        # To allow configured run, you must\n        # use self.extra_argv:\n        return argv+self.extra_argv\n\n    def env(self):\n        env = os.environ.copy()\n        env['MY_STUFF_CONFIGVAR] = 'my_stuff_config_value'\n\n        # To allow configured run, you must\n        # use self.extra_argv:\n        env.update(self.extra_env)\n\n        return env\n\n```\nThere are more tunning options, like terminal hidding etc... \n\nEverything is procedural (method call, no static/declarative thingy) so you're in full control ;)\n\nIf you want the Runner icon or tags to depend on the date or the current user your can override the classmethods `runner_icon()` and `runner_tags()`\n\n\n## Configure your Session:\n\nIn your session class, add the `SubprocessView` and the `LaunchToolBar` to\nthe registered view types.\n\n```\nclass MySession(gui.KabaretStandaloneGUISession):\n\n    def register_view_types(self):\n        super(MySession, self).register_view_types()\n\n        type_name = self.register_view_type(SubprocessView)\n        self.add_view(type_name, hidden=True)\n\n        type_name = self.register_view_type(LauncherToolBar)\n        self.add_view(\n            type_name, hidden=False, \n            area=QtCore.Qt.RightToolBarArea\n        )\n```\n\nIn the `_create_actors()` method, you will create the `SubprocessManager` Actor and configure it with your generic runners:\n\n```\n    def _create_actors(self):\n        # Add the Actor to the session:\n        subprocess_manager = SubprocessManager(self)\n\n        # Create your factory:\n        site_factory = factories.create_new_factory('Studio Tools')\n\n        # Ensure your Runners are known there:\n        site_factory.ensure_runner_type(my_runners.Blender)\n        site_factory.ensure_runner_type(my_runners.Godot)\n        site_factory.ensure_runner_type(my_runners.Krita)\n\n        # Register your factory to the Actor:\n        subprocess_manager.ensure_factory(site_factory)\n\n```\n\nNow you have an awesome toolbar with buttons to launch each \nversion of the runner you registered \\o/\n(They appear grouped by the first tag of each Runner)\n\n## Configure your Project\n\nSome *Runner*s will be specific to flow type.\nFor example, not all pipelines will supported USDView...\n\nSo you need to define Runners inside your flow and have them show up in the toolbar only if you entered a project using this flow.\n\nOne way to do so is to use your Project's `_fill_ui()` as a trigger for installation:\n\n```\nclass MyProject(flow.Object):\n\n    episodes = flow.Child(Episodes).ui(show_filter=True)\n    admin = flow.Child(Admin)\n\n    _RUNNERS_FACTORY = None\n\n    def ensure_runners_loaded(self):\n        session = self.root().session()\n        subprocess_manager = session.get_actor('SubprocessManager')\n\n        if self._RUNNERS_FACTORY is None:\n            self._RUNNERS_FACTORY = subprocess_manager.create_new_factory(\n                'Best Pipeline Eva'\n            )\n            self._RUNNERS_FACTORY.ensure_runner_type(\n                my_runners.USDView,\n                my_runners.USDBlast,\n            )\n        subprocess_manager.ensure_factory(self._RUNNERS_FACTORY)\n\n    def _fill_ui(self, ui):\n        # We can't setup runner in the constructor because\n        # it needs access to self.session() which is set\n        # *after* constructor :/\n        # So we set them up the first time the project is displayed:\n        if self._RUNNERS_FACTORY is None:\n            self.ensure_runners_loaded()\n\n\n``` \n\n## Run Subprocesses from the Flow\n\nThis is the most important since running stuff within \na context is what we want 90% of time :p\n\nIn order to use your Runners from the flow and to have them use\nsome values from your flow (filename, env var, flag, etc...), you\nwill use the Action `kabaret.subprocess_manager.flow.RunAction`:\n\nHere we define a RunAction that uses the parent's `filename` Param as a command line argument to a `TextEdit` runner:\n```\nclass EditAction(RunAction):\n\n    _scene = flow.Parent()\n\n    def runner_name_and_tags(self):\n        # Specifying None for tags means 'accept all'\n        return 'TextEdit', None\n\n    def needs_dialog(self):\n        return False\n\n    def extra_argv(self):\n        # All strings returned here will be\n        # appended to the runner command line:\n        return [self._scene_.filename.get()]\n``` \n\nYou can also provide `extra_env`, let the user select the version\nof the runner, etc... \n\nYou can ask for more examples and support in the kabaret discord:\n    https://www.kabaretstudio.com/support\n\nHappy Running ! :)\n\n\n",
    "bugtrack_url": null,
    "license": "LGPLv3+",
    "summary": "Subprocess Management extension for the Kabaret framework",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://gitlab.com/kabaretstudio/kabaret.subprocess_manager"
    },
    "split_keywords": [
        "kabaret",
        "vfx",
        "animation",
        "pipeline",
        "dataflow",
        "workflow",
        "subprocess"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b48bc4300dd892ce74937f18fa6173399d4c51e99152cf70a3f719ac815b97a",
                "md5": "329466af0c90618809d282cf875074cf",
                "sha256": "5d8b9b103ed12295385458f8ce78db0d3ff80f536082a2e246808b8df2e2ed4c"
            },
            "downloads": -1,
            "filename": "kabaret_subprocess_manager-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "329466af0c90618809d282cf875074cf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7",
            "size": 40783,
            "upload_time": "2024-10-25T14:52:17",
            "upload_time_iso_8601": "2024-10-25T14:52:17.291964Z",
            "url": "https://files.pythonhosted.org/packages/5b/48/bc4300dd892ce74937f18fa6173399d4c51e99152cf70a3f719ac815b97a/kabaret_subprocess_manager-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-25 14:52:17",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "kabaretstudio",
    "gitlab_project": "kabaret.subprocess_manager",
    "lcname": "kabaret.subprocess-manager"
}
        
Elapsed time: 0.42878s