Skip to main content

Library implementing protocol used for communication between DevAssistant and PingPong scripts (a.k.a. executable assistants). The protocol specification can be found at TODO:link.

Note that this library implements both “server” and “client” side. The “server” side is only used by DevAssistant itself. If you’re considering implementing a DevAssistant PingPong library for another language, you just need to implement the “client” side.

Usage

To write a simple PingPong script, you need to create a minimal Yaml assistant, that specifies metadata, dependencies needed to run the PingPong script (which is a Python 3 script in this case):

fullname: PingPong script example
description: A simple PingPong script using DevAssistant PingPong protocol

dependencies:
# TODO: once dapp library is on PyPI/packaged in Fedora, it should also be added to list of deps
- rpm: [python3]

args:
  name:
    flags: [-n, --name]
    help: Please provide your name.

files:
  script: &script
    source: script.py

run:
- pingpong: python3 *script

Let’s assume that the above assistant is ~/.devassistant/assistants/crt/test.yaml. The corresponding PingPong script has to be ~/.devassistant/files/crt/test/script.py and can look like this:

#!/usr/bin/python3
import dapp

class MyScript(dapp.DAPPClient):
    def run(self, ctxt):
        if 'name' in ctxt:
            name = ctxt['name'].capitalize()
        else:
            name = 'Stranger'
        self.call_command(ctxt, 'log_i', 'Hello {n}!'.format(n=name))
        return (True, 'I greeted him!')

if __name__ == '__main__':
    MyScript().pingpong()

Things to Note

  • The PingPong script class has to subclass dapp.DAPPClient.

  • The run method has to accept two arguments, self (Python specific argument pointing to the object) and ctxt. The ctxt is a dict (Python mapping type) that holds the global context of the Yaml DSL (e.g. it contains the name argument, if it was specified by user on command line/in GUI).

  • You can utilize DevAssistant commands [1] by calling call_command method. This takes three arguments - global context, command type and command input. The first is (possibly modified) context that was passed to the run method and the other two are the same as explained at [1].

  • The ctxt dict can possibly get modified by running the command, check documentation of every specific command to see what it does and whether it modifies anything in the global context.

  • The call_command method returns a 2-tuple - logical result and result of the command. Again, these are documented for all commands at [1].

  • The run method has to return a 2-tuple - a logical result (e.g. True/False) and a result, just as any other command would.

  • If you want the assistant to modify the global context, just modify the ctxt variable. All commands that you possibly run after pingpong in the Yaml file will then see all the modifications that you did.

  • Note, that to actually start the PingPong script, you have to call pingpong() method of the script class, not the run() method.

[1] http://docs.devassistant.org/en/latest/developer_documentation/command_reference.html

Release files for dapp 0.3.0

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

Source distribution (sdist)

Source distribution for dapp 0.3.0
File Size Uploaded
dapp-0.3.0.tar.gz 17.7 kB Details

Release files / dapp-0.3.0.tar.gz

Download URL dapp-0.3.0.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ff69da1f3f562db7a000b1a492bbfcedbc104c020c33e22540df7deb9b0709d0
BLAKE2b-256 checksum
How to use checksums
229b641450341fa0033cba8689a8c8bd827f761a28c19ef3a85946fcf0ba6fac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.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